Skip to content

Commit c3fd9bb

Browse files
authored
#2559. Add test that EnumName extension is not augmentable (#2899)
1 parent 1a32df6 commit c3fd9bb

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

LanguageFeatures/Augmentation-libraries/augmenting_enum_values_A05_t04.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ augment enum E4 {
5353
main() {
5454
Expect.equals("name", E1.e0.name);
5555
Expect.equals("name2", E2.e0.name);
56+
Expect.equals("e0", EnumName(E1.e0).name);
57+
Expect.equals("e0", EnumName(E2.e0).name);
5658
Expect.equals("E3.name", E3.name);
5759
Expect.equals("E4.name", E4.name);
5860
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Some enum members can not be augmented: It is a compile-time
6+
/// error if an augmenting declaration in an enum declaration (introductory or
7+
/// augmenting) has the name `values`, `index`, `hashCode`, or `==`.
8+
///
9+
/// @description Checks that it is not an error to declare or augment `name`
10+
/// static member or property.
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=macros
14+
15+
import '../../Utils/expect.dart';
16+
17+
enum E1 {
18+
e0;
19+
}
20+
21+
augment enum E1 {
22+
augment e0;
23+
static String get name => "name1";
24+
}
25+
26+
enum E2 {
27+
e0;
28+
static String get name => "name";
29+
}
30+
31+
augment enum E2 {
32+
augment e0;
33+
augment static String get name => "name2";
34+
}
35+
36+
main() {
37+
Expect.equals("name1", E1.name);
38+
Expect.equals("e0", E1.e0.name);
39+
Expect.equals("name2", E2.e0.name);
40+
Expect.equals("e0", E2.e0.name);
41+
}

0 commit comments

Comments
 (0)