Skip to content

Commit 1ee4d2a

Browse files
committed
#3315. Move/add name conflict tests to Primary-constructors.
1 parent 59bc36e commit 1ee4d2a

12 files changed

+465
-12
lines changed

LanguageFeatures/Declaring-constructors/static_processing_A01_t01.dart renamed to LanguageFeatures/Primary-constructors/static_processing_A02_t01.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
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 A compile-time error occurs if a class, enum, or extension type
6-
/// has a primary constructor whose name is also the name of a constructor
7-
/// declared in the body.
5+
/// @assertion A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
810
///
911
/// @description Check that it is a compile-time error if a class has a primary
1012
/// constructor whose name is also the name of a constructor declared in the
@@ -28,7 +30,7 @@ class C2(final int v) {
2830
}
2931

3032
class C3.someName(var int v) {
31-
C3.someName();
33+
C3.someName(this.v);
3234
// ^^^^^^^^
3335
// [analyzer] unspecified
3436
// [cfe] unspecified
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2025, 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 A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
10+
///
11+
/// @description Check that it is a compile-time error if a mixin class has a
12+
/// primary constructor whose name is also the name of a constructor declared in
13+
/// the body.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=declaring-constructors
17+
18+
mixin class C1() {
19+
C1();
20+
//^^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
}
24+
25+
mixin class C2() {
26+
C2.new();
27+
// ^^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
}
31+
32+
mixin class C3.someName() {
33+
C3.someName();
34+
// ^^^^^^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
38+
39+
mixin class C4._() {
40+
C4._();
41+
// ^
42+
// [analyzer] unspecified
43+
// [cfe] unspecified
44+
}
45+
46+
main() {
47+
print(C1);
48+
print(C2);
49+
print(C3);
50+
print(C4);
51+
}

LanguageFeatures/Declaring-constructors/static_processing_A01_t02.dart renamed to LanguageFeatures/Primary-constructors/static_processing_A02_t03.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
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 A compile-time error occurs if a class, enum, or extension type
6-
/// has a primary constructor whose name is also the name of a constructor
7-
/// declared in the body.
5+
/// @assertion A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
810
///
911
/// @description Check that it is a compile-time error if an extension type has
1012
/// a primary constructor whose name is also the name of a constructor declared
@@ -28,7 +30,7 @@ extension type ET2(final int v) {
2830
}
2931

3032
extension type ET3.someName(int v) {
31-
ET3.someName();
33+
ET3.someName(this.v);
3234
// ^^^^^^^^
3335
// [analyzer] unspecified
3436
// [cfe] unspecified

LanguageFeatures/Declaring-constructors/static_processing_A01_t03.dart renamed to LanguageFeatures/Primary-constructors/static_processing_A02_t04.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
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 A compile-time error occurs if a class, enum, or extension type
6-
/// has a primary constructor whose name is also the name of a constructor
7-
/// declared in the body.
5+
/// @assertion A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
810
///
911
/// @description Check that it is a compile-time error if an enum has a primary
1012
/// constructor whose name is also the name of a constructor declared in the
@@ -34,7 +36,7 @@ enum const E2(final int v) {
3436
enum E3.someName(final int v) {
3537
e0.someName(3);
3638

37-
const E3.someName();
39+
const E3.someName(this.v);
3840
// ^^^^^^^^
3941
// [analyzer] unspecified
4042
// [cfe] unspecified
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2025, 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 A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
10+
///
11+
/// @description Check that it is a compile-time error if a class has a primary
12+
/// constructor whose name is `C.n`, and the body declares a static member whose
13+
/// basename is `n`.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=declaring-constructors
17+
18+
class C1.someName(var int v) {
19+
static int someName = 0;
20+
// ^^^^^^^^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
}
24+
25+
class C2.someName(final int v) {
26+
static int get someName => 0;
27+
// ^^^^^^^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
}
31+
32+
class C3._someName(var int v) {
33+
static void _someName(int _) {}
34+
// ^^^^^^^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
38+
39+
class C4.someName(final int v) {
40+
static void set someName(int _) {}
41+
// ^^^^^^^^
42+
// [analyzer] unspecified
43+
// [cfe] unspecified
44+
}
45+
46+
main() {
47+
print(C1);
48+
print(C2);
49+
print(C3);
50+
print(C4);
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2025, 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 A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
10+
///
11+
/// @description Check that it is a compile-time error if a mixin class has a
12+
/// primary constructor whose name is `C.n`, and the body declares a static
13+
/// member whose basename is `n`.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=declaring-constructors
17+
18+
mixin class C1.someName() {
19+
static int someName = 0;
20+
// ^^^^^^^^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
}
24+
25+
mixin class C2.someName() {
26+
static int get someName => 0;
27+
// ^^^^^^^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
}
31+
32+
mixin class C3._someName() {
33+
static void _someName() {}
34+
// ^^^^^^^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
38+
39+
mixin class C4.someName() {
40+
static void set someName(int _) {}
41+
// ^^^^^^^^
42+
// [analyzer] unspecified
43+
// [cfe] unspecified
44+
}
45+
46+
main() {
47+
print(C1);
48+
print(C2);
49+
print(C3);
50+
print(C4);
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) 2025, 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 A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
10+
///
11+
/// @description Check that it is a compile-time error if an extension type has
12+
/// a primary constructor whose name is `C.n`, and the body declares a static
13+
/// member whose basename is `n`.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=declaring-constructors
17+
18+
extension type ET1.someName(int _) {
19+
static int someName = 0;
20+
// ^^^^^^^^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
}
24+
25+
extension type ET2.someName(int _) {
26+
static int get someName => 0;
27+
// ^^^^^^^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
}
31+
32+
extension type ET3._someName(int _) {
33+
static void _someName(int _) {}
34+
// ^^^^^^^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
38+
39+
extension type ET4.someName(int _) {
40+
static void set someName(int _) {}
41+
// ^^^^^^^^
42+
// [analyzer] unspecified
43+
// [cfe] unspecified
44+
}
45+
46+
main() {
47+
print(ET1);
48+
print(ET2);
49+
print(ET3);
50+
print(ET4);
51+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2025, 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 A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
10+
///
11+
/// @description Check that it is a compile-time error if an enum has a primary
12+
/// constructor whose name is `C.n`, and the body declares a static member whose
13+
/// basename is `n`.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=declaring-constructors
17+
18+
enum E1.someName(int _) {
19+
e0.someName(1);
20+
static int someName = 0;
21+
// ^^^^^^^^
22+
// [analyzer] unspecified
23+
// [cfe] unspecified
24+
}
25+
26+
enum E2.someName(int _) {
27+
e0.someName(2);
28+
static int get someName => 0;
29+
// ^^^^^^^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
}
33+
34+
enum ET3._someName(int _) {
35+
e0._someName(3);
36+
static void _someName(int _) {}
37+
// ^^^^^^^^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
}
41+
42+
enum ET4.someName(int _) {
43+
e4.someName(4);
44+
static void set someName(int _) {}
45+
// ^^^^^^^^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
}
49+
50+
main() {
51+
print(E1);
52+
print(E2);
53+
print(E3);
54+
print(E4);
55+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2025, 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 A compile-time error occurs if a class, mixin class, enum, or
6+
/// extension type has a primary constructor whose name is also the name of a
7+
/// constructor declared in the body, or if it declares a primary constructor
8+
/// whose name is `C.n`, and the body declares a static member whose basename is
9+
/// `n`.
10+
///
11+
/// @description Check that it is not an error if a class has a primary
12+
/// constructor whose name is `C.n`, and the body declares an instance member
13+
/// whose basename is `n`.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=declaring-constructors
17+
18+
import '../../Utils/expect.dart';
19+
20+
class C1.someName(var int v) {
21+
int someName = 0;
22+
}
23+
24+
class C2.someName(final int v) {
25+
int get someName => v;
26+
}
27+
28+
class C3._someName(final int v) {
29+
int _someName() => v;
30+
}
31+
32+
class C4.someName(var int v) {
33+
void set someName(int x) {
34+
v = x;
35+
}
36+
}
37+
38+
main() {
39+
Expect.equals(0, C1.someName(1).someName);
40+
Expect.equals(2, C2.someName(2).someName);
41+
Expect.equals(3, C3._someName(3)._someName());
42+
var c4 = C4.someName(0);
43+
c4.someName = 4;
44+
Expect.equals(4, c4.v);
45+
}

0 commit comments

Comments
 (0)