Skip to content

Commit 5f2610d

Browse files
lrhnCommit Queue
authored andcommitted
Add tests for issue 53625.
Tests valid and invalid extension type representation type and representation object reference declarations. Bug: https://dartbug.com/53625 Change-Id: I56b61e4c7e691db975da286b31a93a0635257088 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328160 Commit-Queue: Lasse Nielsen <[email protected]> Reviewed-by: Erik Ernst <[email protected]>
1 parent 85fd1b8 commit 5f2610d

File tree

2 files changed

+324
-0
lines changed

2 files changed

+324
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// Copyright (c) 2023, 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+
// SharedOptions=--enable-experiment=inline-class
6+
7+
import "dart:async" show FutureOr;
8+
9+
// Extension type declarations must have a "representation declaration"
10+
// of the form: '(' <metadata> <type> <identifier> ')'
11+
//
12+
// Any type term is allowed.
13+
14+
// Any special, or semi-special, type is allowed.
15+
extension type V01(dynamic _) {}
16+
extension type V02(void _) {}
17+
extension type V03(Never _) {}
18+
extension type V04(Null _) {}
19+
extension type V05(Function _) {}
20+
extension type V06(Record _) {}
21+
extension type V07(Type _) {}
22+
extension type V08(Object? _) {}
23+
extension type V09(FutureOr<int> _) {}
24+
extension type V10(FutureOr<int>? _) {}
25+
26+
// Interface types.
27+
extension type V11(List<int> _) {}
28+
extension type V12(IType _) {}
29+
extension type V13(FType _) {}
30+
extension type V14(SType _) {}
31+
extension type V15(MType _) {}
32+
extension type V16(EType _) {}
33+
34+
// Extension types.
35+
extension type V17(ExtType _) {}
36+
37+
// Record types.
38+
extension type V18(() _) {}
39+
extension type V19((int,) _) {}
40+
extension type V20(({int x}) _) {}
41+
extension type V21((int, String) _) {}
42+
extension type V22((int, {String x}) _) {}
43+
extension type V23(({int x, String y}) _) {}
44+
45+
// Function types
46+
extension type V24(Function() _) {}
47+
extension type V25(void Function() _) {}
48+
extension type V26(void Function(int) _) {}
49+
extension type V27(void Function(int x) _) {}
50+
extension type V28(void Function(int, String) _) {}
51+
extension type V29(void Function(int, [String]) _) {}
52+
extension type V30(void Function([int, String]) _) {}
53+
extension type V31(void Function(int, {String y}) _) {}
54+
extension type V32(void Function({int x, String y}) _) {}
55+
extension type V33(void Function(int, {required String y}) _) {}
56+
extension type V34(void Function({required int x, String y}) _) {}
57+
extension type V35(Function Function(Function) Function() _) {}
58+
59+
// Type variables
60+
extension type V36<T>(T _) {}
61+
extension type V37<T>(List<T> _) {}
62+
extension type V38<T>(FutureOr<T?>? _) {}
63+
64+
// Type aliases
65+
extension type V39(AType _) {}
66+
extension type V40(A<IType> _) {}
67+
extension type V41(A<FType> _) {}
68+
extension type V42(A<SType> _) {}
69+
extension type V43(A<MType> _) {}
70+
extension type V44(A<EType> _) {}
71+
extension type V45(A<ExtType> _) {}
72+
73+
// And can be created.
74+
void main() {
75+
V01(1)._;
76+
V02(1)._;
77+
try {
78+
V03(0 as Never)._;
79+
} on Error {
80+
// Expected!
81+
}
82+
V04(null)._;
83+
V05(() {})._;
84+
V06(())._;
85+
V07(int)._;
86+
V08(1)._;
87+
V09(1)._;
88+
V10(1)._;
89+
V11([])._;
90+
V12(instance)._;
91+
V13(instance)._;
92+
V14(instance)._;
93+
V15(instance)._;
94+
V16(instance)._;
95+
V17(ExtType(int))._;
96+
V18(())._;
97+
V19((1,))._;
98+
V20((x: 1))._;
99+
V21((1, "2"))._;
100+
V22((1, x: "2"))._;
101+
V23((x: 1, y: "2"))._;
102+
V24(() {})._;
103+
V25(() {})._;
104+
V26((int x) {})._;
105+
V27((int x) {})._;
106+
V28((int x, String y) {})._;
107+
V29((int x, [String y = "0"]) {})._;
108+
V30(([int x = 0, String y = "0"]) {})._;
109+
V31((int x, {String y = "0"}) {})._;
110+
V32(({int x = 0, String y = "0"}) {})._;
111+
V33((int x, {required String y}) {})._;
112+
V34(({required int x, String y = "0"}) {})._;
113+
V35(() => (Function f) => f)._;
114+
V36<Type>(int)._;
115+
V37<Type>([int])._;
116+
V38<Type>(int)._;
117+
V39(int)._;
118+
V40(instance)._;
119+
V41(instance)._;
120+
V42(instance)._;
121+
V43(instance)._;
122+
V44(instance)._;
123+
V45(ExtType(int))._;
124+
}
125+
126+
// Helpers.
127+
extension type ExtType(Type x) implements Type {}
128+
129+
abstract interface class IType implements Type {}
130+
131+
mixin MType implements Type {}
132+
133+
sealed class SType with MType {}
134+
135+
final class FType extends SType implements IType {}
136+
137+
enum EType implements FType { e }
138+
139+
typedef A<X> = X;
140+
typedef AType = Type;
141+
const instance = EType.e;
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
// Copyright (c) 2023, 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+
// SharedOptions=--enable-experiment=inline-class
6+
7+
// Regression check for https://dartbug.com/53625
8+
//
9+
// Extension type declarations must have a "representation declaration"
10+
// of the form: '(' <metadata> <type> <identifier> ')'
11+
// where `<metadata>` can be empty, the other two not.
12+
//
13+
// Any other format is (currently) disallowed.
14+
15+
16+
// The "representation declaration" is like the parameter list of
17+
// an implicit constructor.
18+
// It still does not accept any other parameter list shape than the above.
19+
20+
extension type E00(int) {}
21+
// ^^^
22+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE
23+
// ^
24+
// [cfe] unspecified
25+
26+
extension type E01(int x,) {}
27+
// ^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
31+
extension type E02(final int x) {}
32+
// ^^^^^
33+
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
34+
// [cfe] unspecified
35+
36+
extension type E03(var x) {}
37+
// ^^^
38+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE
39+
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
40+
// [cfe] unspecified
41+
42+
extension type E04(final x) {}
43+
// ^^^^^
44+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE
45+
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
46+
// [cfe] unspecified
47+
48+
extension type E05(covariant int x) {}
49+
// ^
50+
// [cfe] unspecified
51+
52+
extension type E06(required int x) {}
53+
// ^^^^^^^^
54+
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
55+
// [cfe] unspecified
56+
57+
extension type E07(int this.x) {} // Initializing formal.
58+
// ^^^^^^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
extension type E08(this.x) {} // Initializing formal.
63+
// ^^^^^^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
67+
extension type E09(int super.x) implements E {} // Constructor super-parameter.
68+
// ^^^^^^^
69+
// [analyzer] unspecified
70+
// [cfe] unspecified
71+
72+
extension type E10(super.x) implements E {} // Constructor super-parameter.
73+
// ^^^^^^^
74+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD
75+
// [cfe] unspecified
76+
77+
extension type E11(int x()) {} // Old-style function parameter syntax.
78+
// ^^^^^^^
79+
// [analyzer] unspecified
80+
// [cfe] unspecified
81+
82+
// The "primary parameter" declares a "field",
83+
// but still does not accept field modifiers or initializers.
84+
85+
extension type E12(late int x) {}
86+
// ^^^^
87+
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
88+
// [cfe] unspecified
89+
90+
extension type E13(int x = 0) {}
91+
// ^^^
92+
// [analyzer] unspecified
93+
// [cfe] unspecified
94+
95+
extension type E14(static int x) {}
96+
// ^^^^^^
97+
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
98+
// [cfe] unspecified
99+
100+
extension type const E15(const int x) {}
101+
// ^^^^^
102+
// [analyzer] SYNTACTIC_ERROR.REPRESENTATION_FIELD_MODIFIER
103+
// [cfe] unspecified
104+
105+
// Precisely one parameter is allowed and required.
106+
107+
extension type E16() {}
108+
// ^
109+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD
110+
// [cfe] unspecified
111+
112+
extension type E17(int x, String y) {}
113+
// ^
114+
// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS
115+
// [cfe] unspecified
116+
117+
extension type E18(int x, [String y = "2"]) {}
118+
// ^
119+
// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS
120+
// [cfe] unspecified
121+
122+
extension type E19(int x, {required String y}) {}
123+
// ^
124+
// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS
125+
// [cfe] unspecified
126+
127+
extension type E20(int x, {String y = "2"}) {}
128+
// ^
129+
// [analyzer] SYNTACTIC_ERROR.MULTIPLE_REPRESENTATION_FIELDS
130+
// [cfe] unspecified
131+
132+
extension type E21([int x = 0]) {}
133+
// ^
134+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD
135+
// [cfe] unspecified
136+
137+
extension type E22([int x = 0, int y = 0]) {}
138+
// ^
139+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD
140+
// [cfe] unspecified
141+
142+
extension type E23({required int x}) {}
143+
// ^
144+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD
145+
// [cfe] unspecified
146+
147+
extension type E24({int x = 0}) {}
148+
// ^
149+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD
150+
// [cfe] unspecified
151+
152+
extension type E25({int x = 0, int y = 0}) {}
153+
// ^
154+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_FIELD
155+
// [cfe] unspecified
156+
157+
// Annotations are allowed, but only at the start.
158+
159+
extension type E26(@anno int) {}
160+
// ^
161+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE
162+
// ^
163+
// [cfe] unspecified
164+
165+
extension type E27(int @anno x) {}
166+
// ^^^
167+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_REPRESENTATION_TYPE
168+
// ^
169+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
170+
// [cfe] unspecified
171+
172+
extension type E28(int x @anno) {}
173+
// ^
174+
// [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN
175+
// [cfe] unspecified
176+
177+
178+
// Helpers
179+
const anno = "Annotation";
180+
181+
extension type E(int x) {}
182+
183+
void main() {}

0 commit comments

Comments
 (0)