Skip to content

Commit 094ea3a

Browse files
authored
#2112. Add missing tests for mixins. Part 2 (#2118)
1 parent 3ee213d commit 094ea3a

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 Let S be a class, M be a mixin with required superinterfaces
6+
/// T1, . . . , Tn, combined superinterface MS, implemented interfaces
7+
/// I1, . . . , Ik and members as mixin member declarations, and let N be a name
8+
/// ...
9+
/// It is a compile-time error if any of members contains a super-invocation of
10+
/// a member m (for example super.foo, super + 2, or super[1] = 2), and S does
11+
/// not have a concrete implementation of m which is a valid override of the
12+
/// member m in the interface MS
13+
///
14+
/// @description Checks that it is a compile-time error if any of members
15+
/// contains a super-invocation of a member `m`, and `S` does not have a
16+
/// concrete implementation of `m`
17+
/// @author [email protected]
18+
19+
abstract class S {
20+
bool get m;
21+
S operator +(int other);
22+
S operator [](int index);
23+
}
24+
25+
mixin M1 on S {
26+
void foo() {
27+
super.m;
28+
}
29+
}
30+
31+
mixin M2 on S {
32+
void foo() {
33+
super + 2;
34+
}
35+
}
36+
37+
mixin M3 on S {
38+
void foo() {
39+
super[0];
40+
}
41+
}
42+
43+
abstract class C1 = S with M1;
44+
// ^^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
48+
abstract class C2 = S with M2;
49+
// ^^
50+
// [analyzer] unspecified
51+
// [cfe] unspecified
52+
53+
abstract class C3 = S with M3;
54+
// ^^
55+
// [analyzer] unspecified
56+
// [cfe] unspecified
57+
58+
main() {
59+
print(C1);
60+
print(C2);
61+
print(C3);
62+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 Let S be a class, M be a mixin with required superinterfaces
6+
/// T1, . . . , Tn, combined superinterface MS, implemented interfaces
7+
/// I1, . . . , Ik and members as mixin member declarations, and let N be a name
8+
/// ...
9+
/// It is a compile-time error if any of members contains a super-invocation of
10+
/// a member m (for example super.foo, super + 2, or super[1] = 2), and S does
11+
/// not have a concrete implementation of m which is a valid override of the
12+
/// member m in the interface MS
13+
///
14+
/// @description Checks that it is not an error if `S` does not have a concrete
15+
/// implementation of a member `m` but there are no super-invocation of `m`
16+
/// @author [email protected]
17+
18+
abstract class S {
19+
bool get m;
20+
S operator +(int other);
21+
S operator [](int index);
22+
}
23+
24+
mixin M1 on S {
25+
void foo() {}
26+
}
27+
28+
mixin M2 on S {
29+
void foo() {}
30+
}
31+
32+
mixin M3 on S {
33+
void foo() {}
34+
}
35+
36+
abstract class C1 = S with M1;
37+
38+
abstract class C2 = S with M2;
39+
40+
abstract class C3 = S with M3;
41+
42+
main() {
43+
print(C1);
44+
print(C2);
45+
print(C3);
46+
}
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 Let S be a class, M be a mixin with required superinterfaces
6+
/// T1, . . . , Tn, combined superinterface MS, implemented interfaces
7+
/// I1, . . . , Ik and members as mixin member declarations, and let N be a name
8+
/// ...
9+
/// It is a compile-time error if any of members contains a super-invocation of
10+
/// a member m (for example super.foo, super + 2, or super[1] = 2), and S does
11+
/// not have a concrete implementation of m which is a valid override of the
12+
/// member m in the interface MS
13+
///
14+
/// @description Checks that it is not an error if any of members contains a
15+
/// super-invocation of a member `m`, and `S` does have a concrete
16+
/// implementation of `m` which is a valid override of the member `m` in the
17+
/// interface `MS`
18+
/// @author [email protected]
19+
20+
class A {
21+
Object m(num o) => o;
22+
}
23+
24+
class S extends A {
25+
num m(Object n) => 42;
26+
}
27+
28+
mixin M on A {
29+
void foo() {
30+
super.m(3.14);
31+
}
32+
}
33+
34+
abstract class C1 = S with M;
35+
36+
abstract class C2 = A with M;
37+
38+
main() {
39+
print(C1);
40+
print(C2);
41+
}

0 commit comments

Comments
 (0)