-
Notifications
You must be signed in to change notification settings - Fork 12
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
How to handle fields in subclasses when super classes have fields with same name? #42
Comments
Another question related to this one is: Considering those same
While
So, who is right here ? |
Hm, another good question. |
This is a good test case -- well done @Hirevo! I would strongly recommend not trying to be clever and trying to allow subclasses to have their own fields of the same name. In a dynamically typed language this opens up a world of pain for very little gain (in a statically typed language it's also a pain, but slightly less so). My suggestion is simply to forbid subclasses from redefining a name that's used in a superclass. [The subclass can, of course, still access the appropriate field, but it can't pretend to redefine it.] This also has the pleasing bonus of being simple to implement! |
I've prototyped this in softdevteam/yksom#147 (and detected another related case which I think is worth explicitly handling). Thoughts welcome! |
Just for context: The historical SOM had independent class loading. With this I mean that classes could be parsed without the super class having to be present. This means, it wasn't possible to know the fields of the superclass. Current SOM requires the super class to be loaded before hand, which leads to a possible recursion in the parser. Don't think that the parser was reentrant originally. In the interest of simplicity, the extra static checks are probably a good tradeoff. |
Cool. I'll ask for that to be reviewed for inclusion into yksom. |
147: Detect overlapping field names r=vext01 a=ltratt There are two cases to be dealt with: 1. A field name has already been defined in a superclass (5e00d91). 2. A class defines the same field more than once (9370609). The first of those was pointed out by @Hirevo in SOM-st/SOM#42; the second is a relatively simple variation on the same theme. Co-authored-by: Laurence Tratt <[email protected]>
As reported by @Hirevo, how do we want to handle it when subclasses define fields with the same name as fields in their super classes?
This currently seems to ignore the field defined in
TestB
.In yksom (@ltratt) it seems to crash according to @Hirevo.
A sensible language would probably shadow field
a
fromTestA
, which means it can't be accessed fromTestB
, and onlyTestB.a
can be accessed as a separate field.The text was updated successfully, but these errors were encountered: