Skip to content

Commit 3fe41c8

Browse files
authored
#1400. Composing inline classes tests (#2076)
Composing inline classes tests
1 parent 672e21d commit 3fe41c8

14 files changed

+593
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 inline class declaration named Inline, 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+
/// A compile-time error occurs if V1 is a type name or a parameterized type
10+
/// which occurs as a superinterface in an inline class declaration DV, but V1
11+
/// does not denote an inline type.
12+
///
13+
/// @description Checks that it is a compile-time error if superinterface of an
14+
/// inline class is not an inline type
15+
/// @author [email protected]
16+
17+
// SharedOptions=--enable-experiment=inline-class
18+
19+
class I1 {}
20+
class I2<T1, T2> {}
21+
22+
inline class V1 implements I1 {
23+
// ^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
final int it;
27+
V1(this.it);
28+
}
29+
30+
inline class V2<T1, T2 extends num?> implements I2<T1, T2> {
31+
// ^^^^^^^^^^
32+
// [analyzer] unspecified
33+
// [cfe] unspecified
34+
final T1 id;
35+
V2(this.id);
36+
}
37+
38+
main() {
39+
print(V1);
40+
print(V2);
41+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 inline class declaration named Inline, 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+
/// A compile-time error occurs if any direct or indirect superinterface of DV
10+
/// is the type Inline or a type of the form Inline<...>
11+
///
12+
/// @description Checks that it is a compile-time error if an inline class has a
13+
/// dependency on itself.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=inline-class
17+
18+
inline class V1 implements V2 {
19+
// ^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
final int id;
23+
V1(this.id);
24+
}
25+
26+
inline class V2 implements V3 {
27+
// ^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
final int id;
31+
V2(this.id);
32+
}
33+
34+
typedef V1Alias = V1;
35+
36+
inline class V3 implements V1Alias {
37+
// ^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
final int id;
41+
V3(this.id);
42+
}
43+
44+
main() {
45+
print(V1);
46+
print(V2);
47+
print(V3);
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 inline class declaration named Inline, 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+
/// A compile-time error occurs if any direct or indirect superinterface of DV
10+
/// is the type Inline or a type of the form Inline<...>
11+
///
12+
/// @description Checks that it is a compile-time error if an inline class has a
13+
/// dependency on itself.
14+
/// @author [email protected]
15+
16+
// SharedOptions=--enable-experiment=inline-class
17+
18+
inline class V1<T> implements V2<T> {
19+
// ^^
20+
// [analyzer] unspecified
21+
// [cfe] unspecified
22+
final T id;
23+
V1(this.id);
24+
}
25+
26+
inline class V2<T> implements V3<T> {
27+
// ^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
final T id;
31+
V2(this.id);
32+
}
33+
34+
typedef V1Alias = V1<String>;
35+
36+
inline class V3<T> implements V1Alias {
37+
// ^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
final T id;
41+
V3(this.id);
42+
}
43+
44+
main() {
45+
print(V1);
46+
print(V2);
47+
print(V3);
48+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 inline class declaration named Inline, 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 superinterface 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 inline class 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+
inline class I1<T1, T2> {}
22+
inline class I2<T1, T2> implements I1<T1, T2>{}
23+
24+
inline class V1 implements I1<int, String>, I2<int, Object> {
25+
// ^^
26+
// [analyzer] unspecified
27+
// [cfe] unspecified
28+
final int id;
29+
V1(this.id);
30+
}
31+
32+
inline class V2<T1, T2> implements I1<T1, T2>, I2<T2, T1> {
33+
// ^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
final int id;
37+
V2(this.id);
38+
}
39+
40+
main() {
41+
print(V1);
42+
print(V2);
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 inline class declaration named Inline, 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 an inline class declaration DV named Inline has representation
10+
/// type R, and that the inline type V1 with declaration DV1 is a superinterface
11+
/// of DV (note that V1 may have some actual type arguments). Assume that S is
12+
/// the instantiated representation type corresponding to V1. A compile-time
13+
/// error occurs if R is not a subtype of S.
14+
///
15+
/// @description Checks that it is a compile-time error if an inline class has
16+
/// a representation type `R` and a superinterface with a representation type
17+
/// `S` and `R` is not a subtype of `S`
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
inline class V1 {
23+
final int id;
24+
V1(this.id);
25+
}
26+
27+
inline class V implements V1 {
28+
final num id;
29+
// ^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
V(this.id);
33+
}
34+
35+
main() {
36+
print(V1);
37+
print(V);
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 inline class declaration named Inline, 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 an inline class declaration DV named Inline has representation
10+
/// type R, and that the inline type V1 with declaration DV1 is a superinterface
11+
/// of DV (note that V1 may have some actual type arguments). Assume that S is
12+
/// the instantiated representation type corresponding to V1. A compile-time
13+
/// error occurs if R is not a subtype of S.
14+
///
15+
/// @description Checks that it is a compile-time error if an inline class has
16+
/// a representation type `R` and a superinterface with a representation type
17+
/// `S` and `R` is not a subtype of `S`
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
inline class V1<T> {
23+
final T id1;
24+
V1(this.id1);
25+
}
26+
27+
inline class V implements V1<String> {
28+
// ^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
32+
final num id;
33+
V(this.id);
34+
}
35+
36+
main() {
37+
print(V1);
38+
print(V);
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 inline class declaration named Inline, 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 an inline class declaration DV named Inline has representation
10+
/// type R, and that the inline type V1 with declaration DV1 is a superinterface
11+
/// of DV (note that V1 may have some actual type arguments). Assume that S is
12+
/// the instantiated representation type corresponding to V1. A compile-time
13+
/// error occurs if R is not a subtype of S.
14+
///
15+
/// @description Checks that it is not an error if an inline class has a
16+
/// representation type `R` and a superinterface with a representation type `S`
17+
/// and `R` is a subtype of `S`
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
inline class V1<T> {
23+
final T id1;
24+
V1(this.id1);
25+
}
26+
27+
inline class V implements V1<num> {
28+
final int id;
29+
V(this.id);
30+
}
31+
32+
main() {
33+
print(V1);
34+
print(V);
35+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 inline class declaration named Inline, 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+
/// A compile-time error occurs if an inline class declaration DV has two
10+
/// superinterfaces V1 and V2, where both V1 and V2 have a member named m, and
11+
/// the two declarations of m are distinct declarations, and DV does not declare
12+
/// a member named m.
13+
///
14+
/// @description Checks that it is a compile-time error if an inline class
15+
/// declaration `DV` has two superinterfaces `V1` and `V2`, where both `V1` and
16+
/// `V2` have a member named `m`, and the two declarations of `m` are distinct
17+
/// declarations, and DV does not declare a member named `m`. Test the case when
18+
/// members in `V1` and `V2` have different signatures
19+
/// @author [email protected]
20+
21+
// SharedOptions=--enable-experiment=inline-class
22+
23+
inline class V1 {
24+
final int id;
25+
V1(this.id);
26+
27+
int m() => 42;
28+
}
29+
30+
inline class V2 {
31+
final int id;
32+
V2(this.id);
33+
34+
String m() => "42";
35+
}
36+
37+
inline class V implements V1, V2 {
38+
// ^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
final int id;
42+
V(this.id);
43+
}
44+
45+
main() {
46+
print(V);
47+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 inline class declaration named Inline, 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+
/// A compile-time error occurs if an inline class declaration DV has two
10+
/// superinterfaces V1 and V2, where both V1 and V2 have a member named m, and
11+
/// the two declarations of m are distinct declarations, and DV does not declare
12+
/// a member named m.
13+
///
14+
/// @description Checks that it is not an error if an inline class declaration
15+
/// `DV` has two superinterfaces `V1` and `V2`, where both `V1` and `V2` have a
16+
/// member named `m`, and the two declarations of `m` are distinct
17+
/// declarations, but DV does declare a member named `m`.
18+
/// @author [email protected]
19+
20+
// SharedOptions=--enable-experiment=inline-class
21+
22+
inline class V1 {
23+
final int id;
24+
V1(this.id);
25+
26+
int m() => 1;
27+
}
28+
29+
inline class V2 {
30+
final int id;
31+
V2(this.id);
32+
33+
int m() => 2;
34+
}
35+
36+
inline class V implements V1, V2 {
37+
final int id;
38+
V(this.id);
39+
40+
num get m => 3.14;
41+
}
42+
43+
main() {
44+
print(V);
45+
}

0 commit comments

Comments
 (0)