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

No warning when abstract class from imported library is also declared in file #5871

Closed
sethladd opened this issue Oct 15, 2012 · 8 comments
Closed
Assignees
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@sethladd
Copy link
Contributor

Consider this code:

import 'dart:html';

var screens = new Map<String, Screen>();

addScreen(String name) {
  screens[name] = new Screen();
}

Screen returnScreen(String name) {
  return screens[name];
}

class Screen {
  
}

main() {
  addScreen("foo");
  var s = returnScreen("foo");
  print(s.runtimeType);
}

When you run it, you get this error:

Exception: type 'Screen' is not a subtype of type 'Screen' of 'function result'.
Stack Trace: #­0 returnScreen (http://127.0.0.1:3030/Users/sethladd/dart/dupehtmlclassname/dupehtmlclassname.dart:13:17)

­1 main (http://127.0.0.1:3030/Users/sethladd/dart/dupehtmlclassname/dupehtmlclassname.dart:22:23)

There is an abstract class named Screen in dart:html.

I would expect some sort of warning from the Editor when I declared a class named Screen.

@sethladd
Copy link
Contributor Author

@bwilkerson
Copy link
Member

I believe that this is working as expected. According to the specification (in the section on handling import directives):

Then, for each entry mapping key k to declaration d in NS, d is made available in the top level scope of L under the name k unless either:
a declaration with the name k exists in L, ...

If I'm understanding this correctly, this means that it's OK (there shouldn't be a warning or error) for a library L to declare a name that is also declared in an imported library. The rationale is that adding a new name to an imported library is less likely to break the importing library.

That said, I think it would be a good idea for us to offer an option to generate a "warning" in this case.


Set owner to @bwilkerson.
Added this to the M3 milestone.
Removed Type-Defect label.
Added Type-Enhancement label.

@bwilkerson
Copy link
Member

Removed this from the M3 milestone.
Added this to the M4 milestone.

@bwilkerson
Copy link
Member

Removed this from the M4 milestone.
Added this to the Later milestone.

@bwilkerson
Copy link
Member

Added Analyzer-Hint label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@sethladd sethladd added Type-Enhancement area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-warning Issues with the analyzer's Warning codes labels Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@bwilkerson
Copy link
Member

We have improved the error message, so hopefully the UX is better now. Closing as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants