Skip to content

Commit e6b87e6

Browse files
authored
#3315. Update and move extension types tests to Primary-constructors (#3396)
Update and move extension types tests to `Primary-constructors`
1 parent a6b4d3e commit e6b87e6

File tree

7 files changed

+148
-206
lines changed

7 files changed

+148
-206
lines changed

LanguageFeatures/Declaring-constructors/static_processing_A04_t02.dart

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

LanguageFeatures/Declaring-constructors/static_processing_A04_t03.dart

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

LanguageFeatures/Declaring-constructors/static_processing_A04_t04.dart

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

LanguageFeatures/Declaring-constructors/static_processing_A04_t05.dart

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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 Consider a class, mixin class, enum, or extension type
6+
/// declaration `D` with a primary constructor (note that it cannot be a
7+
/// `<mixinApplicationClass>`, because that kind of declaration does not
8+
/// syntactically support primary constructors). This declaration is treated as
9+
/// a class, mixin class, enum, respectively extension type declaration without
10+
/// a primary constructor which is obtained as described in the following. This
11+
/// determines the dynamic semantics of a primary constructor.
12+
/// ...
13+
/// If `D` is an extension type, it is a compile-time error if the primary
14+
/// constructor that `D` contains does not have exactly one parameter.
15+
///
16+
/// @description Check that it is a compile-time error if an extension type does
17+
/// not contain a primary constructor that has exactly one declaring parameter
18+
/// which is `final`.
19+
/// @author [email protected]
20+
21+
// SharedOptions=--enable-experiment=declaring-constructors
22+
23+
extension type const ET1(var int v) {}
24+
// ^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
28+
extension type ET2.someName(var int v) {}
29+
// ^^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
33+
extension type ET3([var int v = 0]) {}
34+
// ^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
38+
extension type const ET4.someName([var int v = 0]) {}
39+
// ^^^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
43+
extension type const ET5({var int v = 0}) {}
44+
// ^^^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
48+
extension type ET6.someName({var int v = 0}) {}
49+
// ^^^
50+
// [analyzer] unspecified
51+
// [cfe] unspecified
52+
53+
extension type ET7({required var int v}) {}
54+
// ^^^
55+
// [analyzer] unspecified
56+
// [cfe] unspecified
57+
58+
extension type const ET8.someName({required var int v}) {}
59+
// ^^^
60+
// [analyzer] unspecified
61+
// [cfe] unspecified
62+
63+
main() {
64+
print(ET1);
65+
print(ET2);
66+
print(ET3);
67+
print(ET4);
68+
print(ET5);
69+
print(ET6);
70+
print(ET7);
71+
print(ET8);
72+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 Consider a class, mixin class, enum, or extension type
6+
/// declaration `D` with a primary constructor (note that it cannot be a
7+
/// `<mixinApplicationClass>`, because that kind of declaration does not
8+
/// syntactically support primary constructors). This declaration is treated as
9+
/// a class, mixin class, enum, respectively extension type declaration without
10+
/// a primary constructor which is obtained as described in the following. This
11+
/// determines the dynamic semantics of a primary constructor.
12+
/// ...
13+
/// If `D` is an extension type, it is a compile-time error if the primary
14+
/// constructor that `D` contains does not have exactly one parameter.
15+
///
16+
/// @description Check that it is not an error if an extension type contains
17+
/// a primary constructor that has exactly one parameter.
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=declaring-constructors
21+
22+
import '../../Utils/expect.dart';
23+
24+
extension type const ET1(final int v);
25+
26+
extension type const ET2({final int v = 0});
27+
28+
// Representation variable below is `final` by default
29+
extension type ET3.someName([int v = 0]);
30+
31+
extension type const ET4._({required int v}); // It is allowed to omit `final` here
32+
33+
main() {
34+
Expect.equals(1, ET1(1).v);
35+
Expect.equals(0, ET2().v);
36+
Expect.equals(2, ET2(v: 2).v);
37+
Expect.equals(0, ET3.someName().v);
38+
Expect.equals(3, ET3.someName(3).v);
39+
Expect.equals(4, ET4._(v: 4).v);
40+
}

LanguageFeatures/Declaring-constructors/static_processing_A04_t01.dart renamed to LanguageFeatures/Primary-constructors/static_processing_A05_t03.dart

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,55 @@
1616
1717
// SharedOptions=--enable-experiment=declaring-constructors
1818

19-
extension type const ET1(var int v);
20-
// ^^^
19+
extension type const ET1();
20+
// ^
2121
// [analyzer] unspecified
2222
// [cfe] unspecified
2323

24-
extension type ET2.someName(var int v);
25-
// ^^^
24+
extension type ET2.someName();
25+
// ^
2626
// [analyzer] unspecified
2727
// [cfe] unspecified
2828

29-
extension type ET3 {
30-
this(var int v);
31-
// ^^^
29+
extension type ET3(int v1, final int _);
30+
// ^
3231
// [analyzer] unspecified
3332
// [cfe] unspecified
34-
}
3533

36-
extension type ET4 {
37-
const this.someName(var int v);
38-
// ^^^
34+
extension type const ET4.someName(final int v1, final int v2);
35+
// ^
3936
// [analyzer] unspecified
4037
// [cfe] unspecified
41-
}
4238

43-
extension type ET5 {
44-
const this(int v);
45-
// ^
39+
extension type ET5(int v1, [int v2 = 0]);
40+
// ^
4641
// [analyzer] unspecified
4742
// [cfe] unspecified
48-
}
4943

50-
extension type ET6 {
51-
this(int v);
52-
// ^
44+
extension type const ET6.someName([final int v1 = 1, final int _ = 2]);
45+
// ^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
49+
extension type ET7(int v1, {int v2 = 0});
50+
// ^
51+
// [analyzer] unspecified
52+
// [cfe] unspecified
53+
54+
extension type const ET8.someName({final int v1 = 1, final int v2 = 2});
55+
// ^
56+
// [analyzer] unspecified
57+
// [cfe] unspecified
58+
59+
extension type ET9({required int v1, required int v2});
60+
// ^
61+
// [analyzer] unspecified
62+
// [cfe] unspecified
63+
64+
extension type const ET10.someName(int v1, {required final int v2 = 2});
65+
// ^
5366
// [analyzer] unspecified
5467
// [cfe] unspecified
55-
}
5668

5769
main() {
5870
print(ET1);
@@ -61,4 +73,8 @@ main() {
6173
print(ET4);
6274
print(ET5);
6375
print(ET6);
76+
print(ET7);
77+
print(ET8);
78+
print(ET9);
79+
print(ET10);
6480
}

0 commit comments

Comments
 (0)