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
Language enhancement: qualifier for top level scope #2288
Comments
This comment was originally written by zundel@google.com I did cook up one case where a programmer can be caught off guard and no warnings will be emitted by an errant library upgrade. Assume that a developer is using two third party libraries, libA and libB libA.dart: libB.dart: user code: import ("libA.dart"); class myClass extends B { Now, at some point, libA is updated so that foo() is renamed. newFoo(int a) { Now, if you run the usercode libAfeature(), the invocation of foo() now resolves to the superclass method for 'foo()'. Its all well and good to say that libA shouldn't have it renamed its top level method, but that is in a library that the user code doesn't control. The proposed 'global' qualifier would have provided a way for the library user to protect themselves. Another way the user could have protected themselves from this kind of change is to prefix the library. |
Added this to the Later milestone. |
This comment was originally written by waprave...@gmail.com The obvious thing is to search the class hierarchy for the method and if it doesn't exist there then search the top level. This void go() { class Base class Test extends Base { void main() { and this void go() { class Base class Test extends Base { void main() { should produce the same result. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
This comment was originally written by @seaneagan Might make sense to use the "as" keyword on "library": library foo as foo; import 'package:bar/bar.dart'; // Has a top-level var baz; class Bar { get bloop => [bar, foo.bar, baz, foo.baz]; |
No current plans to add this feature. A top-level scope identifier should not be used defensively, because that would mean writing it everywhere. It should at most be used when necessary. A partial workaround is (or should be): import "" as top; which makes the current library's export scope available. |
This issue was originally filed by zundel@google.com
This is a request to add a special qualifier, similar to 'this' and 'super' to specify access to a symbol a the library scope. I don't care what the name is, but it could be something like "global"
foo() {
return "global";
}
class A {
foo() {
return "class A";
}
bar() {
print (foo()); // prints "class A"
print (global.foo()); // prints "global"
}
}
The justification for this request is that currently, the only way to specify a field or method at the top level (library) scope is to use the identifier with no qualifiers. Another instance field can shadow the top level identifier and give no direct way. This will return a warning, so we do have coverage for this problem, but nevertheless, there is no way to defensively code around this issue the way you can with 'this.foo' or 'super.foo' to make it explicit that you do not mean for a symbol to resolve to the library scope.
A private discussion with Gilad convinces me that this is not an essential feature, assuming one pays attention to the warnings. You can work aroun d this by creating a delegate method at the top level with a different name, for example.
The text was updated successfully, but these errors were encountered: