Skip to content
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

Closed
DartBot opened this issue Dec 22, 2011 · 7 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).

Comments

@DartBot
Copy link

DartBot commented Dec 22, 2011

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();
}

@iposva-google
Copy link
Contributor

Please figure out with Gilad if the expectation is correct.


cc @gbracha.
Set owner to @a-siva.
Added Accepted label.

@a-siva
Copy link
Contributor

a-siva commented Jun 1, 2012

Discussed with Gilad.

dart:core is always implicitly imported, so this becomes equivalent to the scenario:

xyz.dart
========
#library("xyz.dart");
int A;

mytest.dart
===========
import("xyz.dart");
import("xyz.lib", prefix:"junk");
both A and junk.A are valid.


Added AsDesigned label.

@DartBot
Copy link
Author

DartBot commented Jun 4, 2012

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.
Removed Area-VM label.
Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Jun 7, 2012

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.

@peter-ahe-google
Copy link
Contributor

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');
class Object {
  toString() => 'an Object from 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.

@gbracha
Copy link
Contributor

gbracha commented Jun 7, 2012

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.

@gbracha
Copy link
Contributor

gbracha commented Jun 7, 2012

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.

@DartBot DartBot added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Jun 7, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

6 participants