Skip to content

Analyzer enum value constant initializers have some issues #54988

Open
@srawlins

Description

@srawlins

Some issues with enum value "constant initializers": If the constructor call is implicit, as in enum E { one, two; }, then for the element representing E.one (a ConstFieldElementImpl), then I see a constantInitializer field, an InstanceCreationExpressionImpl node, with the following:

  • None of the AST nodes here claim to be synthetic, via isSynthetic. Not the InstanceCreationExpressionImpl, the ArgumentListImpl, etc.

  • The toString() shows E(). Of course the constantInitializer of E.two also shows E(). This seems wrong, or at least disingenuous, to claim a call to a default constructor with no arguments, for both calls.

    The ConstFieldElementImpl does have an evaluationResult field, a DartObject showing accurate data, aligning with the spec. Namely that there are two fields, _name = 'one' and index = 0. 👍

    The spec suggests deguaring an enum like this here with a private constructor like E._$(int _$index, String_ $name), and an enum value as a static field like static const E one = E._$(0, "one");. (Indeed, during const evaluation, we appear to do something like this, based on the DartObject.)

    I suggest our constantInitializer should then look something like E(0, 'one') or even just E(0), in order to give some semblance of differentiation between E.one and E.two.

Dartdoc relies on the analyzer's Element model, and these constant initializers, to give some information about how an enum value is declared.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestanalyzer-apiIssues that impact the public API of the analyzer packagearea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions