Skip to content

Commit 28e9069

Browse files
authored
#2087. Add tests for parameters covariant-by-declaration (#2121)
Add tests for parameters covariant-by-declaration
1 parent 0cec314 commit 28e9069

27 files changed

+1409
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 For each parameter p of m where covariant is present, it is a
6+
/// compile-time error if there exists a direct or indirect superinterface of C
7+
/// which has an accessible method signature m′′ with the same name as m, such
8+
/// that m′′ has a parameter p′′ that corresponds to p, unless the type of p is
9+
/// a subtype or a supertype of the type of p′′
10+
///
11+
/// @description Checks that it is a compile-time error if there is a member
12+
/// with a covariant parameter `p` and there is another member with the same
13+
/// name but with the parameter which is not a subtype or supertype of `p`
14+
/// @author [email protected]
15+
16+
class A {
17+
void m1(num a) {}
18+
void m2([num a = 0]) {}
19+
void m3({num a = 0}) {}
20+
void m4({required num a}) {}
21+
22+
void set s(num n) {}
23+
24+
void operator +(num n) {}
25+
}
26+
27+
class C extends A {
28+
void m1(covariant String a) {}
29+
// ^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
33+
void m2([covariant String a = ""]) {}
34+
// ^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
38+
void m3({covariant String a = ""}) {}
39+
// ^^
40+
// [analyzer] unspecified
41+
// [cfe] unspecified
42+
43+
void m4({required covariant String a}) {}
44+
// ^^
45+
// [analyzer] unspecified
46+
// [cfe] unspecified
47+
48+
void set s(covariant String s) {}
49+
// ^
50+
// [analyzer] unspecified
51+
// [cfe] unspecified
52+
53+
void operator +(covariant String n) {}
54+
// ^
55+
// [analyzer] unspecified
56+
// [cfe] unspecified
57+
}
58+
59+
main() {
60+
print(C);
61+
}
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 For each parameter p of m where covariant is present, it is a
6+
/// compile-time error if there exists a direct or indirect superinterface of C
7+
/// which has an accessible method signature m′′ with the same name as m, such
8+
/// that m′′ has a parameter p′′ that corresponds to p, unless the type of p is
9+
/// a subtype or a supertype of the type of p′′
10+
///
11+
/// @description Checks that it is not an error if there is a member
12+
/// with a covariant parameter `p` and there is another member with the same
13+
/// name but with the parameter which is a subtype of `p`
14+
/// @author [email protected]
15+
16+
class A {
17+
void m1(num a) {}
18+
void m2([num a = 0]) {}
19+
void m3({num a = 0}) {}
20+
void m4({required num a}) {}
21+
22+
void set s(num n) {}
23+
void operator +(num n) {}
24+
}
25+
26+
class C extends A {
27+
void m1(covariant Object a) {}
28+
void m2([covariant Object a = ""]) {}
29+
void m3({covariant Object a = ""}) {}
30+
void m4({required covariant Object a}) {}
31+
32+
void set s(covariant Object s) {}
33+
void operator +(covariant Object n) {}
34+
}
35+
36+
main() {
37+
print(C);
38+
}
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 For each parameter p of m where covariant is present, it is a
6+
/// compile-time error if there exists a direct or indirect superinterface of C
7+
/// which has an accessible method signature m′′ with the same name as m, such
8+
/// that m′′ has a parameter p′′ that corresponds to p, unless the type of p is
9+
/// a subtype or a supertype of the type of p′′
10+
///
11+
/// @description Checks that it is not an error if there is a member with a
12+
/// covariant parameter `p` and there is another member with the same name but
13+
/// with the parameter which is a supertype of `p`
14+
/// @author [email protected]
15+
16+
class A {
17+
void m1(num a) {}
18+
void m2([num a = 0]) {}
19+
void m3({num a = 0}) {}
20+
void m4({required num a}) {}
21+
22+
void set s(num n) {}
23+
void operator +(num n) {}
24+
}
25+
26+
class C extends A {
27+
void m1(covariant int a) {}
28+
void m2([covariant int a = 1]) {}
29+
void m3({covariant int a = 1}) {}
30+
void m4({required covariant int a}) {}
31+
32+
void set s(covariant int s) {}
33+
void operator +(covariant int n) {}
34+
}
35+
36+
main() {
37+
print(C);
38+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 For each parameter p of m where covariant is present, it is a
6+
/// compile-time error if there exists a direct or indirect superinterface of C
7+
/// which has an accessible method signature m′′ with the same name as m, such
8+
/// that m′′ has a parameter p′′ that corresponds to p, unless the type of p is
9+
/// a subtype or a supertype of the type of p′′
10+
///
11+
/// @description Checks that it is a compile-time error if there is a member
12+
/// with a covariant parameter `p` and there is another member with the same
13+
/// name but with the parameter which is not a subtype or supertype of `p`
14+
/// @author [email protected]
15+
16+
class A {
17+
void m1(covariant num a) {}
18+
void m2([covariant num a = 0]) {}
19+
void m3({covariant a = 0}) {}
20+
void m4({required covariant num a}) {}
21+
22+
void set s(covariant num n) {}
23+
void operator +(covariant num n) {}
24+
}
25+
26+
class C extends A {
27+
void m1(String a) {}
28+
// ^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
32+
void m2([String a = ""]) {}
33+
// ^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
37+
void m3({String a = ""}) {}
38+
// ^^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
42+
void m4({required String a}) {}
43+
// ^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
47+
void set s(String s) {}
48+
// ^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
52+
void operator +(String n) {}
53+
// ^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
}
57+
58+
main() {
59+
print(C);
60+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 For each parameter p of m where covariant is present, it is a
6+
/// compile-time error if there exists a direct or indirect superinterface of C
7+
/// which has an accessible method signature m′′ with the same name as m, such
8+
/// that m′′ has a parameter p′′ that corresponds to p, unless the type of p is
9+
/// a subtype or a supertype of the type of p′′
10+
///
11+
/// @description Checks that it is a compile-time error if there is a member
12+
/// with a covariant parameter `p` and there is another member with the same
13+
/// name but with the parameter which is not a subtype or supertype of `p`
14+
/// @author [email protected]
15+
16+
class A {
17+
void m1(num a) {}
18+
void m2([num a = 0]) {}
19+
void m3({a = 0}) {}
20+
void m4({required num a}) {}
21+
22+
void set s(num n) {}
23+
void operator +(num n) {}
24+
}
25+
26+
abstract class B {
27+
void m1(covariant String a);
28+
void m2([covariant String a = ""]);
29+
void m3({covariant String a = ""});
30+
void m4({required covariant String a});
31+
32+
void set s(covariant String s);
33+
void operator +(covariant String n);
34+
}
35+
36+
class C extends A implements B {
37+
void m1(int a) {}
38+
// ^^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
42+
void m2([int a = 1]) {}
43+
// ^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
47+
void m3({int a = 1}) {}
48+
// ^^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
52+
void m4({required int a}) {}
53+
// ^^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
57+
void set s(int s) {}
58+
// ^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
void operator +(int n) {}
63+
// ^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
}
67+
68+
main() {
69+
print(C);
70+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 For each parameter p of m where covariant is present, it is a
6+
/// compile-time error if there exists a direct or indirect superinterface of C
7+
/// which has an accessible method signature m′′ with the same name as m, such
8+
/// that m′′ has a parameter p′′ that corresponds to p, unless the type of p is
9+
/// a subtype or a supertype of the type of p′′
10+
///
11+
/// @description Checks that it is a compile-time error if there is a member
12+
/// with a covariant parameter `p` and there is another member with the same
13+
/// name but with the parameter which is not a subtype or supertype of `p`
14+
/// @author [email protected]
15+
16+
class A {
17+
void m1(num a) {}
18+
void m2([num a = 0]) {}
19+
void m3({a = 0}) {}
20+
void m4({required num a}) {}
21+
22+
void set s(num n) {}
23+
void operator +(num n) {}
24+
}
25+
26+
abstract mixin class B {
27+
void m1(covariant String a);
28+
void m2([covariant String a = ""]);
29+
void m3({covariant String a = ""});
30+
void m4({required covariant String a});
31+
32+
void set s(covariant String s);
33+
void operator +(covariant String n);
34+
}
35+
36+
class C extends A with B {
37+
void m1(int a) {}
38+
// ^^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
42+
void m2([int a = 1]) {}
43+
// ^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
47+
void m3({int a = 1}) {}
48+
// ^^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
52+
void m4({required int a}) {}
53+
// ^^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
57+
void set s(int s) {}
58+
// ^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
void operator +(int n) {}
63+
// ^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
}
67+
68+
main() {
69+
print(C);
70+
}
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 For each parameter p of m where covariant is present, it is a
6+
/// compile-time error if there exists a direct or indirect superinterface of C
7+
/// which has an accessible method signature m′′ with the same name as m, such
8+
/// that m′′ has a parameter p′′ that corresponds to p, unless the type of p is
9+
/// a subtype or a supertype of the type of p′′
10+
///
11+
/// @description Checks that it is not an error if there is a member
12+
/// with a covariant parameter `p` and there is another member with the same
13+
/// name but with the parameter which is a subtype of `p`
14+
/// @author [email protected]
15+
16+
class A {
17+
void m1(covariant Object a) {}
18+
void m2([covariant Object a = ""]) {}
19+
void m3({covariant Object a = ""}) {}
20+
void m4({required covariant Object a}) {}
21+
22+
void set s(covariant Object s) {}
23+
void operator +(covariant Object n) {}
24+
}
25+
26+
class C extends A {
27+
void m1(num a) {}
28+
void m2([num a = 0]) {}
29+
void m3({num a = 0}) {}
30+
void m4({required num a}) {}
31+
32+
void set s(num n) {}
33+
void operator +(num n) {}
34+
}
35+
36+
main() {
37+
print(C);
38+
}

0 commit comments

Comments
 (0)