Skip to content

Commit 1a32df6

Browse files
authored
#2559. Add more tests for augmenting enum members and values. (#2897)
1 parent 7f3439d commit 1a32df6

File tree

5 files changed

+176
-6
lines changed

5 files changed

+176
-6
lines changed

LanguageFeatures/Augmentation-libraries/augmenting_enum_values_A01_t02.dart renamed to LanguageFeatures/Augmentation-libraries/augmenting_enum_values_A05_t01.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion Enum values can only be augmented by enum values, and the
6-
/// implicit getter introduced by them is not augmentable.
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 `==`.
78
///
89
/// @description Checks that it is a compile-time error to augment enum's
910
/// `values` getter.
1011
/// @author [email protected]
1112
1213
// SharedOptions=--enable-experiment=macros
1314

14-
part 'augmenting_enum_values_A01_t02_lib.dart';
15+
part 'augmenting_enum_values_A05_t01_lib.dart';
1516

1617
enum E1 {
1718
e0;

LanguageFeatures/Augmentation-libraries/augmenting_enum_values_A01_t02_lib.dart renamed to LanguageFeatures/Augmentation-libraries/augmenting_enum_values_A05_t01_lib.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// @assertion Enum values can only be augmented by enum values, and the
6-
/// implicit getter introduced by them is not augmentable.
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 `==`.
78
///
89
/// @description Checks that it is a compile-time error to augment enum's
910
/// `values` getter.
1011
/// @author [email protected]
1112
1213
// SharedOptions=--enable-experiment=macros
1314

14-
part of 'augmenting_enum_values_A01_t02.dart';
15+
part of 'augmenting_enum_values_A05_t01.dart';
1516

1617
augment enum E1 {
1718
augment e0;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 a compile-time error to augment enum's
10+
/// `index`, `hashCode` or `==` members.
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=macros
14+
15+
enum E1 {
16+
e0;
17+
}
18+
19+
augment enum E1 {
20+
augment e0;
21+
augment int get index => 0;
22+
//^^^^^^^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
}
26+
27+
enum E2 {
28+
e0;
29+
}
30+
31+
augment enum E2 {
32+
augment e0;
33+
augment int get hashCode => 0;
34+
//^^^^^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
38+
39+
enum E3 {
40+
e0;
41+
}
42+
43+
augment enum E3 {
44+
augment e0;
45+
augment bool operator ==(Object other) => true;
46+
//^^^^^^^
47+
// [analyzer] unspecified
48+
// [cfe] unspecified
49+
}
50+
51+
main() {
52+
print(E1);
53+
print(E2);
54+
print(E3);
55+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 a compile-time error if an enum's
10+
/// augmentation declares `index`, `hashCode` or `==` members.
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=macros
14+
15+
enum E1 {
16+
e0;
17+
}
18+
19+
augment enum E1 {
20+
augment e0;
21+
int get index => 0;
22+
// ^^^^^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
}
26+
27+
enum E2 {
28+
e0;
29+
}
30+
31+
augment enum E2 {
32+
augment e0;
33+
int get hashCode => 0;
34+
// ^^^^^^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
38+
39+
enum E3 {
40+
e0;
41+
}
42+
43+
augment enum E3 {
44+
augment e0;
45+
bool operator ==(Object other) => true;
46+
// ^^
47+
// [analyzer] unspecified
48+
// [cfe] unspecified
49+
}
50+
51+
main() {
52+
print(E1);
53+
print(E2);
54+
print(E3);
55+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
/// 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+
String get name => "name";
24+
}
25+
26+
enum E2 {
27+
e0;
28+
String get name => "name1";
29+
}
30+
31+
augment enum E2 {
32+
augment e0;
33+
augment String get name => "name2";
34+
}
35+
36+
enum E3 {
37+
e0;
38+
}
39+
40+
augment enum E3 {
41+
augment e0,
42+
name;
43+
}
44+
45+
enum E4 {
46+
e0, name;
47+
}
48+
49+
augment enum E4 {
50+
augment name;
51+
}
52+
53+
main() {
54+
Expect.equals("name", E1.e0.name);
55+
Expect.equals("name2", E2.e0.name);
56+
Expect.equals("E3.name", E3.name);
57+
Expect.equals("E4.name", E4.name);
58+
}

0 commit comments

Comments
 (0)