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 implicit this-access in initializer list is not understandable. #37293

Closed
lrhn opened this issue Jun 18, 2019 · 0 comments
Closed
Labels
analyzer-ux area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug

Comments

@lrhn
Copy link
Member

lrhn commented Jun 18, 2019

See: https://stackoverflow.com/questions/56640524/named-inherited-constructor-not-taking-arguments-in-dart/56645417#56645417

The error message is:

  error • Only static members can be accessed in initializers at errmsg.dart:31:25 • implicit_this_reference_in_initializer

(Display differs depending on environment, in VS Code it shows the variable name too), but that's basically it.

Saying that you can only access static methods is simplistic (you can access instance members of other objects), and it doesn't tell you what is wrong. You have to take a mental step to recognize that this thing is not a static access, and only then try to figure out what to do instead.

So, this message could use a better description of what is wrong. Perhaps:

The initializer list code implicitly accesses the instance member firstname of the object being created.
You cannot access instance members of an object until the constructor invocation reaches a constructor body.

The underscored name is not useful to end-users. Should IDEs hide it, or use it to look up a better description from somewhere? That would be a fine way to give a more elaborate explanation of the error. I can see that VS Code does not.

@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug labels Jun 18, 2019
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. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants