language
language copied to clipboard
Is it possible to augment the `values` of an enum?
Thanks to @sgrekhov for bringing up this topic. We may or may not allow developers to augment an implicitly induced member like the values
list of an enum:
enum E { one }
const someAnnotation = 1;
augment enum E {
augment one;
@someAnnotation
augment static const values;
}
We do already allow the implicitly induced getter of an instance variable to be augmented, which may be seen as prior art. However, there may also be unwanted consequences of allowing augmentation of values
.
(Note that the example relies on having #4008 such that augment static const values;
isn't a syntax error.)
As @jakemac53 mentioned below, we could make augmentations of index
, hashCode
, and operator ==
an error as well. This may be covered already, otherwise we could add a couple of words in the augmentations feature specification in order to make it explicit.
name
might have some restrictions as well, but this is an extension method and there is nothing stopping us from declaring a member named name
in an enum
, so we probably can't do anything about that.
@dart-lang/language-team, WDYT?