Skip to content

Wrong name used to access the index field of enumeration constants #2318

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

Closed
bwilkerson opened this issue Aug 25, 2020 · 2 comments
Closed

Wrong name used to access the index field of enumeration constants #2318

bwilkerson opened this issue Aug 25, 2020 · 2 comments
Assignees
Labels
P2 A bug or feature request we're likely to work on type-code-health Internal changes to our tools and workflows to make them cleaner, simpler, or more maintainable

Comments

@bwilkerson
Copy link
Member

In at least one place:

new ModelElement.fromPropertyInducingElement (package:dartdoc/src/model/model_element.dart:203:65)

this package is assuming that every enumeration constant has a field whose name is the same as the name of the constant and whose value is the index of the constant. That isn't true; the field is named index. We need to fix the analyzer to stop producing a representation of such a field, but we can't do so until this package stops depending on the existence of that field.

The easiest way to test that all such locations have been fixed might be to update the version of analyzer being used by dartdoc to stop producing the invalid field. The code that produces the field is, as of this writing, at pkg/analyzer/lib/src/dart/element/element.dart:1778.

@srawlins
Copy link
Member

Thanks for filing this, @bwilkerson .

If I try to change that case on line 203 from:

var index = e.computeConstantValue().getField(e.name).toIntValue();

to

var index = e.computeConstantValue().getField('index').toIntValue();

I get a null pointer exception:

  NoSuchMethodError: The method 'toIntValue' was called on null.                                                                                                     
  Receiver: null                                                                                                                                                     
  Tried calling: toIntValue()                                                                                                                                        
  dart:core                                             Null.toIntValue                                                                                              
  package:dartdoc/src/model/model_element.dart 203:66   new ModelElement.fromPropertyInducingElement

Are we sure that analyzer's enum constant values contain that index getter, and that it contains a value?

@jcollins-g jcollins-g added type-code-health Internal changes to our tools and workflows to make them cleaner, simpler, or more maintainable P2 A bug or feature request we're likely to work on labels Sep 28, 2020
@scheglov scheglov self-assigned this Dec 14, 2021
@scheglov
Copy link
Contributor

Was fixed #2865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-code-health Internal changes to our tools and workflows to make them cleaner, simpler, or more maintainable
Projects
None yet
Development

No branches or pull requests

4 participants