Skip to content

Commit 730bdea

Browse files
committed
#3182. Update augmenting_constructors_A02-04* tests
1 parent 6dc3fad commit 730bdea

12 files changed

+266
-188
lines changed

LanguageFeatures/Augmentations/augmenting_constructors_A02_t01.dart

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,69 @@
44

55
/// @assertion It is a compile-time error if:
66
/// ...
7-
/// - The augmenting constructor parameters specify any default values.
7+
/// - More than one declaration in the augmentation chain specifies a default
8+
/// value for the same optional parameter. This is an error even in the case
9+
/// where all of them are identical.
810
///
9-
/// @description Checks that it is a compile-time error if the augmenting
10-
/// constructor parameters specify any default values.
11+
/// @description Checks that it is a compile-time error when both the augmenting
12+
/// constructor parameters and the introductory declaration specify default
13+
/// values.
1114
/// @author [email protected]
1215
13-
// SharedOptions=--enable-experiment=macros
14-
15-
part 'augmenting_constructors_A02_t01_lib.dart';
16+
// SharedOptions=--enable-experiment=augmentations
1617

1718
class C {
1819
C([int x = 0]);
1920
C.c1({int x = 0});
2021
}
2122

23+
augment class C {
24+
augment C([int x = 0]);
25+
// ^
26+
// [analyzer] unspecified
27+
// [cfe] unspecified
28+
29+
augment C.c1({int x = 0});
30+
// ^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
}
34+
2235
enum E {
23-
e0(0);
36+
e0, e1.c1();
2437
const E([int x = 0]);
2538
const E.c1({int x = 0});
2639
}
2740

41+
augment enum E {
42+
augment const E([int x = 0]);
43+
// ^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
47+
augment const E.c1({int x = 0});
48+
// ^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
}
52+
2853
extension type ET(int id) {
2954
ET.c1(this.id, [int x = 0]);
3055
ET.c2(this.id, {int x = 0});
3156
}
3257

