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

Improve error message for typo in setter name #48603

Open
rkj opened this issue Mar 17, 2022 · 2 comments
Open

Improve error message for typo in setter name #48603

rkj opened this issue Mar 17, 2022 · 2 comments
Labels
analyzer-ux area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@rkj
Copy link

rkj commented Mar 17, 2022

Code like this:

class A {}

class B {
  A _a;
  A get a => _a;
  set A(A a) => _a = a;
}

gives error:

Error: 'A' isn't a type.
  A _a;

which is a little confusing, as the type is clearly defined above. It took me a long while to find out what is the actual issue (I first thought incorrect import / conflicting names imported).

It also causes analyzer to highlight all the places except where the actual problem is:
8pTMspp9ZPUtgWb

@bwilkerson
Copy link
Member

I agree that the message isn't very helpful in this particular case.

That said, Dart doesn't disallow the use of uppercase names for instance members, so there's nothing wrong with defining a setter named A. And, Dart's look-up rules say that A should resolve to the instance member rather than a top-level name inside the class that defines the instance member. So technically (though unhelpfully) all of the highlighted usage of the name are places where the analyzer correctly resolved the name to the setter and let you know that a setter wasn't appropriate.

That leaves the question of how to be more helpful. My first attempt to improve the situation would be to include an indication of the definition of the name in the message:

A is a setter, but a type was expected here.

We could also provide a context message explaining where the setter A is defined.

Given that the common convention is for instance members to start with a lowercase letter, we might also want to change the correction message to include a suggestion that you might want to rename the setter.

Would that be better? Would it be enough, or is there additional information you would have found useful?

@a-siva a-siva added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Mar 17, 2022
@rkj
Copy link
Author

rkj commented Mar 17, 2022

That would totally help me, specifying what the thing in the error would be probably helpful in other cases.

@srawlins srawlins added P3 A lower priority bug or feature request analyzer-ux type-enhancement A request for a change that isn't a bug and removed area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Mar 21, 2022
@srawlins srawlins added the contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) label May 20, 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. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) 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

4 participants