Skip to content

Commit 15158f7

Browse files
authored
#2641. Check that it is still an error to declare more than one class member named _ (#2669)
Check that it is still an error to declare more than one class member named `_`
1 parent e9bb3ed commit 15158f7

12 files changed

+1612
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 Other declarations: top-level variables, top-level function
6+
/// names, type names, member names, etc. are unchanged. They can be named `_`
7+
/// as they are today.
8+
///
9+
/// @description Checks that a member named `_` is still accessible and its
10+
/// value can be used. Test mixin members
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=wildcard-variables
14+
15+
import '../../Utils/expect.dart';
16+
17+
mixin M1 {
18+
static int _ = 1;
19+
}
20+
21+
mixin M2 {
22+
static int _() => 2;
23+
}
24+
25+
mixin M3 {
26+
static int get _ => 3;
27+
}
28+
29+
mixin M4 {
30+
static void set _(int v) {}
31+
}
32+
33+
mixin M5 {
34+
int _ = 5;
35+
}
36+
37+
mixin M6 {
38+
int _() => 6;
39+
}
40+
41+
mixin M7 {
42+
int get _ => 7;
43+
}
44+
45+
mixin M8 {
46+
void set _(int v) {}
47+
}
48+
49+
class MA5 = Object with M5;
50+
class MA6 = Object with M6;
51+
class MA7 = Object with M7;
52+
class MA8 = Object with M8;
53+
54+
main() {
55+
Expect.equals(1, M1._);
56+
Expect.equals(2, M2._());
57+
Expect.equals(3, M3._);
58+
M4._ = 42;
59+
Expect.equals(5, MA5()._);
60+
Expect.equals(6, MA6()._());
61+
Expect.equals(7, MA7()._);
62+
MA8()._ = 42;
63+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 Other declarations: top-level variables, top-level function
6+
/// names, type names, member names, etc. are unchanged. They can be named `_`
7+
/// as they are today.
8+
///
9+
/// @description Checks that a member named `_` is still accessible and its
10+
/// value can be used. Test enum members
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=wildcard-variables
14+
15+
import '../../Utils/expect.dart';
16+
17+
enum E1 {
18+
e1;
19+
static int _ = 1;
20+
}
21+
22+
enum E2 {
23+
e1;
24+
static int _() => 2;
25+
}
26+
27+
enum E3 {
28+
e1;
29+
static int get _ => 3;
30+
}
31+
32+
enum E4 {
33+
e1;
34+
static void set _(int v) {}
35+
}
36+
37+
enum E5 {
38+
e1;
39+
final int _ = 5;
40+
}
41+
42+
enum E6 {
43+
e1;
44+
int _() => 6;
45+
}
46+
47+
enum E7 {
48+
e1;
49+
int get _ => 7;
50+
}
51+
52+
enum E8 {
53+
e1;
54+
void set _(int v) {}
55+
}
56+
57+
main() {
58+
Expect.equals(1, E1._);
59+
Expect.equals(2, E2._());
60+
Expect.equals(3, E3._);
61+
E4._ = 42;
62+
Expect.equals(5, E5.e1._);
63+
Expect.equals(6, E6.e1._());
64+
Expect.equals(7, E7.e1._);
65+
E8.e1._ = 42;
66+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 Other declarations: top-level variables, top-level function
6+
/// names, type names, member names, etc. are unchanged. They can be named `_`
7+
/// as they are today.
8+
///
9+
/// @description Checks that a member named `_` is still accessible and its
10+
/// value can be used. Test extension type members
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=wildcard-variables
14+
15+
import '../../Utils/expect.dart';
16+
17+
extension type ET1(int id) {
18+
static int _ = 1;
19+
}
20+
21+
extension type ET2(int id) {
22+
static int _() => 2;
23+
}
24+
25+
extension type ET3(int id) {
26+
static int get _ => 3;
27+
}
28+
29+
extension type ET4(int id) {
30+
static void set _(int v) {}
31+
}
32+
33+
extension type ET5(int id) {
34+
int _() => 5;
35+
}
36+
37+
extension type ET6(int id) {
38+
int get _ => 6;
39+
}
40+
41+
extension type ET7(int id) {
42+
void set _(int v) {}
43+
}
44+
45+
main() {
46+
Expect.equals(1, ET1._);
47+
Expect.equals(2, ET2._());
48+
Expect.equals(3, ET3._);
49+
ET4._ = 42;
50+
Expect.equals(5, ET5(1)._());
51+
Expect.equals(6, ET6(1)._);
52+
ET7(1)._ = 42;
53+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 Other declarations: top-level variables, top-level function
6+
/// names, type names, member names, etc. are unchanged. They can be named `_`
7+
/// as they are today.
8+
///
9+
/// @description Checks that a member named `_` is still accessible and its
10+
/// value can be used. Test extension members
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=wildcard-variables
14+
15+
import '../../Utils/expect.dart';
16+
17+
class A1 {}
18+
extension Ext1 on A1 {
19+
static int _ = 1;
20+
}
21+
22+
class A2 {}
23+
extension Ext2 on A2 {
24+
static int _() => 2;
25+
}
26+
27+
class A3 {}
28+
extension Ext3 on A3 {
29+
static int get _ => 3;
30+
}
31+
32+
class A4 {}
33+
extension Ext4 on A4 {
34+
static void set _(int v) {}
35+
}
36+
37+
class A5 {}
38+
extension Ext5 on A5 {
39+
int _() => 5;
40+
}
41+
42+
class A6 {}
43+
extension Ext6 on A6 {
44+
int get _ => 6;
45+
}
46+
47+
class A7 {}
48+
extension Ext7 on A7 {
49+
void set _(int v) {}
50+
}
51+
52+
main() {
53+
Expect.equals(1, Ext1._);
54+
Expect.equals(2, Ext2._());
55+
Expect.equals(3, Ext3._);
56+
Ext4._ = 42;
57+
Expect.equals(5, A5()._());
58+
Expect.equals(6, A6()._);
59+
A7()._ = 42;
60+
}

0 commit comments

Comments
 (0)