-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Importing core library with a prefix does not remove the names from the global namespace #939
Comments
Discussed with Gilad. dart:core is always implicitly imported, so this becomes equivalent to the scenario: xyz.dart mytest.dart Added AsDesigned label. |
This comment was originally written by ngeoffray@google.com As far as I understand, that was not the original intent. I re-opened the bug in the area language, and CC'ed Peter to let him know about the bug. cc @peter-ahe-google. |
Because the rules for import have changed so that local declarations take priority, there is no reason for a special case here. Added AsDesigned label. |
That local declaration take priority is convenient for avoiding conflicts. However, it doesn't solve all problems. For example, let's say you have a library A. This library defines a class named Object (please pretend that Object wasn't defined in the core library when library A was originally written): #library('A'); Now let's say you have a user of library A: #import('a.dart'); main() => print(new Object()); What happens here? I know using Object as an example is silly, but it is only an example of what happens when a new class or interface is introduced into the core library. Added Triaged label. |
What happens is the same thing that happens when any two imported libraries conflict. This is a weakness of the existing scheme, which does blanket imports by default rather than explicitly importing each required declaration individually. The core library is imported implicitly, which is a special case that is somewhat justifiable. However, the actual semantics of the import construct (and associated combinators) do not have a special case for the core library and should not have one. |
The guarantee we can give people is that if they always import under a prefix, their code will not break as additional declarations are added to their imports. This is the best that can be done while still supporting blanket (aka wildcard) imports. So the specified behavior remains: core lib implicitly imported, but no special case handling beyond that. Added Done label. |
This issue was originally filed by ngeoffray@google.com
The following code works on the VM, even though it should complain that ne the second List constructor cannot be resolved.
import("dart:core", prefix: "baz");
main() {
new baz.List();
new List();
}
The text was updated successfully, but these errors were encountered: