Insufficient choices in resolution
Currently, the nested structure of choices does not prefer local definitions over imported definitions. This gave me some hard times with This() and Super():
Class(c, _, _): defines Class c implicitly defines Field This() of type ClassTy(c) This(): refers to Field This()
This works fine, until we have imports:
Parent(p): imports Field, imported Field, Method, imported Method from Class p implicitly defines Field Super() of type ClassTy(c)
Now This() is defined locally and imported from the parent, thus we have two valid resolutions.
Solution 1
A choice at the right place could let the local definitions win, but currently it does not.
Solution 2
Another direction would be more fine-grained specification of target scopes. For imports, we have already
imported
. We could use this also inrefers
clauses:Super(): refers to imported Field This()
We could have more of these, for example
local
for local resolution:This(): refers to local Field This()
Solution 3
Another option are scopes. We can currently say:
This(): refers to Field This() in current scope
Here,
current
is the default, and includes imports and surrounding scopes. We could have more variants there as well:This(): refers to Field This() in local scope
This could be mixed with the namespace modifiers, e.g.
Super(): refers to imported Field This() in local scope
Solution 4
And finally, there is disambiguation. We might have more disambiguates:
This(): refers to innermost Field This()
Opinions? Preferences? Objections?
Submitted by Guido Wachsmuth on 3 July 2013 at 11:58
Issue Log
What’s the difference between
refers to local Field This()
andrefers to Field This() in local scope
. Also, how wouldThis(): refers to Field This() in local scope
interact with scopes introduced by subsequent definitions? MaybeThis(): refers to Field This() in local Class
orThis(): refers to Field This() in enclosing Class
makes more sense for that case.
@Gabriël: I just sketched different design options. Not all combinations make sense, because there are equivalents in different options. I basically asked for your preference to describe such things.
Log in to post comments