[Grace-core] The no shadowing rule
Andrew P Black
black at cs.pdx.edu
Wed Sep 24 15:58:44 PDT 2014
Thinking about this some more, we have to allow re-use of methods names, but can prohibit re-use of other names. That makes for a simple rule.
The key, though, is to remember what makes a method. Obviously, things declared using the method keyword are methods. But every def inside an object (which includes inside a module, class or a factory method) also makes a method (possibly confidential, but still a method), and every var makes two methods. A class declaration is equivalent to a def, so it makes a method, too (and the spec is silent on whether a class is public or confidential by default — I added a note that we need to fix this).
Parameters never make methods. Names defined in an import statement make (confidential by default) methods in the module object.
So, my program 3
class y.new { … }
class z.new {
method y { … }
}
should be OK, because y is a method in the module object, and also in the z.new object, and it's OK to have multiple objects with the same method names — indeed, it's the key to the power of OO. In contrast, Programs 1 & 2 both reuse the name of a parameter for a method.
The parameter thus becomes inaccessible — there seems no reason to allow this, and it is always possible to rename the parameter, with no effect on any client.
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailhost.cecs.pdx.edu/pipermail/grace-core/attachments/20140924/be447f49/attachment.html>
More information about the Grace-core
mailing list