Skip to content

Commit 2592c1c

Browse files
authored
#3329. Add tests for "corresponding public name" (#3361)
Add tests for "corresponding public name".
1 parent 317b9ea commit 2592c1c

File tree

5 files changed

+336
-0
lines changed

5 files changed

+336
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 Given a named initializing formal or field parameter (for a
6+
/// primary constructor) with private name `p` in constructor `C`:
7+
/// - If `p` has no corresponding public name `n`, then compile-time error.
8+
///
9+
/// @description Check that it is a compile-time error if a named initializing
10+
/// formal parameter has a private name that has no corresponding public name.
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=private-named-parameters
14+
15+
class C {
16+
String __p;
17+
C({this.__p = ""});
18+
// ^^^
19+
// [analyzer] unspecified
20+
// [cfe] unspecified
21+
22+
C._({required this.__p});
23+
// ^^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
}
27+
28+
extension type ET._(String __p) {
29+
ET({this.__p = ""});
30+
// ^^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
34+
ET.named({required this.__p});
35+
// ^^^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
38+
}
39+
40+
enum E {
41+
e0;
42+
43+
final String __p;
44+
const E({this.__p = ""});
45+
// ^^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
49+
const E.named({required this.__p});
50+
// ^^^
51+
// [analyzer] unspecified
52+
// [cfe] unspecified
53+
}
54+
55+
main() {
56+
print(C);
57+
print(ET);
58+
print(E);
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 Given a named initializing formal or field parameter (for a
6+
/// primary constructor) with private name `p` in constructor `C`:
7+
/// - If `p` has no corresponding public name `n`, then compile-time error.
8+
///
9+
/// @description Check that it is a compile-time error if a named initializing
10+
/// formal parameter has a private name that has no corresponding public name.
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=private-named-parameters
14+
15+
class C {
16+
String _1;
17+
C({this._1 = ""});
18+
// ^^
19+
// [analyzer] unspecified
20+
// [cfe] unspecified
21+
22+
C._({required this._1});
23+
// ^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
}
27+
28+
extension type ET._(String _1) {
29+
ET({this._1 = ""});
30+
// ^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
34+
ET.named({required this._1});
35+
// ^^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
38+
}
39+
40+
enum E {
41+
e0;
42+
43+
final String _1;
44+
const E({this._1 = ""});
45+
// ^^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
49+
const E.named({required this._1});
50+
// ^^
51+
// [analyzer] unspecified
52+
// [cfe] unspecified
53+
}
54+
55+
main() {
56+
print(C);
57+
print(ET);
58+
print(E);
59+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 Given a named initializing formal or field parameter (for a
6+
/// primary constructor) with private name `p` in constructor `C`:
7+
/// - If `p` has no corresponding public name `n`, then compile-time error.
8+
///
9+
/// @description Check that it is a compile-time error if a named formal
10+
/// parameter of a declaring constructor has a private name with no
11+
/// corresponding public name.
12+
/// @author [email protected]
13+
14+
// SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors
15+
16+
class C1({var String __p}) {
17+
// ^^^
18+
// [analyzer] unspecified
19+
// [cfe] unspecified
20+
}
21+
22+
class C2({required final String _1}) {
23+
// ^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
}
27+
28+
class C3 {
29+
this({required final String __p});
30+
// ^^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
}
34+
35+
class C4 {
36+
this({var String _1 = ""});
37+
// ^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
}
41+
42+
extension type ET1 {
43+
this({final String __p = ""});
44+
// ^^^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
}
48+
49+
extension type ET2 {
50+
this({final String _1 = ""});
51+
// ^^
52+
// [analyzer] unspecified
53+
// [cfe] unspecified
54+
}
55+
56+
enum E1({required final String __p}) {
57+
// ^^^
58+
// [analyzer] unspecified
59+
// [cfe] unspecified
60+
e0(_p: "");
61+
// ^^
62+
// [analyzer] unspecified
63+
// [cfe] unspecified
64+
}
65+
66+
enum E2 {
67+
e0;
68+
69+
const this({final String _1 = ""});
70+
// ^^
71+
// [analyzer] unspecified
72+
// [cfe] unspecified
73+
}
74+
75+
main() {
76+
print(C1);
77+
print(C2);
78+
print(C3);
79+
print(C4);
80+
print(ET1);
81+
print(ET2);
82+
print(E1);
83+
print(E2);
84+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 Given a named initializing formal or field parameter (for a
6+
/// primary constructor) with private name `p` in constructor `C`:
7+
/// - If `p` has no corresponding public name `n`, then compile-time error. You
8+
/// can't use a private name for a named parameter unless there is a valid
9+
/// public name that could be used at the call site.
10+
/// - If any other parameter in `C` has declared name `p` or `n`, then
11+
/// compile-time error.
12+
///
13+
/// @description Check that it is a compile-time error if any other parameter in
14+
/// `C` has declared name `p` or `n`.
15+
/// @author [email protected]
16+
17+
// SharedOptions=--enable-experiment=private-named-parameters
18+
19+
class C {
20+
String _p;
21+
String p;
22+
C(int? _p, {this._p = ""}) : p = "";
23+
// ^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
27+
C._({required this._p, this.p});
28+
// ^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
}
32+
33+
extension type ET._(String _p) {
34+
ET(int _p, {this._p = ""});
35+
// ^^
36+
// [analyzer] unspecified
37+
// [cfe] unspecified
38+
39+
ET.named({required this._p, int? p});
40+
// ^
41+
// [analyzer] unspecified
42+
// [cfe] unspecified
43+
}
44+
45+
enum E {
46+
e0(1);
47+
48+
final String _p;
49+
final int? p;
50+
const E(int? _p, {this._p = ""});
51+
// ^^
52+
// [analyzer] unspecified
53+
// [cfe] unspecified
54+
55+
const E.named({required this._p, this.p});
56+
// ^
57+
// [analyzer] unspecified
58+
// [cfe] unspecified
59+
}
60+
61+
main() {
62+
print(C);
63+
print(ET);
64+
print(E);
65+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 Given a named initializing formal or field parameter (for a
6+
/// primary constructor) with private name `p` in constructor `C`:
7+
/// - If `p` has no corresponding public name `n`, then compile-time error. You
8+
/// can't use a private name for a named parameter unless there is a valid
9+
/// public name that could be used at the call site.
10+
/// - If any other parameter in `C` has declared name `p` or `n`, then
11+
/// compile-time error.
12+
///
13+
/// @description Check that it is a compile-time error if any other parameter in
14+
/// `C` has declared name `p` or `n`.
15+
/// @author [email protected]
16+
17+
// SharedOptions=--enable-experiment=private-named-parameters,declaring-constructors
18+
19+
class C1(int? _p, {var String _p = ""}) {
20+
// ^^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
}
24+
25+
class C2 {
26+
this({final String _p = "", int p = 0});
27+
// ^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
}
31+
32+
extension type ET1 {
33+
this(int _p, {final String _p = ""});
34+
// ^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
38+
39+
extension type ET2 {
40+
this({final String _p = "", int p = 0});
41+
// ^
42+
// [analyzer] unspecified
43+
// [cfe] unspecified
44+
}
45+
46+
enum E1(int? _p, {final String _p = ""}) {
47+
// ^^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
e0;
51+
}
52+
53+
enum E2 {
54+
e0;
55+
56+
const this({final String _p = "", final int? p});
57+
// ^
58+
// [analyzer] unspecified
59+
// [cfe] unspecified
60+
}
61+
62+
main() {
63+
print(C1);
64+
print(C2);
65+
print(ET1);
66+
print(ET2);
67+
print(E1);
68+
print(E2);
69+
}

0 commit comments

Comments
 (0)