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

analyzer API: Element.metadata missing for static final fields #28058

Open
yjbanov opened this issue Dec 9, 2016 · 2 comments
Open

analyzer API: Element.metadata missing for static final fields #28058

yjbanov opened this issue Dec 9, 2016 · 2 comments
Labels
analyzer-api Issues that impact the public API of the analyzer package 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

@yjbanov
Copy link

yjbanov commented Dec 9, 2016

Example:

abstract class Foo {
  @Injector()
  static final field = null;

  @Injector()
  static get getter => null;
}

This happened when processing the code using resolved LibraryElement.

Expected Element.metadata corresponding to the FieldElement.getter of field and getter to return 1 ElementAnnotation.

Actually getting 1 ElementAnnotation for getter and 0 for field.

/cc @matanlurey @stereotype441

@yjbanov yjbanov added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Dec 9, 2016
@stereotype441
Copy link
Member

I believe this is working as intended. The language spec says that for each final field, a synthetic getter is created, so in a sense the code as equivalent to the following pseudocode:

abstract class Foo {
  @Injector()
  static final field = null;

  static get field => ...; // synthetic getter which gets the value of the field

  @Injector()
  static get getter => null;
}

So FieldElement.getter of field refers to the synthetic getter, which indeed has no annotations.

Putting on my psychic debugging hat, I'm guessing this arose because you are analyzing some code which refers to the field, and since the reference actually resolves to the synthetic getter, you aren't seeing the annotation you expect. If that's the case, the solution is to check whether the getter you're looking at is synthetic, and if so, look at the corresponding PropertyInducingElement. (Note: most people probably want to do this, so maybe we should make a convenience method that does this automatically. What do you think, @bwilkerson ?)

@bwilkerson
Copy link
Member

I'd be fine with adding a convenience getter.

@bwilkerson bwilkerson 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 labels Dec 12, 2016
@srawlins srawlins added the analyzer-api Issues that impact the public API of the analyzer package label Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-api Issues that impact the public API of the analyzer package 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