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

Error message for name mis-match can be improved in the case of shadowing #12042

Open
stevemessick opened this issue Jul 25, 2013 · 6 comments
Open
Labels
analyzer-ux area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@stevemessick
Copy link
Contributor

class A {}

class B {
 A a = new A(); // Error on A of "A a"

 A() {}
}

main() {
 new B();
}

Current message is "A is not a type"

Apparently, the invalid constructor confuses the resolver. This occurs when porting GT to angular, so can be expected to be seen often in the near future.

@bwilkerson
Copy link
Member

Is it confused, or is it doing the right thing? As far as I can see "A() {}" defines a method named "A". It's unfortunate that this method hides the class named "A" in the outer scope, but it does. I think your example is equivalent to

class B {
  m a = new m();
  m() {}
}

In which case, I think the error that "m is not a type" is the correct error. (Where "correct" means "conforms to the specification".) It would be nice if we could always tell the difference between a method and a constructor, but we can't.

That said, I agree that we could do better. When we find an error of this type we could look in the outer scope to see if the name denotes a type somewhere else and provide a better error message, such as "The type 'A' cannot be used here because it is hidden by the method 'A'".

We might also want to provide a hint on the method 'A' that it is hiding the class A and provide a quick-fix to rename it to 'B', but that would have to be in addition to the error.


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

@bwilkerson
Copy link
Member

Removed Type-Defect label.
Added Type-Enhancement, Analyzer-UX labels.

@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.

@stevemessick stevemessick added Type-Enhancement area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-ux 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
@srawlins
Copy link
Member

I agree with @bwilkerson. Done?

@bwilkerson
Copy link
Member

We would like to improve the feedback when possible.

@bwilkerson bwilkerson removed their assignment Aug 15, 2016
@srawlins srawlins changed the title Wrong error message for type/constructor name mis-match Error message for name mis-match can be improved in the case of shadowing Jan 5, 2022
@srawlins srawlins added P3 A lower priority bug or feature request and removed P2 A bug or feature request we're likely to work on labels Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-ux area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants