1
1
# Augmentations
2
2
3
3
4
- Version: 1.28 (see [ Changelog] ( #Changelog ) at end)
4
+ Version: 1.29 (see [ Changelog] ( #Changelog ) at end)
5
5
6
6
Augmentations allow spreading your implementation across multiple locations,
7
7
both 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:
724
724
### Augmenting enum values
725
725
726
726
Enum 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.
731
729
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 .
735
733
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.
739
736
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 ` .
744
739
745
740
For example:
746
741
@@ -750,39 +745,57 @@ part 'a.dart';
750
745
part 'c.dart';
751
746
752
747
enum 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
+ }
754
757
}
755
758
756
759
// a.dart
757
760
part of 'main.dart';
758
761
part 'b.dart';
759
762
760
763
augment enum A {
761
- second;
764
+ third;
765
+
766
+ /// Some doc comment
762
767
augment first; // This is still `first` in values.
768
+
769
+ @someAnnotation
770
+ augment second; // Don't repeat the argument list, original is used.
763
771
}
764
772
765
773
// b.dart
766
774
part of 'a.dart';
767
775
768
776
augment enum A {
769
- augment third ;
777
+ fourth ;
770
778
}
771
779
772
780
// c.dart
773
781
part of 'main.dart';
774
782
775
783
augment 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);
777
789
}
778
790
```
779
791
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 ] ` .
781
793
782
794
It is a compile-time error if:
783
795
784
796
* An augmenting getter is defined for an enum value. _ An enum value
785
797
counts as a constant variable._
798
+ * An enum value augmentation provides an explicit constructor invocation.
786
799
787
800
### Augmenting constructors
788
801
@@ -1354,6 +1367,11 @@ to the augmentation.
1354
1367
1355
1368
## Changelog
1356
1369
1370
+ ### 1.29
1371
+
1372
+ * Simplify enum value augmentations, no longer allow altering the
1373
+ constructor invocation.
1374
+
1357
1375
### 1.28
1358
1376
1359
1377
* Explicitly disallow augmenting abstract variables with non-abstract
0 commit comments