Skip to content

Commit fd0c7c2

Browse files
authored
#2080. Add correct member overrides tests. Part 1. (#2088)
Add correct member overrides tests. Part 1.
1 parent 0d7a014 commit fd0c7c2

26 files changed

+1698
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 m and m′ be member signatures with the same name id. Then m
6+
/// is a correct override of m′ iff the following criteria are all satisfied:
7+
/// • m and m′ are both methods, both getters, or both setters.
8+
///
9+
/// @description Checks that it is a compile-time error if `m` and `m′` are not
10+
/// both getters or methods. Test 'implements' clause
11+
/// @author [email protected]
12+
13+
interface class I1 {
14+
int get m => 42;
15+
}
16+
17+
interface class I2 {
18+
int m() => 42;
19+
}
20+
21+
class C1 implements I1 {
22+
int m() => 42;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
}
27+
28+
class C2 implements I2 {
29+
int get m => 42;
30+
// ^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
}
34+
35+
mixin M1 implements I1 {
36+
int m() => 0;
37+
// ^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
}
41+
42+
mixin M2 implements I2 {
43+
int get m => 0;
44+
// ^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
}
48+
49+
main() {
50+
print(C1);
51+
print(C2);
52+
print(M1);
53+
print(M2);
54+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 m and m′ be member signatures with the same name id. Then m
6+
/// is a correct override of m′ iff the following criteria are all satisfied:
7+
/// • m and m′ are both methods, both getters, or both setters.
8+
///
9+
/// @description Checks that it is a compile-time error if `m` and `m′` are not
10+
/// both getters or methods. Test `implements` clause
11+
/// @author [email protected]
12+
/// @issue 52620
13+
14+
interface class I1 {
15+
int get m => 42;
16+
}
17+
18+
interface class I2 {
19+
int m() => 42;
20+
}
21+
22+
class C1 implements I1, I2 {
23+
int m() => 42;
24+
// ^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
28+
29+
class C2 implements I1, I2 {
30+
int get m => 42;
31+
// ^
32+
// [analyzer] unspecified
33+
// [cfe] unspecified
34+
}
35+
36+
mixin M1 implements I1, I2 {
37+
int m() => 0;
38+
// ^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
}
42+
43+
mixin M2 implements I1, I2 {
44+
int get m => 2;
45+
// ^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
}
49+
50+
main() {
51+
print(C1);
52+
print(C2);
53+
print(M1);
54+
print(M2);
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 m and m′ be member signatures with the same name id. Then m
6+
/// is a correct override of m′ iff the following criteria are all satisfied:
7+
/// • m and m′ are both methods, both getters, or both setters.
8+
///
9+
/// @description Checks that it is a compile-time error if `m` and `m′` are not
10+
/// both getters or methods. Test `extends` and `on` clauses
11+
/// @author [email protected]
12+
13+
class I1 {
14+
int get m => 42;
15+
}
16+
17+
class I2 {
18+
int m() => 42;
19+
}
20+
21+
class C1 extends I1 {
22+
int m() => 42;
23+
// ^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
}
27+
28+
class C2 extends I2 {
29+
int get m => 42;
30+
// ^
31+
// [analyzer] unspecified
32+
// [cfe] unspecified
33+
}
34+
35+
mixin M1 on I1 {
36+
int m() => 0;
37+
// ^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
}
41+
42+
mixin M2 on I2 {
43+
int get m => 0;
44+
// ^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
}
48+
49+
main() {
50+
print(C1);
51+
print(C2);
52+
print(M1);
53+
print(M2);
54+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 m and m′ be member signatures with the same name id. Then m
6+
/// is a correct override of m′ iff the following criteria are all satisfied:
7+
/// • m and m′ are both methods, both getters, or both setters.
8+
///
9+
/// @description Checks that it is a compile-time error if `m` and `m′` are not
10+
/// both getters or methods.
11+
/// @author [email protected]
12+
/// @issue 52620
13+
14+
mixin class I1 {
15+
int get m => 42;
16+
}
17+
18+
interface class I2 {
19+
int m() => 42;
20+
}
21+
22+
class C1 extends I1 implements I2 {
23+
int m() => 42;
24+
// ^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
28+
29+
class C2 extends I1 implements I2 {
30+
int get m => 42;
31+
// ^
32+
// [analyzer] unspecified
33+
// [cfe] unspecified
34+
}
35+
36+
mixin M1 on I1 implements I2 {
37+
int m() => 0;
38+
// ^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
}
42+
43+
mixin M2 on I1 implements I2 {
44+
int get m => 2;
45+
// ^
46+
// [analyzer] unspecified
47+
// [cfe] unspecified
48+
}
49+
50+
main() {
51+
print(C1);
52+
print(C2);
53+
print(M1);
54+
print(M2);
55+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 m and m′ be member signatures with the same name id. Then m
6+
/// is a correct override of m′ iff the following criteria are all satisfied:
7+
/// ...
8+
/// • If m and m′ are both getters: The return type of m must be a subtype of
9+
/// the return type of m′
10+
///
11+
/// @description Checks that it is a compile-time error if `m` and `m′` are both
12+
/// getters and the return type of `m` is not a subtype of the return type of
13+
/// `m′`. Test `implements` clause
14+
/// @author [email protected]
15+
16+
interface class I {
17+
int get m => 42;
18+
}
19+
20+
class C implements I {
21+
num get m => 3.14;
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
}
26+
27+
mixin M implements I {
28+
num get m => 3.14;
29+
// ^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
}
33+
34+
main() {
35+
print(C);
36+
print(M);
37+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 m and m′ be member signatures with the same name id. Then m
6+
/// is a correct override of m′ iff the following criteria are all satisfied:
7+
/// ...
8+
/// • If m and m′ are both getters: The return type of m must be a subtype of
9+
/// the return type of m′
10+
///
11+
/// @description Checks that it is a compile-time error if `m` and `m′` are both
12+
/// getters and the return type of `m` is not a subtype of the return type of
13+
/// `m′`. Test `implements` clause
14+
/// @author [email protected]
15+
16+
interface class I1 {
17+
int get m => 1;
18+
}
19+
20+
interface class I2 {
21+
num get m => 2;
22+
}
23+
24+
class C1 implements I1, I2 {
25+
num get m => 3;
26+
// ^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
}
30+
31+
class C2 implements I1, I2 {
32+
Object get m => "C2";
33+
// ^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
}
37+
38+
mixin M1 implements I1, I2 {
39+
num get m => 4;
40+
// ^
41+
// [analyzer] unspecified
42+
// [cfe] unspecified
43+
}
44+
45+
mixin M2 implements I1, I2 {
46+
Object get m => "M2";
47+
// ^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
}
51+
52+
main() {
53+
print(C1);
54+
print(C2);
55+
print(M1);
56+
print(M2);
57+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 m and m′ be member signatures with the same name id. Then m
6+
/// is a correct override of m′ iff the following criteria are all satisfied:
7+
/// ...
8+
/// • If m and m′ are both getters: The return type of m must be a subtype of
9+
/// the return type of m′
10+
///
11+
/// @description Checks that it is a compile-time error if `m` and `m′` are both
12+
/// getters and the return type of `m` is not a subtype of the return type of
13+
/// `m′`. Test `extends` and `on` clauses
14+
/// @author [email protected]
15+
16+
mixin class I {
17+
int get m => 42;
18+
}
19+
20+
class C extends I {
21+
num get m => 3.14;
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
}
26+
27+
mixin M on I {
28+
num get m => 3.14;
29+
// ^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
}
33+
34+
main() {
35+
print(C);
36+
print(M);
37+
}

0 commit comments

Comments
 (0)