58+
augment extension type ET {
59+
augment ET.c1(this.id, [int x = 0]);
60+
// ^
61+
// [analyzer] unspecified
62+
// [cfe] unspecified
63+
64+
augment ET.c2(this.id, {int x = 0});
65+
// ^
66+
// [analyzer] unspecified
67+
// [cfe] unspecified
68+
}
69+
3370
main() {
3471
print(C);
3572
print(E);

LanguageFeatures/Augmentations/augmenting_constructors_A02_t01_lib.dart

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 It is a compile-time error if:
6+
/// ...
7+
/// - More than one declaration in the augmentation chain specifies a default
8+
/// value for the same optional parameter. This is an error even in the case
9+
/// where all of them are identical.
10+
///
11+
/// @description Checks that it is a compile-time error when more than one
12+
/// augmenting constructor declaration specify default values.
13+
/// @author [email protected]
14+
15+
// SharedOptions=--enable-experiment=augmentations
16+
17+
class C {
18+
C([int x]);
19+
C.c1({int x});
20+
}
21+
22+
augment class C {
23+
augment C([int x = 0]);
24+
augment C.c1({int x = 0});
25+
}
26+
27+
augment class C {
28+
augment C([int x = 0]);
29+
// ^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
33+
augment C.c1({int x = 0});
34+
// ^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
38+
39+
enum E {
40+
e0, e1.c1();
41+
const E([int x]);
42+
const E.c1({int x});
43+
}
44+
45+
augment enum E {
46+
augment const E([int x = 0]);
47+
augment const E.c1({int x = 0});
48+
}
49+
50+
augment enum E {
51+
augment const E([int x = 0]);
52+
// ^
53+
// [analyzer] unspecified
54+
// [cfe] unspecified
55+
56+
augment const E.c1({int x = 0});
57+
// ^
58+
// [analyzer] unspecified
59+
// [cfe] unspecified
60+
}
61+
62+
extension type ET(int id) {
63+
ET.c1(this.id, [int x]);
64+
ET.c2(this.id, {int x});
65+
}
66+
67+
augment extension type ET {
68+
augment ET.c1(this.id, [int x = 0]);
69+
augment ET.c2(this.id, {int x = 0});
70+
}
71+
72+
augment extension type ET {
73+
augment ET.c1(this.id, [int x = 0]);
74+
// ^
75+
// [analyzer] unspecified
76+
// [cfe] unspecified
77+
78+
augment ET.c2(this.id, {int x = 0});
79+
// ^
80+
// [analyzer] unspecified
81+
// [cfe] unspecified
82+
}
83+
84+
main() {
85+
print(C);
86+
print(E);
87+
print(ET);
88+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 It is a compile-time error if:
6+
/// ...
7+
/// - More than one declaration in the augmentation chain specifies a default
8+
/// value for the same optional parameter. This is an error even in the case
9+
/// where all of them are identical.
10+
///
11+
/// @description Checks that it is not an error if augmenting constructor
12+
/// specifies default values for optional parameters.
13+
/// @author [email protected]
14+
15+
// SharedOptions=--enable-experiment=augmentations
16+
17+
import '../../Utils/expect.dart';
18+
19+
class C {
20+
int x;
21+
C([int x]);
22+
C.c1({int x});
23+
}
24+
25+
augment class C {
26+
augment C([int x = 1]) : x = x;
27+
augment C.c1({int x = 2}) : x = x;
28+
}
29+
30+
enum E {
31+
e0, e1.c1();
32+
33+
final int x;
34+
const E([int x]);
35+
const E.c1({int x});
36+
}
37+
38+
augment enum E {
39+
augment const E([int x = 1]) : x = x;
40+
augment const E.c1({int x = 2}) : x = x;
41+
}
42+
43+
String log = "";
44+
45+
extension type ET(int id) {
46+
ET.c1(this.id, [int x]);
47+
ET.c2(this.id, {int x});
48+
}
49+
50+
augment extension type ET {
51+
augment ET.c1(this.id, [int x = 1]) : assert(() {
52+
log = "$x";
53+
return true;
54+
}());
55+
augment ET.c2(this.id, {int x = 2}) assert(() {
56+
log = "$x";
57+
return true;
58+
}());
59+
}
60+
61+
main() {
62+
Expect.equals(1, C().x);
63+
Expect.equals(2, C.c1().x);
64+
Expect.equals(1, E.e0.x);
65+
Expect.equals(2, E.e1.x);
66+
ET.c1(0);
67+
if (assertStatementsEnabled()) {
68+
Expect.equals("1", log);
69+
}
70+
ET.c2(0);
71+
if (assertStatementsEnabled()) {
72+
Expect.equals("2", log);
73+
}
74+
}

LanguageFeatures/Augmentations/augmenting_constructors_A03_t01.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@
1111
/// constructor is `const` and the augmenting constructor is not.
1212
/// @author [email protected]
1313
14-
// SharedOptions=--enable-experiment=macros
15-
16-
part 'augmenting_constructors_A03_t01_lib.dart';
14+
// SharedOptions=--enable-experiment=augmentations
1715

1816
class C {
1917
const C();
2018
}
2119

20+
augment class C {
21+
augment C();
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
}
26+
2227
extension type ET(int id) {
2328
const ET.foo(this.id);
2429
}
2530

31+
augment extension type ET {
32+
augment ET.foo(this.id);
33+
// ^^^^^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
}
37+
2638
main() {
2739
print(C);
2840
print(ET);

LanguageFeatures/Augmentations/augmenting_constructors_A03_t01_lib.dart

Lines changed: 0 additions & 30 deletions
This file was deleted.

LanguageFeatures/Augmentations/augmenting_constructors_A03_t02.dart

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,30 @@
1111
/// constructor is `const` and the introductory constructor is not.
1212
/// @author [email protected]
1313
14-
// SharedOptions=--enable-experiment=macros
15-
16-
part 'augmenting_constructors_A03_t02_lib.dart';
14+
// SharedOptions=--enable-experiment=augmentations
1715

1816
class C {
1917
C();
2018
}
2119

20+
augment class C {
21+
augment const C();
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
}
26+
2227
extension type ET(int id) {
2328
ET.foo(this.id);
2429
}
2530

31+
augment extension type ET {
32+
augment const ET.foo(this.id);
33+
// ^^^^^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
}
37+
2638
main() {
2739
print(C);
2840
print(ET);

0 commit comments

Comments
 (0)