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
Comments
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 { 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. |
Removed Type-Defect label. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
I agree with @bwilkerson. Done? |
We would like to improve the feedback when possible. |
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.
The text was updated successfully, but these errors were encountered: