-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple classes with the same name are allowed #227
Comments
What do other SOMs do? |
som-rs currently panics, like so:
som-java also panics with a runtime exception:
|
I'd happily take a PR to make yksom behave as som-rs! |
There's an implicit contract between
I believe the SOM grammar is defined to allow only for a single |
Hm, I didn't correctly read the initial issue: I don't believe SOM enforces a match between file and class name. @Hirevo the result you get seems sensible to me based on the definition of load, resolve, and unknownGlobal. |
@smarr What made the output surprising to me is that simply loading the I agree that setting the global's value after loading the class is expected, but I expected only either Before running the code, My expectation was that either:
So, with this output, I initially thought that that second theory was correct but adding a
To verify this further, rewriting Main = (
run: args = (
('Foo: ' + (system global: #Foo)) println.
('Bar: ' + (system global: #Bar)) println.
Bar new sayHello.
('Foo: ' + (system global: #Foo)) println.
('Bar: ' + (system global: #Bar)) println.
)
) results in the following output:
So, now I knew that the VM itself was writing at multiple globals at once, and I found after a quick look through the code that there is indeed two calls to The first one to be called is in Lines 279 to 287 in d262fb5
The second one is in Lines 269 to 273 in d262fb5
So, when loading (I'm sorry for the long winded response :/) |
I looked back in som-java, and it seems to explicitely do this check, which is the one that triggered the error message I showed above. |
Ok, so, since SOM-java does the name check, I guess that's the way to go. Though, this also means there's an assumption of only a single class, and the I also convinced myself that it's not me who introduced the check: I somehow thought I would have. |
yksom, as opposed to most other SOMs, currently doesn't require class names to match their file names, which can lead to weird behaviours where loading new classes overwrites existing globals which makes previously loaded classes unreachable.
Consider the two following classes:
Now, consider the following
Main
class:Executing
Main
results in the following surprising output:Due to the conflicting naming, it seems that loading the class from
Bar.som
did overwrite the#Bar
global but also the already existing#Foo
global, which seems undesirable.The text was updated successfully, but these errors were encountered: