Skip to content

Commit 90aca0b

Browse files
committed
Add test for incomparable on type resolution and fix expectations.
Change-Id: I8c1ead430a866461d802e86a36c892899645faf4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115620 Reviewed-by: Lasse R.H. Nielsen <[email protected]>
1 parent f4229da commit 90aca0b

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

tests/language_2/extension_methods/static_extension_resolution_failures_test.dart

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,58 @@ main() {
2222
Expect.equals("EA.v2", a.v2);
2323
Expect.equals("EB1.v2", b1.v2);
2424
Expect.equals("EB2.v2", b2.v2);
25-
c // Cannot determine which of EB1 and EB2's v2 is more specific
26-
.v2 //# 01: compile-time error
27-
;
25+
// Cannot determine which of EB1 and EB2's v2 is more specific
26+
c.v2;
27+
//^^
28+
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
29+
// [cfe] The getter 'v2' isn't defined for the class 'C'.
2830

2931
Expect.equals("EA.v3", a.v3);
3032
Expect.equals("EA.v3", b1.v3);
3133
Expect.equals("EA.v3", b2.v3);
3234
Expect.equals("EA.v3", c.v3);
3335

34-
3536
Iterable<num> i_num = <int>[];
3637
Iterable<int> ii = <int>[];
3738
List<num> ln = <int>[];
3839
List<int> li = <int>[];
3940

40-
i_num // No `i_num` extension declared.
41-
.i_num //# 02: compile-time error
42-
;
41+
// No `i_num` extension declared.
42+
i_num.i_num;
43+
// ^^^^^
44+
// [analyzer] STATIC_TYPE_WARNING.UNDEFINED_GETTER
45+
// [cfe] The getter 'i_num' isn't defined for the class 'Iterable<num>'.
4346

4447
Expect.equals("Iterable<int>.i_num", ii.i_num);
4548
Expect.equals("List<num>.i_num", ln.i_num);
4649

47-
li // Both apply, neither is more specific.
48-
.i_num //# 03: compile-time error
49-
;
50-
51-
c // no most specific because both are equally specific.
52-
.cs //# 04: compile-time error
53-
;
50+
// Both apply, neither is more specific.
51+
li.i_num;
52+
// ^^^^^
53+
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
54+
// [cfe] The getter 'i_num' isn't defined for the class 'List<int>'.
55+
56+
// no most specific because both are equally specific.
57+
c.cs;
58+
//^^
59+
// [analyzer] COMPILE_TIME_ERROR.AMBIGUOUS_EXTENSION_MEMBER_ACCESS
60+
// [cfe] The getter 'cs' isn't defined for the class 'C'.
61+
62+
// Both EIT.e1 and ELO.e1 apply, but their instantiated on
63+
// types are incomparable, and hence this is an error.
64+
ln.e1();
65+
// ^
66+
// [analyzer] unspecified
67+
// [cfe] The method 'e1' isn't defined for the class 'List<num>'.
5468
}
5569

5670
// Diamond class hierarchy.
5771
class A {}
72+
5873
class B1 implements A {}
74+
5975
class B2 implements A {}
76+
6077
class C implements B1, B2 {}
6178

6279
extension EA on A {
@@ -97,3 +114,11 @@ extension C1 on C {
97114
extension C2 on C {
98115
String get cs => "C2.cs";
99116
}
117+
118+
extension EIT<T> on Iterable<T> {
119+
String e1() => "Iterable<T>.e1";
120+
}
121+
122+
extension ELO on List<Object> {
123+
String e1() => "List<Object>.e1";
124+
}

tests/language_2/extension_methods/static_extension_resolution_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,16 @@ main() {
210210

211211
// Applicable methods.
212212
Expect.equals("SubTarget<T>.e1", s1.e1());
213-
Expect.equals("SubTarget<Object>.e2", s1.e2());
214-
Expect.equals("Target<T>.e3", s1.e3());
215-
Expect.equals("Target<Object>.e4", s1.e4());
213+
Expect.equals("T.e2", s1.e2());
214+
Expect.equals("T.e3", s1.e3());
215+
Expect.equals("T.e4", s1.e4());
216216
Expect.equals("T.e5", s1.e5());
217217
Expect.equals("Object.e6", s1.e6());
218218

219219
Expect.equals("Target<T>.e1", t1.e1());
220220
Expect.equals("Target<T>.e2", t1.e2());
221221
Expect.equals("Target<T>.e3", t1.e3());
222-
Expect.equals("Target<Object>.e4", t1.e4());
222+
Expect.equals("T.e4", t1.e4());
223223
Expect.equals("T.e5", t1.e5());
224224
Expect.equals("Object.e6", t1.e6());
225225

0 commit comments

Comments
 (0)