Skip to content

Commit b605171

Browse files
authored
dart-lang#1400. [Extension types] Add more superinterfaces tests (dart-lang#2315)
Add more superinterfaces tests
1 parent 52b38e0 commit b605171

7 files changed

+275
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
/// @assertion Assume that DV is an extension type declaration named Name, and
6+
/// V1 occurs as one of the <type>s in the <interfaces> of DV. In this case we
7+
/// say that V1 is a superinterface of DV.
8+
/// ...
9+
/// Assume that DV has two direct or indirect superinterfaces of the form
10+
/// W<T1, .. Tk> respectively W<S1, .. Sk>. A compile-time error occurs if Tj is
11+
/// not equal to Sj for any j in 1 .. k. The notion of equality used here is the
12+
/// same as with the corresponding rule about superinterfaces of classes.
13+
///
14+
/// @description Checks that it is a compile-time error if an extension type has
15+
/// two superinterfaces of the form `W<T1, .. Tk>`, `W<S1, .. Sk>` and there is
16+
/// a `j` such that `Tj` is not equal to `Sj`.
17+
/// @author [email protected]
18+
19+
// SharedOptions=--enable-experiment=inline-class
20+
21+
class A<T> {}
22+
23+
extension type IntET(int _) implements int {}
24+
25+
extension type ET<T extends num>(T _) implements num {}
26+
27+
extension type ET1(A<int> _) implements A<num>, A<int> {}
28+
// ^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
32+
extension type ET2<T extends num>(A<T> _) implements A<num>, A<T> {}
33+
// ^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
37+
extension type ET3<T extends num>(T _) implements ET<T>, ET<num> {}
38+
// ^^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
42+
extension type ET4(int _) implements IntET, num {}
43+
// ^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
47+
main() {
48+
print(ET1);
49+
print(ET2);
50+
print(ET3);
51+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
/// @assertion Assume that DV is an extension type declaration named Name, and
6+
/// V1 occurs as one of the <type>s in the <interfaces> of DV. In this case we
7+
/// say that V1 is a superinterface of DV.
8+
/// ...
9+
/// Assume that DV has two direct or indirect superinterfaces of the form
10+
/// W<T1, .. Tk> respectively W<S1, .. Sk>. A compile-time error occurs if Tj is
11+
/// not equal to Sj for any j in 1 .. k. The notion of equality used here is the
12+
/// same as with the corresponding rule about superinterfaces of classes.
13+
///
14+
/// @description Checks that it is a compile-time error if an extension type has
15+
/// two superinterfaces of the form `W<T1, .. Tk>`, `W<S1, .. Sk>` and there is
16+
/// a `j` such that `Tj` is not equal to `Sj`.
17+
/// @author [email protected]
18+
19+
// SharedOptions=--enable-experiment=inline-class
20+
21+
class A<T> {}
22+
23+
extension type A_ET1<T>(A<T> _) implements A<T> {}
24+
25+
extension type A_ET2<T>(A<T> _) implements A<T> {}
26+
27+
extension type ET(A<int> _) implements A_ET1<int>, A_ET2<num> {}
28+
// ^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
main() {
32+
print(ET);
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
/// @assertion Assume that DV is an extension type declaration named Name, and
6+
/// V1 occurs as one of the <type>s in the <interfaces> of DV. In this case we
7+
/// say that V1 is a superinterface of DV.
8+
/// ...
9+
/// Assume that DV has two direct or indirect superinterfaces of the form
10+
/// W<T1, .. Tk> respectively W<S1, .. Sk>. A compile-time error occurs if Tj is
11+
/// not equal to Sj for any j in 1 .. k. The notion of equality used here is the
12+
/// same as with the corresponding rule about superinterfaces of classes.
13+
///
14+
/// @description Checks that it is a compile-time error if an extension type has
15+
/// two superinterfaces of the form `W<T1, .. Tk>`, `W<S1, .. Sk>` and there is
16+
/// a `j` such that `Tj` is not equal to `Sj`.
17+
/// @author [email protected]
18+
19+
// SharedOptions=--enable-experiment=inline-class
20+
21+
extension type A<T>(T _) {}
22+
23+
extension type A_ET1<T>(A<T> _) implements A<A<T>> {}
24+
25+
extension type A_ET2<T>(A<T> _) implements A<A<T>> {}
26+
27+
extension type ET(A<int> _) implements A_ET1<int>, A_ET2<num> {}
28+
// ^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
main() {
32+
print(ET);
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
/// @assertion Assume that DV is an extension type declaration named Name, and
6+
/// V1 occurs as one of the <type>s in the <interfaces> of DV. In this case we
7+
/// say that V1 is a superinterface of DV.
8+
/// ...
9+
/// Assume that DV has two direct or indirect superinterfaces of the form
10+
/// W<T1, .. Tk> respectively W<S1, .. Sk>. A compile-time error occurs if Tj is
11+
/// not equal to Sj for any j in 1 .. k. The notion of equality used here is the
12+
/// same as with the corresponding rule about superinterfaces of classes.
13+
///
14+
/// @description Checks that it is a compile-time error if an extension type has
15+
/// two superinterfaces of the form `W<T1, .. Tk>`, `W<S1, .. Sk>` and there is
16+
/// a `j` such that `Tj` is not equal to `Sj`.
17+
/// @author [email protected]
18+
19+
// SharedOptions=--enable-experiment=inline-class
20+
21+
class A<T> {}
22+
23+
extension type ET1(A<Never> _) implements A<int> {}
24+
25+
extension type ET2(A<Never> _) implements ET1, A<String> {}
26+
// ^^^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
main() {
30+
print(ET2);
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
/// @assertion Assume that DV is an extension type declaration named Name, and
6+
/// V1 occurs as one of the <type>s in the <interfaces> of DV. In this case we
7+
/// say that V1 is a superinterface of DV.
8+
/// ...
9+
/// Assume that DV has two direct or indirect superinterfaces of the form
10+
/// W<T1, .. Tk> respectively W<S1, .. Sk>. A compile-time error occurs if Tj is
11+
/// not equal to Sj for any j in 1 .. k. The notion of equality used here is the
12+
/// same as with the corresponding rule about superinterfaces of classes.
13+
///
14+
/// @description Checks that it is a compile-time error if an extension type has
15+
/// two superinterfaces of the form `W<T1, .. Tk>`, `W<S1, .. Sk>` and there is
16+
/// a `j` such that `Tj` is not equal to `Sj`.
17+
/// @author [email protected]
18+
19+
// SharedOptions=--enable-experiment=inline-class
20+
21+
extension type A<T>(T _) {}
22+
23+
extension type ET1(A<Never> _) implements A<A<int>> {}
24+
25+
extension type ET2(A<Never> _) implements ET1, A<A<String>> {}
26+
// ^^^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
main() {
30+
print(ET2);
31+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
/// @assertion It is a compile-time error if two elements in the type list of
6+
/// the `implements` clause of an extension type declaration specifies the same
7+
/// type.
8+
///
9+
/// @description Checks that it is a compile-time error if two elements in the
10+
/// type list of the `implements` clause of an extension type declaration
11+
/// specifies the same type.
12+
/// @author [email protected]
13+
/// @issue 53790, 53791
14+
15+
// SharedOptions=--enable-experiment=inline-class
16+
17+
class A {}
18+
19+
class B<T> {}
20+
21+
extension type IntET(int _) implements int {}
22+
23+
extension type ET<T extends num>(T _) implements num {}
24+
25+
extension type ET1(A _) implements A, A {}
26+
// ^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
30+
extension type ET2(B<int> _) implements B<int>, B<int> {}
31+
// ^
32+
// [analyzer] unspecified
33+
// [cfe] unspecified
34+
35+
extension type ET3(IntET _) implements IntET, int, IntET {}
36+
// ^^^^^
37+
// [analyzer] unspecified
38+
// [cfe] unspecified
39+
40+
extension type ET4<T extends num>(B<T> _) implements B<T>, B<T> {}
41+
// ^
42+
// [analyzer] unspecified
43+
// [cfe] unspecified
44+
45+
extension type ET5<T extends num>(T _) implements ET<T>, ET<T> {}
46+
// ^^
47+
// [analyzer] unspecified
48+
// [cfe] unspecified
49+
50+
main() {
51+
print(ET1);
52+
print(ET2);
53+
print(ET3);
54+
print(ET4);
55+
print(ET5);
56+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
/// @assertion It is a compile-time error if two elements in the type list of
6+
/// the `implements` clause of an extension type declaration specifies the same
7+
/// type.
8+
///
9+
/// @description Checks that it is not an error if two elements in the type list
10+
/// of the `implements` clause of an extension type declaration specifies
11+
/// different types.
12+
/// @author [email protected]
13+
14+
// SharedOptions=--enable-experiment=inline-class
15+
16+
class A<T> {}
17+
18+
extension type AET(A<int> _) implements A<int> {}
19+
20+
extension type IntET(int _) implements int {}
21+
22+
extension type ET<T extends num>(T _) implements num {}
23+
24+
extension type ET1(int _) implements num, int {}
25+
26+
extension type ET2(IntET _) implements IntET, int {}
27+
28+
extension type ET3(IntET _) implements IntET, ET<int> {}
29+
30+
extension type ET4(A<int> _) implements A<int>, AET {}
31+
32+
extension type ET5(int _) implements ET<num>, num {}
33+
34+
main() {
35+
print(ET1);
36+
print(ET2);
37+
print(ET3);
38+
print(ET4);
39+
print(ET5);
40+
}

0 commit comments

Comments
 (0)