Description
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()
showsE()
. Of course theconstantInitializer
ofE.two
also showsE()
. 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'
andindex = 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 likestatic 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 likeE(0, 'one')
or even justE(0)
, in order to give some semblance of differentiation betweenE.one
andE.two
.
Dartdoc relies on the analyzer's Element model, and these constant initializers, to give some information about how an enum value is declared.