-
Notifications
You must be signed in to change notification settings - Fork 207
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
Is it possible to augment the values
of an enum?
#4015
Comments
We probably should not allow augmenting |
We currently have this specified in the enhanced enums spec which I think probably covers this? "It's a compile-time error if the enum declaration contains a static or instance member declaration with the name An augmenting declaration is still a declaration, so I think it is covered. |
We could allow augmenting the provided augment static const List<ThisEnum> values =
[...augmented, newValue1, newValue2]; If we did allow augmenting, we'd need to be careful about the specification of that On a similar note: can you augment the getter for the representation value of an extension type with a new body? It's just a getter, but we special-case it to be promotable, which needs to be disabled if you augment with another getter body. Which is a property that isn't visible in the initial declaration, so it would be consistent to disallow augmenting it, because doing so changes the capabilities expected from the original declaration in a breaking way. |
Sounds good! I'd prefer if we make it an error to augment the |
Should we similarly block augmenting the |
Actually, it looks like For |
Created #4103 to do this. It does not introduce any constraints on enum members whose name is |
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: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 namedname
in anenum
, so we probably can't do anything about that.@dart-lang/language-team, WDYT?
The text was updated successfully, but these errors were encountered: