Skip to content

Commit 8ce8fba

Browse files
authored
Fixes #2386. Add more super-bounded types tests (#2949)
Add more super-bounded types tests
1 parent 449cd8f commit 8ce8fba

File tree

9 files changed

+239
-63
lines changed

9 files changed

+239
-63
lines changed

Language/Generics/Superbounded_types/class_A04_t01.dart

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,39 @@ class B1 extends A {}
2020
// ^
2121
// [analyzer] unspecified
2222
// [cfe] unspecified
23-
class B2<X extends A<X>> extends A<X> {}
2423

25-
class B3 extends A<dynamic> {}
24+
class B2 extends A<dynamic> {}
2625
// ^^^^^^^
2726
// [analyzer] unspecified
2827
// [cfe] unspecified
29-
class B4 extends A<Object?> {}
28+
class B3 extends A<Object?> {}
3029
// ^^^^^^^
3130
// [analyzer] unspecified
3231
// [cfe] unspecified
33-
class B5 extends A<void> {}
34-
// ^^^^
35-
// [analyzer] unspecified
36-
// [cfe] unspecified
37-
class B6 extends A<Null> {}
32+
class B4 extends A<void> {}
3833
// ^^^^
3934
// [analyzer] unspecified
4035
// [cfe] unspecified
4136

42-
class B7 extends A<A<dynamic>> {}
37+
class B5 extends A<A<dynamic>> {}
4338
// ^^^^^^^^^^
4439
// [analyzer] unspecified
4540
// [cfe] unspecified
46-
class B8 extends A<A<Object?>> {}
41+
class B6 extends A<A<Object?>> {}
4742
// ^^^^^^^^^^
4843
// [analyzer] unspecified
4944
// [cfe] unspecified
50-
class B9 extends A<A<void>> {}
45+
class B7 extends A<A<void>> {}
5146
// ^^^^^^^
5247
// [analyzer] unspecified
5348
// [cfe] unspecified
54-
class B10 extends A<A<Null>> {}
55-
// ^^^^^^^
56-
// [analyzer] unspecified
57-
// [cfe] unspecified
58-
59-
class B11 extends A<Never> {}
60-
class B12 extends A<A<Never>> {}
6149

62-
main() {}
50+
main() {
51+
print(B1);
52+
print(B2);
53+
print(B3);
54+
print(B4);
55+
print(B5);
56+
print(B6);
57+
print(B7);
58+
}

Language/Generics/Superbounded_types/class_A04_t02.dart

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,39 @@ class B1 implements A {}
2020
// ^
2121
// [analyzer] unspecified
2222
// [cfe] unspecified
23-
class B2<X extends A<X>> implements A<X> {}
2423

25-
class B3 implements A<dynamic> {}
24+
class B2 implements A<dynamic> {}
2625
// ^^^^^^^
2726
// [analyzer] unspecified
2827
// [cfe] unspecified
29-
class B4 implements A<Object?> {}
28+
class B3 implements A<Object?> {}
3029
// ^^^^^^^
3130
// [analyzer] unspecified
3231
// [cfe] unspecified
33-
class B5 implements A<void> {}
34-
// ^^^^
35-
// [analyzer] unspecified
36-
// [cfe] unspecified
37-
class B6 implements A<Null> {}
32+
class B4 implements A<void> {}
3833
// ^^^^
3934
// [analyzer] unspecified
4035
// [cfe] unspecified
4136

42-
class B7 implements A<A<dynamic>> {}
37+
class B5 implements A<A<dynamic>> {}
4338
// ^^^^^^^^^^
4439
// [analyzer] unspecified
4540
// [cfe] unspecified
46-
class B8 implements A<A<Object?>> {}
41+
class B6 implements A<A<Object?>> {}
4742
// ^^^^^^^^^^
4843
// [analyzer] unspecified
4944
// [cfe] unspecified
50-
class B9 implements A<A<void>> {}
45+
class B7 implements A<A<void>> {}
5146
// ^^^^^^^
5247
// [analyzer] unspecified
5348
// [cfe] unspecified
54-
class B10 implements A<A<Null>> {}
55-
// ^^^^^^^
56-
// [analyzer] unspecified
57-
// [cfe] unspecified
58-
59-
class B11 implements A<Never> {}
60-
61-
class B12 implements A<A<Never>> {}
6249

63-
main() {}
50+
main() {
51+
print(B1);
52+
print(B2);
53+
print(B3);
54+
print(B4);
55+
print(B5);
56+
print(B6);
57+
print(B7);
58+
}

Language/Generics/Superbounded_types/class_A04_t03.dart

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,39 @@ class B1 extends C with A {}
2121
// ^
2222
// [analyzer] unspecified
2323
// [cfe] unspecified
24-
class B2<X extends A<X>> extends C with A<X> {}
2524

26-
class B3 extends C with A<dynamic> {}
25+
class B2 extends C with A<dynamic> {}
2726
// ^^^^^^^
2827
// [analyzer] unspecified
2928
// [cfe] unspecified
30-
class B4 extends C with A<Object?> {}
29+
class B3 extends C with A<Object?> {}
3130
// ^^^^^^^
3231
// [analyzer] unspecified
3332
// [cfe] unspecified
34-
class B5 extends C with A<void> {}
35-
// ^^^^
36-
// [analyzer] unspecified
37-
// [cfe] unspecified
38-
class B6 extends C with A<Null> {}
33+
class B4 extends C with A<void> {}
3934
// ^^^^
4035
// [analyzer] unspecified
4136
// [cfe] unspecified
4237

43-
class B7 extends C with A<A<dynamic>> {}
38+
class B5 extends C with A<A<dynamic>> {}
4439
// ^^^^^^^^^^
4540
// [analyzer] unspecified
4641
// [cfe] unspecified
47-
class B8 extends C with A<A<Object?>> {}
42+
class B6 extends C with A<A<Object?>> {}
4843
// ^^^^^^^^^^
4944
// [analyzer] unspecified
5045
// [cfe] unspecified
51-
class B9 extends C with A<A<void>> {}
46+
class B7 extends C with A<A<void>> {}
5247
// ^^^^^^^
5348
// [analyzer] unspecified
5449
// [cfe] unspecified
55-
class B10 extends C with A<A<Null>> {}
56-
// ^^^^^^^
57-
// [analyzer] unspecified
58-
// [cfe] unspecified
59-
60-
class B11 extends C with A<Never> {}
61-
class B12 extends C with A<A<Never>> {}
6250

63-
main() {}
51+
main() {
52+
print(B1);
53+
print(B2);
54+
print(B3);
55+
print(B4);
56+
print(B5);
57+
print(B6);
58+
print(B7);
59+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 a parameterized type `T` is
6+
/// super-bounded when it is used in any of the following ways:
7+
/// ...
8+
/// - `T` is an immediate subterm of an `extends` clause of a class, or it
9+
/// occurs as an element in the type list of an `implements` clause, or a `with`
10+
/// clause, or it occurs as an element in the type list of an `on` clause of a
11+
/// mixin.
12+
///
13+
/// @description Checks that it is a compile-time error if a super-bounded type
14+
/// occurs as an element in a type list of an `on` clause of a mixin.
15+
/// @author [email protected]
16+
17+
class A<T extends A<T>> {}
18+
19+
mixin M1 on A {}
20+
// ^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
24+
mixin M2 on A<dynamic> {}
25+
// ^^^^^^^
26+
// [analyzer] unspecified
27+
// [cfe] unspecified
28+
mixin M3 on A<Object?> {}
29+
// ^^^^^^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
mixin M4 on A<void> {}
33+
// ^^^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
37+
mixin M5 on A<A<dynamic>> {}
38+
// ^^^^^^^^^^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
mixin M6 on A<A<Object?>> {}
42+
// ^^^^^^^^^^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
mixin M7 on A<A<void>> {}
46+
// ^^^^^^^
47+
// [analyzer] unspecified
48+
// [cfe] unspecified
49+
50+
main() {
51+
print(M1);
52+
print(M2);
53+
print(M3);
54+
print(M4);
55+
print(M5);
56+
print(M6);
57+
print(M7);
58+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 a parameterized type `T` is
6+
/// super-bounded when it is used in any of the following ways:
7+
/// ...
8+
/// - `T` is an immediate subterm of an `extends` clause of a class, or it
9+
/// occurs as an element in the type list of an `implements` clause, or a `with`
10+
/// clause, or it occurs as an element in the type list of an `on` clause of a
11+
/// mixin.
12+
///
13+
/// @description Checks that it is a compile-time error if a super-bounded class
14+
/// occurs as an element in the type list of an `implements` clause of an
15+
/// extension type.
16+
/// @author [email protected]
17+
18+
class A<T extends A<T>> {}
19+
20+
extension type ET1(A _) implements A {}
21+
// ^
22+
// [analyzer] unspecified
23+
// [cfe] unspecified
24+
25+
extension type ET2(A<dynamic> _) implements A<dynamic> {}
26+
// ^^^^^^^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
extension type ET3(A<Object?> _) implements A<Object?>{}
30+
// ^^^^^^^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
extension type ET4(A<void> _) implements A<void> {}
34+
// ^^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
38+
extension type ET5(A<A<dynamic>> _) implements A<A<dynamic>> {}
39+
// ^^^^^^^^^^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
extension type ET6(A<A<Object?>> _) implements A<A<Object?>> {}
43+
// ^^^^^^^^^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
extension type ET7(A<A<void>> _) implements A<A<void>> {}
47+
// ^^^^^^^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
51+
main() {
52+
print(ET1);
53+
print(ET2);
54+
print(ET3);
55+
print(ET4);
56+
print(ET5);
57+
print(ET6);
58+
print(ET7);
59+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 a parameterized type `T` is
6+
/// super-bounded when it is used in any of the following ways:
7+
/// ...
8+
/// - `T` is an immediate subterm of an `extends` clause of a class, or it
9+
/// occurs as an element in the type list of an `implements` clause, or a `with`
10+
/// clause, or it occurs as an element in the type list of an `on` clause of a
11+
/// mixin.
12+
///
13+
/// @description Checks that it is not an error to declare an extension on a
14+
/// super-bounded class.
15+
/// @author [email protected]
16+
17+
class A<T extends A<T>> {}
18+
19+
extension Ext1 on A {}
20+
21+
extension on A<dynamic> {}
22+
23+
extension on A<Object?>{}
24+
25+
extension on A<void> {}
26+
27+
extension on A<A<dynamic>> {}
28+
29+
extension on A<A<Object?>> {}
30+
31+
extension on A<A<void>> {}
32+
33+
main() {
34+
print(A);
35+
}

Language/Generics/Superbounded_types/well_bounded_A01_t02.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,13 @@ main() {
3232
A<A<Object>> a4;
3333
// ^^^^^^^^^
3434
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
A<Null> a5;
37+
// ^^^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
A<A<Null>> a6;
41+
// ^^^^^^^
42+
// [analyzer] unspecified
3543
// [cfe] unspecified
3644
}

Language/Generics/Superbounded_types/well_bounded_A01_t04.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ class A<T extends A<T>> {}
1515
class B1<X extends A<Object?>> {}
1616
class B2<X extends A<dynamic>> {}
1717
class B3<X extends A<void>> {}
18-
class B4<X extends A<Never>> {}
18+
19+
mixin M<X extends A<Object?>> on A<Never> {}
20+
extension type ET<X extends A<Object?>>(String _) implements Object {}
1921

2022
main() {
21-
B1();
22-
B2();
23-
B3();
24-
B4();
23+
print(B1);
24+
print(B2);
25+
print(B3);
26+
print(M);
27+
print(ET);
2528
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 Any use of a type `T` which is not well-bounded is a
6+
/// compile-time error.
7+
///
8+
/// @description Checks that it is a compile-time error to declare an extension
9+
/// on a malbounded type.
10+
/// @author [email protected]
11+
12+
class A<T extends A<T>> {}
13+
14+
extension on A<Null> {}
15+
// ^^^^
16+
// [analyzer] unspecified
17+
// [cfe] unspecified
18+
19+
extension on A<A<Null>> {}
20+
// ^^^^^^^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
24+
main() {
25+
print(A);
26+
}

0 commit comments

Comments
 (0)