11# Augmentations
22
33Author: rnystrom@google.com , jakemac@google.com , lrn@google.com <br >
4- Version: 1.28 (see [ Changelog] ( #Changelog ) at end)
4+ Version: 1.29 (see [ Changelog] ( #Changelog ) at end)
55
66Augmentations allow spreading your implementation across multiple locations,
77both within a single file and across multiple files. They can add new top-level
@@ -724,23 +724,18 @@ It is a **compile-time error** if:
724724### Augmenting enum values
725725
726726Enum values can _ only_ be augmented by enum values, and the implicit getter
727- introduced by them is not augmentable. The one thing you are allowed to do
728- is to replace the argument list and add metadata or doc comments. There is
729- no way to refer to the original argument list (although a macro may be able
730- introspect on it and copy over some or all of the arguments).
727+ introduced by them is not augmentable. The only thing you are allowed to do
728+ when augmenting an enum value is add metadata annotations or doc comments.
731729
732- An augmenting enum value is allowed to invoke a different constructor than
733- the augmented enum value, or provide an argument list where none was present
734- before .
730+ When augmenting an enum value, no constructor invocation should be provided.
731+ The original value is always used, and the explicit constructor invocation (if
732+ present) should not be copied .
735733
736- If no argument list is provided, the augmented argument list is not altered,
737- this allows augmenting with metadata or comments without copying over the entire
738- argument list.
734+ New enum values may be defined in an augmenting enum, and they will be appended
735+ to the current values of the declaration in augmentation application order.
739736
740- New enum values may also be defined in the augmentation, and they will be
741- appended to the current values of the declaration in augmentation application
742- order. Augmenting an existing enum value never changes the order in which it
743- appears in ` values ` .
737+ Augmenting an existing enum value never changes the order in which it appears in
738+ ` values ` .
744739
745740For example:
746741
@@ -750,39 +745,57 @@ part 'a.dart';
750745part 'c.dart';
751746
752747enum A {
753- first;
748+ first,
749+ second.custom(1);
750+
751+ final int b;
752+
753+ const A() : b = 0;
754+
755+ const A.custom(this.b);
756+ }
754757}
755758
756759// a.dart
757760part of 'main.dart';
758761part 'b.dart';
759762
760763augment enum A {
761- second;
764+ third;
765+
766+ /// Some doc comment
762767 augment first; // This is still `first` in values.
768+
769+ @someAnnotation
770+ augment second; // Don't repeat the argument list, original is used.
763771}
764772
765773// b.dart
766774part of 'a.dart';
767775
768776augment enum A {
769- augment third ;
777+ fourth ;
770778}
771779
772780// c.dart
773781part of 'main.dart';
774782
775783augment enum A {
776- augment fourth;
784+ fifth;
785+
786+ // Error, enum value augmentations cannot have an explicit constructor
787+ // invocation.
788+ augment third.custom(3);
777789}
778790```
779791
780- Then ` A.values ` is ` [A.first, A.second, A.third, A.fourth] ` .
792+ Then ` A.values ` is ` [A.first, A.second, A.third, A.fourth, A.fifth ] ` .
781793
782794It is a compile-time error if:
783795
784796* An augmenting getter is defined for an enum value. _ An enum value
785797 counts as a constant variable._
798+ * An enum value augmentation provides an explicit constructor invocation.
786799
787800### Augmenting constructors
788801
@@ -1354,6 +1367,11 @@ to the augmentation.
13541367
13551368## Changelog
13561369
1370+ ### 1.29
1371+
1372+ * Simplify enum value augmentations, no longer allow altering the
1373+ constructor invocation.
1374+
13571375### 1.28
13581376
13591377* Explicitly disallow augmenting abstract variables with non-abstract
0 commit comments