Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: pkg/analyzer/test/src/task/strong/checker_test.dart

Issue 1497253002: Align strong-mode error codes with analyzer conv. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: doc_fix Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // TODO(jmesserly): this file needs to be refactored, it's a port from 5 // TODO(jmesserly): this file needs to be refactored, it's a port from
6 // package:dev_compiler's tests 6 // package:dev_compiler's tests
7 /// General type checking tests 7 /// General type checking tests
8 library test.src.task.strong.checker_test; 8 library test.src.task.strong.checker_test;
9 9
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
11 11
12 import 'strong_test_helper.dart'; 12 import 'strong_test_helper.dart';
13 import 'package:analyzer/src/task/strong/info.dart';
13 14
14 void main() { 15 void main() {
16
15 testChecker('ternary operator', { 17 testChecker('ternary operator', {
16 '/main.dart': ''' 18 '/main.dart': '''
17 abstract class Comparable<T> { 19 abstract class Comparable<T> {
18 int compareTo(T other); 20 int compareTo(T other);
19 static int compare(Comparable a, Comparable b) => a.compareTo(b); 21 static int compare(Comparable a, Comparable b) => a.compareTo(b);
20 } 22 }
21 typedef int Comparator<T>(T a, T b); 23 typedef int Comparator<T>(T a, T b);
22 24
23 typedef bool _Predicate<T>(T value); 25 typedef bool _Predicate<T>(T value);
24 26
25 class SplayTreeMap<K, V> { 27 class SplayTreeMap<K, V> {
26 Comparator<K> _comparator; 28 Comparator<K> _comparator;
27 _Predicate _validKey; 29 _Predicate _validKey;
28 30
29 // Initializing _comparator needs a cast, since K may not always be 31 // Initializing _comparator needs a cast, since K may not always be
30 // Comparable. 32 // Comparable.
31 // Initializing _validKey shouldn't need a cast. Currently 33 // Initializing _validKey shouldn't need a cast. Currently
32 // it requires inference to work because of dartbug.com/23381 34 // it requires inference to work because of dartbug.com/23381
33 SplayTreeMap([int compare(K key1, K key2), 35 SplayTreeMap([int compare(K key1, K key2),
34 bool isValidKey(potentialKey)]) { 36 bool isValidKey(potentialKey)]) {
35 : _comparator = /*warning:DownCastComposite*/(compare == null) 37 : _comparator = /*warning:DOWN_CAST_COMPOSITE*/(compare == null)
36 ? Comparable.compare : compare, 38 ? Comparable.compare : compare,
37 _validKey = /*warning:DownCastComposite*/(isValidKey != null) 39 _validKey = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey != null)
38 ? isValidKey : ((v) => true); 40 ? isValidKey : ((v) => true);
39 _Predicate<Object> _v = /*warning:DownCastComposite*/(isValidKey != null) 41 _Predicate<Object> _v = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey != null)
40 ? isValidKey : (/*info:InferredTypeClosure*/ (v) => true); 42 ? isValidKey : (/*info:INFERRED_TYPE_CLOSURE */(v) => true);
41 // TODO(leafp): Fix unimplemented LUB in analyzer 43 // TODO(leafp): Fix unimplemented LUB in analyzer
42 _v = /*warning:DownCastComposite*/(isValidKey != null) 44 _v = /*warning:DOWN_CAST_COMPOSITE*/(isValidKey != null)
43 ? _v : (/*info:InferredTypeClosure*/(v) => true); 45 ? _v : (/*info:INFERRED_TYPE_CLOSURE*/(v) => true);
44 } 46 }
45 } 47 }
46 void main() { 48 void main() {
47 Object obj = 42; 49 Object obj = 42;
48 dynamic dyn = 42; 50 dynamic dyn = 42;
49 int i = 42; 51 int i = 42;
50 52
51 // Check the boolean conversion of the condition. 53 // Check the boolean conversion of the condition.
52 print((/*severe:StaticTypeError*/i) ? false : true); 54 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true);
53 print((/*info:DownCastImplicit*/obj) ? false : true); 55 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true);
54 print((/*info:DynamicCast*/dyn) ? false : true); 56 print((/*info:DYNAMIC_CAST*/dyn) ? false : true);
55 } 57 }
56 ''' 58 '''
57 }); 59 });
58 60
59 testChecker('if/for/do/while statements use boolean conversion', { 61 testChecker('if/for/do/while statements use boolean conversion', {
60 '/main.dart': ''' 62 '/main.dart': '''
61 main() { 63 main() {
62 dynamic d = 42; 64 dynamic d = 42;
63 Object obj = 42; 65 Object obj = 42;
64 int i = 42; 66 int i = 42;
65 bool b = false; 67 bool b = false;
66 68
67 if (b) {} 69 if (b) {}
68 if (/*info:DynamicCast*/dyn) {} 70 if (/*info:DYNAMIC_CAST*/dyn) {}
69 if (/*info:DownCastImplicit*/obj) {} 71 if (/*info:DOWN_CAST_IMPLICIT*/obj) {}
70 if (/*severe:StaticTypeError*/i) {} 72 if (/*severe:STATIC_TYPE_ERROR*/i) {}
71 73
72 while (b) {} 74 while (b) {}
73 while (/*info:DynamicCast*/dyn) {} 75 while (/*info:DYNAMIC_CAST*/dyn) {}
74 while (/*info:DownCastImplicit*/obj) {} 76 while (/*info:DOWN_CAST_IMPLICIT*/obj) {}
75 while (/*severe:StaticTypeError*/i) {} 77 while (/*severe:STATIC_TYPE_ERROR*/i) {}
76 78
77 do {} while (b); 79 do {} while (b);
78 do {} while (/*info:DynamicCast*/dyn); 80 do {} while (/*info:DYNAMIC_CAST*/dyn);
79 do {} while (/*info:DownCastImplicit*/obj); 81 do {} while (/*info:DOWN_CAST_IMPLICIT*/obj);
80 do {} while (/*severe:StaticTypeError*/i); 82 do {} while (/*severe:STATIC_TYPE_ERROR*/i);
81 83
82 for (;b;) {} 84 for (;b;) {}
83 for (;/*info:DynamicCast*/dyn;) {} 85 for (;/*info:DYNAMIC_CAST*/dyn;) {}
84 for (;/*info:DownCastImplicit*/obj;) {} 86 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {}
85 for (;/*severe:StaticTypeError*/i;) {} 87 for (;/*severe:STATIC_TYPE_ERROR*/i;) {}
86 } 88 }
87 ''' 89 '''
88 }); 90 });
89 91
90 testChecker('dynamic invocation', { 92 testChecker('dynamic invocation', {
91 '/main.dart': ''' 93 '/main.dart': '''
92 94
93 class A { 95 class A {
94 dynamic call(dynamic x) => x; 96 dynamic call(dynamic x) => x;
95 } 97 }
96 class B extends A { 98 class B extends A {
97 int call(int x) => x; 99 int call(int x) => x;
98 double col(double x) => x; 100 double col(double x) => x;
99 } 101 }
100 void main() { 102 void main() {
101 { 103 {
102 B f = new B(); 104 B f = new B();
103 int x; 105 int x;
104 double y; 106 double y;
105 // The analyzer has what I believe is a bug (dartbug.com/23252) which 107 // The analyzer has what I believe is a bug (dartbug.com/23252) which
106 // causes the return type of calls to f to be treated as dynamic. 108 // causes the return type of calls to f to be treated as dynamic.
107 x = /*info:DynamicCast should be pass*/f(3); 109 x = /*info:DYNAMIC_CAST should be pass*/f(3);
108 x = /*severe:StaticTypeError*/f.col(3.0); 110 x = /*severe:STATIC_TYPE_ERROR*/f.col(3.0);
109 y = /*info:DynamicCast should be severe:StaticTypeError*/f(3); 111 y = /*info:DYNAMIC_CAST should be severe:STATIC_TYPE_ERROR*/f(3);
110 y = f.col(3.0); 112 y = f.col(3.0);
111 f(/*severe:StaticTypeError*/3.0); 113 f(/*severe:STATIC_TYPE_ERROR*/3.0);
112 f.col(/*severe:StaticTypeError*/3); 114 f.col(/*severe:STATIC_TYPE_ERROR*/3);
113 } 115 }
114 { 116 {
115 Function f = new B(); 117 Function f = new B();
116 int x; 118 int x;
117 double y; 119 double y;
118 x = /*info:DynamicCast, info:DynamicInvoke*/f(3); 120 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
119 x = /*info:DynamicCast, info:DynamicInvoke*/f.col(3.0); 121 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0);
120 y = /*info:DynamicCast, info:DynamicInvoke*/f(3); 122 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
121 y = /*info:DynamicCast, info:DynamicInvoke*/f.col(3.0); 123 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0);
122 (/*info:DynamicInvoke*/f(3.0)); 124 (/*info:DYNAMIC_INVOKE*/f(3.0));
123 (/*info:DynamicInvoke*/f.col(3)); 125 (/*info:DYNAMIC_INVOKE*/f.col(3));
124 } 126 }
125 { 127 {
126 A f = new B(); 128 A f = new B();
127 int x; 129 int x;
128 double y; 130 double y;
129 x = /*info:DynamicCast, info:DynamicInvoke*/f(3); 131 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
130 y = /*info:DynamicCast, info:DynamicInvoke*/f(3); 132 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
131 (/*info:DynamicInvoke*/f(3.0)); 133 (/*info:DYNAMIC_INVOKE*/f(3.0));
132 } 134 }
133 { 135 {
134 dynamic g = new B(); 136 dynamic g = new B();
135 (/*info:DynamicInvoke*/g.call(32.0)); 137 (/*info:DYNAMIC_INVOKE*/g.call(32.0));
136 (/*info:DynamicInvoke*/g.col(42.0)); 138 (/*info:DYNAMIC_INVOKE*/g.col(42.0));
137 (/*info:DynamicInvoke*/g.foo(42.0)); 139 (/*info:DYNAMIC_INVOKE*/g.foo(42.0));
138 (/*info:DynamicInvoke*/g.x); 140 (/*info:DYNAMIC_INVOKE*/g.x);
139 A f = new B(); 141 A f = new B();
140 f.call(32.0); 142 f.call(32.0);
141 (/*info:DynamicInvoke*/f.col(42.0)); 143 (/*info:DYNAMIC_INVOKE*/f.col(42.0));
142 (/*info:DynamicInvoke*/f.foo(42.0)); 144 (/*info:DYNAMIC_INVOKE*/f.foo(42.0));
143 (/*info:DynamicInvoke*/f.x); 145 (/*info:DYNAMIC_INVOKE*/f.x);
144 } 146 }
145 } 147 }
146 ''' 148 '''
147 }); 149 });
148 150
149 testChecker('conversion and dynamic invoke', { 151 testChecker('conversion and dynamic invoke', {
150 '/helper.dart': ''' 152 '/helper.dart': '''
151 dynamic toString = (int x) => x + 42; 153 dynamic toString = (int x) => x + 42;
152 dynamic hashCode = "hello"; 154 dynamic hashCode = "hello";
153 ''', 155 ''',
154 '/main.dart': ''' 156 '/main.dart': '''
155 import 'helper.dart' as helper; 157 import 'helper.dart' as helper;
156 158
157 class A { 159 class A {
158 String x = "hello world"; 160 String x = "hello world";
159 161
160 void baz1(y) => x + /*info:DynamicCast*/y; 162 void baz1(y) => x + /*info:DYNAMIC_CAST*/y;
161 static baz2(y) => /*info:DynamicInvoke*/y + y; 163 static baz2(y) => /*info:DYNAMIC_INVOKE*/y + y;
162 } 164 }
163 165
164 void foo(String str) { 166 void foo(String str) {
165 print(str); 167 print(str);
166 } 168 }
167 169
168 class B { 170 class B {
169 String toString([int arg]) => arg.toString(); 171 String toString([int arg]) => arg.toString();
170 } 172 }
171 173
172 void bar(a) { 174 void bar(a) {
173 foo(/*info:DynamicCast,info:DynamicInvoke*/a.x); 175 foo(/*info:DYNAMIC_CAST,info:DYNAMIC_INVOKE*/a.x);
174 } 176 }
175 177
176 baz() => new B(); 178 baz() => new B();
177 179
178 typedef DynFun(x); 180 typedef DynFun(x);
179 typedef StrFun(String x); 181 typedef StrFun(String x);
180 182
181 var bar1 = bar; 183 var bar1 = bar;
182 184
183 void main() { 185 void main() {
184 var a = new A(); 186 var a = new A();
185 bar(a); 187 bar(a);
186 (/*info:DynamicInvoke*/bar1(a)); 188 (/*info:DYNAMIC_INVOKE*/bar1(a));
187 var b = bar; 189 var b = bar;
188 (/*info:DynamicInvoke*/b(a)); 190 (/*info:DYNAMIC_INVOKE*/b(a));
189 var f1 = foo; 191 var f1 = foo;
190 f1("hello"); 192 f1("hello");
191 dynamic f2 = foo; 193 dynamic f2 = foo;
192 (/*info:DynamicInvoke*/f2("hello")); 194 (/*info:DYNAMIC_INVOKE*/f2("hello"));
193 DynFun f3 = foo; 195 DynFun f3 = foo;
194 (/*info:DynamicInvoke*/f3("hello")); 196 (/*info:DYNAMIC_INVOKE*/f3("hello"));
195 (/*info:DynamicInvoke*/f3(42)); 197 (/*info:DYNAMIC_INVOKE*/f3(42));
196 StrFun f4 = foo; 198 StrFun f4 = foo;
197 f4("hello"); 199 f4("hello");
198 a.baz1("hello"); 200 a.baz1("hello");
199 var b1 = a.baz1; 201 var b1 = a.baz1;
200 (/*info:DynamicInvoke*/b1("hello")); 202 (/*info:DYNAMIC_INVOKE*/b1("hello"));
201 A.baz2("hello"); 203 A.baz2("hello");
202 var b2 = A.baz2; 204 var b2 = A.baz2;
203 (/*info:DynamicInvoke*/b2("hello")); 205 (/*info:DYNAMIC_INVOKE*/b2("hello"));
204 206
205 dynamic a1 = new B(); 207 dynamic a1 = new B();
206 (/*info:DynamicInvoke*/a1.x); 208 (/*info:DYNAMIC_INVOKE*/a1.x);
207 a1.toString(); 209 a1.toString();
208 (/*info:DynamicInvoke*/a1.toString(42)); 210 (/*info:DYNAMIC_INVOKE*/a1.toString(42));
209 var toStringClosure = a1.toString; 211 var toStringClosure = a1.toString;
210 (/*info:DynamicInvoke*/a1.toStringClosure()); 212 (/*info:DYNAMIC_INVOKE*/a1.toStringClosure());
211 (/*info:DynamicInvoke*/a1.toStringClosure(42)); 213 (/*info:DYNAMIC_INVOKE*/a1.toStringClosure(42));
212 (/*info:DynamicInvoke*/a1.toStringClosure("hello")); 214 (/*info:DYNAMIC_INVOKE*/a1.toStringClosure("hello"));
213 a1.hashCode; 215 a1.hashCode;
214 216
215 dynamic toString = () => null; 217 dynamic toString = () => null;
216 (/*info:DynamicInvoke*/toString()); 218 (/*info:DYNAMIC_INVOKE*/toString());
217 219
218 (/*info:DynamicInvoke*/helper.toString()); 220 (/*info:DYNAMIC_INVOKE*/helper.toString());
219 var toStringClosure2 = helper.toString; 221 var toStringClosure2 = helper.toString;
220 (/*info:DynamicInvoke*/toStringClosure2()); 222 (/*info:DYNAMIC_INVOKE*/toStringClosure2());
221 int hashCode = /*info:DynamicCast*/helper.hashCode; 223 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode;
222 224
223 baz().toString(); 225 baz().toString();
224 baz().hashCode; 226 baz().hashCode;
225 } 227 }
226 ''' 228 '''
227 }); 229 });
228 230
229 testChecker('Constructors', { 231 testChecker('Constructors', {
230 '/main.dart': ''' 232 '/main.dart': '''
231 const num z = 25; 233 const num z = 25;
232 Object obj = "world"; 234 Object obj = "world";
233 235
234 class A { 236 class A {
235 int x; 237 int x;
236 String y; 238 String y;
237 239
238 A(this.x) : this.y = /*severe:StaticTypeError*/42; 240 A(this.x) : this.y = /*severe:STATIC_TYPE_ERROR*/42;
239 241
240 A.c1(p): this.x = /*info:DownCastImplicit*/z, this.y = /*info:DynamicCas t*/p; 242 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_ CAST*/p;
241 243
242 A.c2(this.x, this.y); 244 A.c2(this.x, this.y);
243 245
244 A.c3(/*severe:InvalidParameterDeclaration*/num this.x, String this.y); 246 A.c3(/*severe:INVALID_PARAMETER_DECLARATION*/num this.x, String this.y);
245 } 247 }
246 248
247 class B extends A { 249 class B extends A {
248 B() : super(/*severe:StaticTypeError*/"hello"); 250 B() : super(/*severe:STATIC_TYPE_ERROR*/"hello");
249 251
250 B.c2(int x, String y) : super.c2(/*severe:StaticTypeError*/y, 252 B.c2(int x, String y) : super.c2(/*severe:STATIC_TYPE_ERROR*/y,
251 /*severe:StaticTypeError*/x); 253 /*severe:STATIC_TYPE_ERROR*/x);
252 254
253 B.c3(num x, Object y) : super.c3(x, /*info:DownCastImplicit*/y); 255 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/y);
254 } 256 }
255 257
256 void main() { 258 void main() {
257 A a = new A.c2(/*info:DownCastImplicit*/z, /*severe:StaticTypeError*/z) ; 259 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR */z);
258 var b = new B.c2(/*severe:StaticTypeError*/"hello", /*info:DownCastImpl icit*/obj); 260 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_ IMPLICIT*/obj);
259 } 261 }
260 ''' 262 '''
261 }); 263 });
262 264
263 testChecker('Unbound variable', { 265 testChecker('Unbound variable', {
264 '/main.dart': ''' 266 '/main.dart': '''
265 void main() { 267 void main() {
266 dynamic y = /*pass should be severe:StaticTypeError*/unboundVariable; 268 dynamic y = /*pass should be severe:STATIC_TYPE_ERROR*/unboundVariable;
267 } 269 }
268 ''' 270 '''
269 }); 271 });
270 272
271 testChecker('Unbound type name', { 273 testChecker('Unbound type name', {
272 '/main.dart': ''' 274 '/main.dart': '''
273 void main() { 275 void main() {
274 /*pass should be severe:StaticTypeError*/AToB y; 276 /*pass should be severe:STATIC_TYPE_ERROR*/AToB y;
275 } 277 }
276 ''' 278 '''
277 }); 279 });
278 280
279 // Regression test for https://github.com/dart-lang/sdk/issues/25069 281 // Regression test for https://github.com/dart-lang/sdk/issues/25069
280 testChecker('Void subtyping', { 282 testChecker('Void subtyping', {
281 '/main.dart': ''' 283 '/main.dart': '''
282 typedef int Foo(); 284 typedef int Foo();
283 void foo() {} 285 void foo() {}
284 void main () { 286 void main () {
285 Foo x = /*severe:StaticTypeError*/foo(); 287 Foo x = /*severe:STATIC_TYPE_ERROR*/foo();
286 } 288 }
287 ''' 289 '''
288 }); 290 });
289 291
290 testChecker('Ground type subtyping: dynamic is top', { 292 testChecker('Ground type subtyping: dynamic is top', {
291 '/main.dart': ''' 293 '/main.dart': '''
292 294
293 class A {} 295 class A {}
294 class B extends A {} 296 class B extends A {}
295 297
(...skipping 23 matching lines...) Expand all
319 321
320 void main() { 322 void main() {
321 dynamic y; 323 dynamic y;
322 Object o; 324 Object o;
323 int i = 0; 325 int i = 0;
324 double d = 0.0; 326 double d = 0.0;
325 num n; 327 num n;
326 A a; 328 A a;
327 B b; 329 B b;
328 o = y; 330 o = y;
329 i = /*info:DynamicCast*/y; 331 i = /*info:DYNAMIC_CAST*/y;
330 d = /*info:DynamicCast*/y; 332 d = /*info:DYNAMIC_CAST*/y;
331 n = /*info:DynamicCast*/y; 333 n = /*info:DYNAMIC_CAST*/y;
332 a = /*info:DynamicCast*/y; 334 a = /*info:DYNAMIC_CAST*/y;
333 b = /*info:DynamicCast*/y; 335 b = /*info:DYNAMIC_CAST*/y;
334 } 336 }
335 ''' 337 '''
336 }); 338 });
337 339
338 testChecker('Ground type subtyping: assigning a class', { 340 testChecker('Ground type subtyping: assigning a class', {
339 '/main.dart': ''' 341 '/main.dart': '''
340 342
341 class A {} 343 class A {}
342 class B extends A {} 344 class B extends A {}
343 345
344 void main() { 346 void main() {
345 dynamic y; 347 dynamic y;
346 Object o; 348 Object o;
347 int i = 0; 349 int i = 0;
348 double d = 0.0; 350 double d = 0.0;
349 num n; 351 num n;
350 A a; 352 A a;
351 B b; 353 B b;
352 y = a; 354 y = a;
353 o = a; 355 o = a;
354 i = /*severe:StaticTypeError*/a; 356 i = /*severe:STATIC_TYPE_ERROR*/a;
355 d = /*severe:StaticTypeError*/a; 357 d = /*severe:STATIC_TYPE_ERROR*/a;
356 n = /*severe:StaticTypeError*/a; 358 n = /*severe:STATIC_TYPE_ERROR*/a;
357 a = a; 359 a = a;
358 b = /*info:DownCastImplicit*/a; 360 b = /*info:DOWN_CAST_IMPLICIT*/a;
359 } 361 }
360 ''' 362 '''
361 }); 363 });
362 364
363 testChecker('Ground type subtyping: assigning a subclass', { 365 testChecker('Ground type subtyping: assigning a subclass', {
364 '/main.dart': ''' 366 '/main.dart': '''
365 367
366 class A {} 368 class A {}
367 class B extends A {} 369 class B extends A {}
368 class C extends A {} 370 class C extends A {}
369 371
370 void main() { 372 void main() {
371 dynamic y; 373 dynamic y;
372 Object o; 374 Object o;
373 int i = 0; 375 int i = 0;
374 double d = 0.0; 376 double d = 0.0;
375 num n; 377 num n;
376 A a; 378 A a;
377 B b; 379 B b;
378 C c; 380 C c;
379 y = b; 381 y = b;
380 o = b; 382 o = b;
381 i = /*severe:StaticTypeError*/b; 383 i = /*severe:STATIC_TYPE_ERROR*/b;
382 d = /*severe:StaticTypeError*/b; 384 d = /*severe:STATIC_TYPE_ERROR*/b;
383 n = /*severe:StaticTypeError*/b; 385 n = /*severe:STATIC_TYPE_ERROR*/b;
384 a = b; 386 a = b;
385 b = b; 387 b = b;
386 c = /*severe:StaticTypeError*/b; 388 c = /*severe:STATIC_TYPE_ERROR*/b;
387 } 389 }
388 ''' 390 '''
389 }); 391 });
390 392
391 testChecker('Ground type subtyping: interfaces', { 393 testChecker('Ground type subtyping: interfaces', {
392 '/main.dart': ''' 394 '/main.dart': '''
393 395
394 class A {} 396 class A {}
395 class B extends A {} 397 class B extends A {}
396 class C extends A {} 398 class C extends A {}
397 class D extends B implements C {} 399 class D extends B implements C {}
398 400
399 void main() { 401 void main() {
400 A top; 402 A top;
401 B left; 403 B left;
402 C right; 404 C right;
403 D bot; 405 D bot;
404 { 406 {
405 top = top; 407 top = top;
406 top = left; 408 top = left;
407 top = right; 409 top = right;
408 top = bot; 410 top = bot;
409 } 411 }
410 { 412 {
411 left = /*info:DownCastImplicit*/top; 413 left = /*info:DOWN_CAST_IMPLICIT*/top;
412 left = left; 414 left = left;
413 left = /*severe:StaticTypeError*/right; 415 left = /*severe:STATIC_TYPE_ERROR*/right;
414 left = bot; 416 left = bot;
415 } 417 }
416 { 418 {
417 right = /*info:DownCastImplicit*/top; 419 right = /*info:DOWN_CAST_IMPLICIT*/top;
418 right = /*severe:StaticTypeError*/left; 420 right = /*severe:STATIC_TYPE_ERROR*/left;
419 right = right; 421 right = right;
420 right = bot; 422 right = bot;
421 } 423 }
422 { 424 {
423 bot = /*info:DownCastImplicit*/top; 425 bot = /*info:DOWN_CAST_IMPLICIT*/top;
424 bot = /*info:DownCastImplicit*/left; 426 bot = /*info:DOWN_CAST_IMPLICIT*/left;
425 bot = /*info:DownCastImplicit*/right; 427 bot = /*info:DOWN_CAST_IMPLICIT*/right;
426 bot = bot; 428 bot = bot;
427 } 429 }
428 } 430 }
429 ''' 431 '''
430 }); 432 });
431 433
432 testChecker('Function typing and subtyping: int and object', { 434 testChecker('Function typing and subtyping: int and object', {
433 '/main.dart': ''' 435 '/main.dart': '''
434 436
435 typedef Object Top(int x); // Top of the lattice 437 typedef Object Top(int x); // Top of the lattice
436 typedef int Left(int x); // Left branch 438 typedef int Left(int x); // Left branch
437 typedef int Left2(int x); // Left branch 439 typedef int Left2(int x); // Left branch
438 typedef Object Right(Object x); // Right branch 440 typedef Object Right(Object x); // Right branch
439 typedef int Bot(Object x); // Bottom of the lattice 441 typedef int Bot(Object x); // Bottom of the lattice
440 442
441 Object top(int x) => x; 443 Object top(int x) => x;
442 int left(int x) => x; 444 int left(int x) => x;
443 Object right(Object x) => x; 445 Object right(Object x) => x;
444 int _bot(Object x) => /*info:DownCastImplicit*/x; 446 int _bot(Object x) => /*info:DOWN_CAST_IMPLICIT*/x;
445 int bot(Object x) => x as int; 447 int bot(Object x) => x as int;
446 448
447 void main() { 449 void main() {
448 { // Check typedef equality 450 { // Check typedef equality
449 Left f = left; 451 Left f = left;
450 Left2 g = f; 452 Left2 g = f;
451 } 453 }
452 { 454 {
453 Top f; 455 Top f;
454 f = top; 456 f = top;
455 f = left; 457 f = left;
456 f = right; 458 f = right;
457 f = bot; 459 f = bot;
458 } 460 }
459 { 461 {
460 Left f; 462 Left f;
461 f = /*warning:DownCastComposite*/top; 463 f = /*warning:DOWN_CAST_COMPOSITE*/top;
462 f = left; 464 f = left;
463 f = /*warning:DownCastComposite*/right; // Should we reject this? 465 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this?
464 f = bot; 466 f = bot;
465 } 467 }
466 { 468 {
467 Right f; 469 Right f;
468 f = /*warning:DownCastComposite*/top; 470 f = /*warning:DOWN_CAST_COMPOSITE*/top;
469 f = /*warning:DownCastComposite*/left; // Should we reject this? 471 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this?
470 f = right; 472 f = right;
471 f = bot; 473 f = bot;
472 } 474 }
473 { 475 {
474 Bot f; 476 Bot f;
475 f = /*warning:DownCastComposite*/top; 477 f = /*warning:DOWN_CAST_COMPOSITE*/top;
476 f = /*warning:DownCastComposite*/left; 478 f = /*warning:DOWN_CAST_COMPOSITE*/left;
477 f = /*warning:DownCastComposite*/right; 479 f = /*warning:DOWN_CAST_COMPOSITE*/right;
478 f = bot; 480 f = bot;
479 } 481 }
480 } 482 }
481 ''' 483 '''
482 }); 484 });
483 485
484 testChecker('Function typing and subtyping: classes', { 486 testChecker('Function typing and subtyping: classes', {
485 '/main.dart': ''' 487 '/main.dart': '''
486 488
487 class A {} 489 class A {}
488 class B extends A {} 490 class B extends A {}
489 491
490 typedef A Top(B x); // Top of the lattice 492 typedef A Top(B x); // Top of the lattice
491 typedef B Left(B x); // Left branch 493 typedef B Left(B x); // Left branch
492 typedef B Left2(B x); // Left branch 494 typedef B Left2(B x); // Left branch
493 typedef A Right(A x); // Right branch 495 typedef A Right(A x); // Right branch
494 typedef B Bot(A x); // Bottom of the lattice 496 typedef B Bot(A x); // Bottom of the lattice
495 497
496 B left(B x) => x; 498 B left(B x) => x;
497 B _bot(A x) => /*info:DownCastImplicit*/x; 499 B _bot(A x) => /*info:DOWN_CAST_IMPLICIT*/x;
498 B bot(A x) => x as B; 500 B bot(A x) => x as B;
499 A top(B x) => x; 501 A top(B x) => x;
500 A right(A x) => x; 502 A right(A x) => x;
501 503
502 void main() { 504 void main() {
503 { // Check typedef equality 505 { // Check typedef equality
504 Left f = left; 506 Left f = left;
505 Left2 g = f; 507 Left2 g = f;
506 } 508 }
507 { 509 {
508 Top f; 510 Top f;
509 f = top; 511 f = top;
510 f = left; 512 f = left;
511 f = right; 513 f = right;
512 f = bot; 514 f = bot;
513 } 515 }
514 { 516 {
515 Left f; 517 Left f;
516 f = /*warning:DownCastComposite*/top; 518 f = /*warning:DOWN_CAST_COMPOSITE*/top;
517 f = left; 519 f = left;
518 f = /*warning:DownCastComposite*/right; // Should we reject this? 520 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this?
519 f = bot; 521 f = bot;
520 } 522 }
521 { 523 {
522 Right f; 524 Right f;
523 f = /*warning:DownCastComposite*/top; 525 f = /*warning:DOWN_CAST_COMPOSITE*/top;
524 f = /*warning:DownCastComposite*/left; // Should we reject this? 526 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this?
525 f = right; 527 f = right;
526 f = bot; 528 f = bot;
527 } 529 }
528 { 530 {
529 Bot f; 531 Bot f;
530 f = /*warning:DownCastComposite*/top; 532 f = /*warning:DOWN_CAST_COMPOSITE*/top;
531 f = /*warning:DownCastComposite*/left; 533 f = /*warning:DOWN_CAST_COMPOSITE*/left;
532 f = /*warning:DownCastComposite*/right; 534 f = /*warning:DOWN_CAST_COMPOSITE*/right;
533 f = bot; 535 f = bot;
534 } 536 }
535 } 537 }
536 ''' 538 '''
537 }); 539 });
538 540
539 testChecker('Function typing and subtyping: dynamic', { 541 testChecker('Function typing and subtyping: dynamic', {
540 '/main.dart': ''' 542 '/main.dart': '''
541 543
542 class A {} 544 class A {}
543 545
544 typedef dynamic Top(dynamic x); // Top of the lattice 546 typedef dynamic Top(dynamic x); // Top of the lattice
545 typedef dynamic Left(A x); // Left branch 547 typedef dynamic Left(A x); // Left branch
546 typedef A Right(dynamic x); // Right branch 548 typedef A Right(dynamic x); // Right branch
547 typedef A Bottom(A x); // Bottom of the lattice 549 typedef A Bottom(A x); // Bottom of the lattice
548 550
549 dynamic left(A x) => x; 551 dynamic left(A x) => x;
550 A bot(A x) => x; 552 A bot(A x) => x;
551 dynamic top(dynamic x) => x; 553 dynamic top(dynamic x) => x;
552 A right(dynamic x) => /*info:DynamicCast*/x; 554 A right(dynamic x) => /*info:DYNAMIC_CAST*/x;
553 555
554 void main() { 556 void main() {
555 { 557 {
556 Top f; 558 Top f;
557 f = top; 559 f = top;
558 f = left; 560 f = left;
559 f = right; 561 f = right;
560 f = bot; 562 f = bot;
561 } 563 }
562 { 564 {
563 Left f; 565 Left f;
564 f = /*warning:DownCastComposite*/top; 566 f = /*warning:DOWN_CAST_COMPOSITE*/top;
565 f = left; 567 f = left;
566 f = /*warning:DownCastComposite*/right; 568 f = /*warning:DOWN_CAST_COMPOSITE*/right;
567 f = bot; 569 f = bot;
568 } 570 }
569 { 571 {
570 Right f; 572 Right f;
571 f = /*warning:DownCastComposite*/top; 573 f = /*warning:DOWN_CAST_COMPOSITE*/top;
572 f = /*warning:DownCastComposite*/left; 574 f = /*warning:DOWN_CAST_COMPOSITE*/left;
573 f = right; 575 f = right;
574 f = bot; 576 f = bot;
575 } 577 }
576 { 578 {
577 Bottom f; 579 Bottom f;
578 f = /*warning:DownCastComposite*/top; 580 f = /*warning:DOWN_CAST_COMPOSITE*/top;
579 f = /*warning:DownCastComposite*/left; 581 f = /*warning:DOWN_CAST_COMPOSITE*/left;
580 f = /*warning:DownCastComposite*/right; 582 f = /*warning:DOWN_CAST_COMPOSITE*/right;
581 f = bot; 583 f = bot;
582 } 584 }
583 } 585 }
584 ''' 586 '''
585 }); 587 });
586 588
587 testChecker('Function typing and subtyping: function literal variance', { 589 testChecker('Function typing and subtyping: function literal variance', {
588 '/main.dart': ''' 590 '/main.dart': '''
589 591
590 class A {} 592 class A {}
591 class B extends A {} 593 class B extends A {}
592 594
593 typedef T Function2<S, T>(S z); 595 typedef T Function2<S, T>(S z);
594 596
595 A top(B x) => x; 597 A top(B x) => x;
596 B left(B x) => x; 598 B left(B x) => x;
597 A right(A x) => x; 599 A right(A x) => x;
598 B bot(A x) => x as B; 600 B bot(A x) => x as B;
599 601
600 void main() { 602 void main() {
601 { 603 {
602 Function2<B, A> f; 604 Function2<B, A> f;
603 f = top; 605 f = top;
604 f = left; 606 f = left;
605 f = right; 607 f = right;
606 f = bot; 608 f = bot;
607 } 609 }
608 { 610 {
609 Function2<B, B> f; 611 Function2<B, B> f;
610 f = /*warning:DownCastComposite*/top; 612 f = /*warning:DOWN_CAST_COMPOSITE*/top;
611 f = left; 613 f = left;
612 f = /*warning:DownCastComposite*/right; // Should we reject this? 614 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this?
613 f = bot; 615 f = bot;
614 } 616 }
615 { 617 {
616 Function2<A, A> f; 618 Function2<A, A> f;
617 f = /*warning:DownCastComposite*/top; 619 f = /*warning:DOWN_CAST_COMPOSITE*/top;
618 f = /*warning:DownCastComposite*/left; // Should we reject this? 620 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this?
619 f = right; 621 f = right;
620 f = bot; 622 f = bot;
621 } 623 }
622 { 624 {
623 Function2<A, B> f; 625 Function2<A, B> f;
624 f = /*warning:DownCastComposite*/top; 626 f = /*warning:DOWN_CAST_COMPOSITE*/top;
625 f = /*warning:DownCastComposite*/left; 627 f = /*warning:DOWN_CAST_COMPOSITE*/left;
626 f = /*warning:DownCastComposite*/right; 628 f = /*warning:DOWN_CAST_COMPOSITE*/right;
627 f = bot; 629 f = bot;
628 } 630 }
629 } 631 }
630 ''' 632 '''
631 }); 633 });
632 634
633 testChecker('Function typing and subtyping: function variable variance', { 635 testChecker('Function typing and subtyping: function variable variance', {
634 '/main.dart': ''' 636 '/main.dart': '''
635 637
636 class A {} 638 class A {}
637 class B extends A {} 639 class B extends A {}
638 640
639 typedef T Function2<S, T>(S z); 641 typedef T Function2<S, T>(S z);
640 642
641 void main() { 643 void main() {
642 { 644 {
643 Function2<B, A> top; 645 Function2<B, A> top;
644 Function2<B, B> left; 646 Function2<B, B> left;
645 Function2<A, A> right; 647 Function2<A, A> right;
646 Function2<A, B> bot; 648 Function2<A, B> bot;
647 649
648 top = right; 650 top = right;
649 top = bot; 651 top = bot;
650 top = top; 652 top = top;
651 top = left; 653 top = left;
652 654
653 left = /*warning:DownCastComposite*/top; 655 left = /*warning:DOWN_CAST_COMPOSITE*/top;
654 left = left; 656 left = left;
655 left = /*warning:DownCastComposite*/right; // Should we reject this? 657 left = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this?
656 left = bot; 658 left = bot;
657 659
658 right = /*warning:DownCastComposite*/top; 660 right = /*warning:DOWN_CAST_COMPOSITE*/top;
659 right = /*warning:DownCastComposite*/left; // Should we reject this? 661 right = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this?
660 right = right; 662 right = right;
661 right = bot; 663 right = bot;
662 664
663 bot = /*warning:DownCastComposite*/top; 665 bot = /*warning:DOWN_CAST_COMPOSITE*/top;
664 bot = /*warning:DownCastComposite*/left; 666 bot = /*warning:DOWN_CAST_COMPOSITE*/left;
665 bot = /*warning:DownCastComposite*/right; 667 bot = /*warning:DOWN_CAST_COMPOSITE*/right;
666 bot = bot; 668 bot = bot;
667 } 669 }
668 } 670 }
669 ''' 671 '''
670 }); 672 });
671 673
672 testChecker('Function typing and subtyping: higher order function literals', { 674 testChecker('Function typing and subtyping: higher order function literals', {
673 '/main.dart': ''' 675 '/main.dart': '''
674 676
675 class A {} 677 class A {}
676 class B extends A {} 678 class B extends A {}
677 679
678 typedef T Function2<S, T>(S z); 680 typedef T Function2<S, T>(S z);
679 681
680 typedef A BToA(B x); // Top of the base lattice 682 typedef A BToA(B x); // Top of the base lattice
681 typedef B AToB(A x); // Bot of the base lattice 683 typedef B AToB(A x); // Bot of the base lattice
682 684
683 BToA top(AToB f) => f; 685 BToA top(AToB f) => f;
684 AToB left(AToB f) => f; 686 AToB left(AToB f) => f;
685 BToA right(BToA f) => f; 687 BToA right(BToA f) => f;
686 AToB _bot(BToA f) => /*warning:DownCastComposite*/f; 688 AToB _bot(BToA f) => /*warning:DOWN_CAST_COMPOSITE*/f;
687 AToB bot(BToA f) => f as AToB; 689 AToB bot(BToA f) => f as AToB;
688 690
689 Function2<B, A> top(AToB f) => f; 691 Function2<B, A> top(AToB f) => f;
690 Function2<A, B> left(AToB f) => f; 692 Function2<A, B> left(AToB f) => f;
691 Function2<B, A> right(BToA f) => f; 693 Function2<B, A> right(BToA f) => f;
692 Function2<A, B> _bot(BToA f) => /*warning:DownCastComposite*/f; 694 Function2<A, B> _bot(BToA f) => /*warning:DOWN_CAST_COMPOSITE*/f;
693 Function2<A, B> bot(BToA f) => f as Function2<A, B>; 695 Function2<A, B> bot(BToA f) => f as Function2<A, B>;
694 696
695 697
696 BToA top(Function2<A, B> f) => f; 698 BToA top(Function2<A, B> f) => f;
697 AToB left(Function2<A, B> f) => f; 699 AToB left(Function2<A, B> f) => f;
698 BToA right(Function2<B, A> f) => f; 700 BToA right(Function2<B, A> f) => f;
699 AToB _bot(Function2<B, A> f) => /*warning:DownCastComposite*/f; 701 AToB _bot(Function2<B, A> f) => /*warning:DOWN_CAST_COMPOSITE*/f;
700 AToB bot(Function2<B, A> f) => f as AToB; 702 AToB bot(Function2<B, A> f) => f as AToB;
701 703
702 void main() { 704 void main() {
703 { 705 {
704 Function2<AToB, BToA> f; // Top 706 Function2<AToB, BToA> f; // Top
705 f = top; 707 f = top;
706 f = left; 708 f = left;
707 f = right; 709 f = right;
708 f = bot; 710 f = bot;
709 } 711 }
710 { 712 {
711 Function2<AToB, AToB> f; // Left 713 Function2<AToB, AToB> f; // Left
712 f = /*warning:DownCastComposite*/top; 714 f = /*warning:DOWN_CAST_COMPOSITE*/top;
713 f = left; 715 f = left;
714 f = /*warning:DownCastComposite*/right; // Should we reject this? 716 f = /*warning:DOWN_CAST_COMPOSITE*/right; // Should we reject this?
715 f = bot; 717 f = bot;
716 } 718 }
717 { 719 {
718 Function2<BToA, BToA> f; // Right 720 Function2<BToA, BToA> f; // Right
719 f = /*warning:DownCastComposite*/top; 721 f = /*warning:DOWN_CAST_COMPOSITE*/top;
720 f = /*warning:DownCastComposite*/left; // Should we reject this? 722 f = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this?
721 f = right; 723 f = right;
722 f = bot; 724 f = bot;
723 } 725 }
724 { 726 {
725 Function2<BToA, AToB> f; // Bot 727 Function2<BToA, AToB> f; // Bot
726 f = bot; 728 f = bot;
727 f = /*warning:DownCastComposite*/left; 729 f = /*warning:DOWN_CAST_COMPOSITE*/left;
728 f = /*warning:DownCastComposite*/top; 730 f = /*warning:DOWN_CAST_COMPOSITE*/top;
729 f = /*warning:DownCastComposite*/left; 731 f = /*warning:DOWN_CAST_COMPOSITE*/left;
730 } 732 }
731 } 733 }
732 ''' 734 '''
733 }); 735 });
734 736
735 testChecker( 737 testChecker(
736 'Function typing and subtyping: higher order function variables', { 738 'Function typing and subtyping: higher order function variables', {
737 '/main.dart': ''' 739 '/main.dart': '''
738 740
739 class A {} 741 class A {}
740 class B extends A {} 742 class B extends A {}
741 743
742 typedef T Function2<S, T>(S z); 744 typedef T Function2<S, T>(S z);
743 745
744 void main() { 746 void main() {
745 { 747 {
746 Function2<Function2<A, B>, Function2<B, A>> top; 748 Function2<Function2<A, B>, Function2<B, A>> top;
747 Function2<Function2<B, A>, Function2<B, A>> right; 749 Function2<Function2<B, A>, Function2<B, A>> right;
748 Function2<Function2<A, B>, Function2<A, B>> left; 750 Function2<Function2<A, B>, Function2<A, B>> left;
749 Function2<Function2<B, A>, Function2<A, B>> bot; 751 Function2<Function2<B, A>, Function2<A, B>> bot;
750 752
751 top = right; 753 top = right;
752 top = bot; 754 top = bot;
753 top = top; 755 top = top;
754 top = left; 756 top = left;
755 757
756 left = /*warning:DownCastComposite*/top; 758 left = /*warning:DOWN_CAST_COMPOSITE*/top;
757 left = left; 759 left = left;
758 left = 760 left =
759 /*warning:DownCastComposite should be severe:StaticTypeError*/right; 761 /*warning:DOWN_CAST_COMPOSITE should be severe:STATIC_TYPE_ERROR*/ri ght;
760 left = bot; 762 left = bot;
761 763
762 right = /*warning:DownCastComposite*/top; 764 right = /*warning:DOWN_CAST_COMPOSITE*/top;
763 right = 765 right =
764 /*warning:DownCastComposite should be severe:StaticTypeError*/left; 766 /*warning:DOWN_CAST_COMPOSITE should be severe:STATIC_TYPE_ERROR*/le ft;
765 right = right; 767 right = right;
766 right = bot; 768 right = bot;
767 769
768 bot = /*warning:DownCastComposite*/top; 770 bot = /*warning:DOWN_CAST_COMPOSITE*/top;
769 bot = /*warning:DownCastComposite*/left; 771 bot = /*warning:DOWN_CAST_COMPOSITE*/left;
770 bot = /*warning:DownCastComposite*/right; 772 bot = /*warning:DOWN_CAST_COMPOSITE*/right;
771 bot = bot; 773 bot = bot;
772 } 774 }
773 } 775 }
774 ''' 776 '''
775 }); 777 });
776 778
777 testChecker('Function typing and subtyping: named and optional parameters', { 779 testChecker('Function typing and subtyping: named and optional parameters', {
778 '/main.dart': ''' 780 '/main.dart': '''
779 781
780 class A {} 782 class A {}
(...skipping 14 matching lines...) Expand all
795 FN n; 797 FN n;
796 FRR rr; 798 FRR rr;
797 FRO ro; 799 FRO ro;
798 FRN rn; 800 FRN rn;
799 FOO oo; 801 FOO oo;
800 FNN nn; 802 FNN nn;
801 FNNN nnn; 803 FNNN nnn;
802 804
803 r = r; 805 r = r;
804 r = o; 806 r = o;
805 r = /*severe:StaticTypeError*/n; 807 r = /*severe:STATIC_TYPE_ERROR*/n;
806 r = /*severe:StaticTypeError*/rr; 808 r = /*severe:STATIC_TYPE_ERROR*/rr;
807 r = ro; 809 r = ro;
808 r = rn; 810 r = rn;
809 r = oo; 811 r = oo;
810 r = /*severe:StaticTypeError*/nn; 812 r = /*severe:STATIC_TYPE_ERROR*/nn;
811 r = /*severe:StaticTypeError*/nnn; 813 r = /*severe:STATIC_TYPE_ERROR*/nnn;
812 814
813 o = /*warning:DownCastComposite*/r; 815 o = /*warning:DOWN_CAST_COMPOSITE*/r;
814 o = o; 816 o = o;
815 o = /*severe:StaticTypeError*/n; 817 o = /*severe:STATIC_TYPE_ERROR*/n;
816 o = /*severe:StaticTypeError*/rr; 818 o = /*severe:STATIC_TYPE_ERROR*/rr;
817 o = /*severe:StaticTypeError*/ro; 819 o = /*severe:STATIC_TYPE_ERROR*/ro;
818 o = /*severe:StaticTypeError*/rn; 820 o = /*severe:STATIC_TYPE_ERROR*/rn;
819 o = oo; 821 o = oo;
820 o = /*severe:StaticTypeError*/nn 822 o = /*severe:STATIC_TYPE_ERROR*/nn
821 o = /*severe:StaticTypeError*/nnn; 823 o = /*severe:STATIC_TYPE_ERROR*/nnn;
822 824
823 n = /*severe:StaticTypeError*/r; 825 n = /*severe:STATIC_TYPE_ERROR*/r;
824 n = /*severe:StaticTypeError*/o; 826 n = /*severe:STATIC_TYPE_ERROR*/o;
825 n = n; 827 n = n;
826 n = /*severe:StaticTypeError*/rr; 828 n = /*severe:STATIC_TYPE_ERROR*/rr;
827 n = /*severe:StaticTypeError*/ro; 829 n = /*severe:STATIC_TYPE_ERROR*/ro;
828 n = /*severe:StaticTypeError*/rn; 830 n = /*severe:STATIC_TYPE_ERROR*/rn;
829 n = /*severe:StaticTypeError*/oo; 831 n = /*severe:STATIC_TYPE_ERROR*/oo;
830 n = nn; 832 n = nn;
831 n = nnn; 833 n = nnn;
832 834
833 rr = /*severe:StaticTypeError*/r; 835 rr = /*severe:STATIC_TYPE_ERROR*/r;
834 rr = /*severe:StaticTypeError*/o; 836 rr = /*severe:STATIC_TYPE_ERROR*/o;
835 rr = /*severe:StaticTypeError*/n; 837 rr = /*severe:STATIC_TYPE_ERROR*/n;
836 rr = rr; 838 rr = rr;
837 rr = ro; 839 rr = ro;
838 rr = /*severe:StaticTypeError*/rn; 840 rr = /*severe:STATIC_TYPE_ERROR*/rn;
839 rr = oo; 841 rr = oo;
840 rr = /*severe:StaticTypeError*/nn; 842 rr = /*severe:STATIC_TYPE_ERROR*/nn;
841 rr = /*severe:StaticTypeError*/nnn; 843 rr = /*severe:STATIC_TYPE_ERROR*/nnn;
842 844
843 ro = /*warning:DownCastComposite*/r; 845 ro = /*warning:DOWN_CAST_COMPOSITE*/r;
844 ro = /*severe:StaticTypeError*/o; 846 ro = /*severe:STATIC_TYPE_ERROR*/o;
845 ro = /*severe:StaticTypeError*/n; 847 ro = /*severe:STATIC_TYPE_ERROR*/n;
846 ro = /*warning:DownCastComposite*/rr; 848 ro = /*warning:DOWN_CAST_COMPOSITE*/rr;
847 ro = ro; 849 ro = ro;
848 ro = /*severe:StaticTypeError*/rn; 850 ro = /*severe:STATIC_TYPE_ERROR*/rn;
849 ro = oo; 851 ro = oo;
850 ro = /*severe:StaticTypeError*/nn; 852 ro = /*severe:STATIC_TYPE_ERROR*/nn;
851 ro = /*severe:StaticTypeError*/nnn; 853 ro = /*severe:STATIC_TYPE_ERROR*/nnn;
852 854
853 rn = /*warning:DownCastComposite*/r; 855 rn = /*warning:DOWN_CAST_COMPOSITE*/r;
854 rn = /*severe:StaticTypeError*/o; 856 rn = /*severe:STATIC_TYPE_ERROR*/o;
855 rn = /*severe:StaticTypeError*/n; 857 rn = /*severe:STATIC_TYPE_ERROR*/n;
856 rn = /*severe:StaticTypeError*/rr; 858 rn = /*severe:STATIC_TYPE_ERROR*/rr;
857 rn = /*severe:StaticTypeError*/ro; 859 rn = /*severe:STATIC_TYPE_ERROR*/ro;
858 rn = rn; 860 rn = rn;
859 rn = /*severe:StaticTypeError*/oo; 861 rn = /*severe:STATIC_TYPE_ERROR*/oo;
860 rn = /*severe:StaticTypeError*/nn; 862 rn = /*severe:STATIC_TYPE_ERROR*/nn;
861 rn = /*severe:StaticTypeError*/nnn; 863 rn = /*severe:STATIC_TYPE_ERROR*/nnn;
862 864
863 oo = /*warning:DownCastComposite*/r; 865 oo = /*warning:DOWN_CAST_COMPOSITE*/r;
864 oo = /*warning:DownCastComposite*/o; 866 oo = /*warning:DOWN_CAST_COMPOSITE*/o;
865 oo = /*severe:StaticTypeError*/n; 867 oo = /*severe:STATIC_TYPE_ERROR*/n;
866 oo = /*warning:DownCastComposite*/rr; 868 oo = /*warning:DOWN_CAST_COMPOSITE*/rr;
867 oo = /*warning:DownCastComposite*/ro; 869 oo = /*warning:DOWN_CAST_COMPOSITE*/ro;
868 oo = /*severe:StaticTypeError*/rn; 870 oo = /*severe:STATIC_TYPE_ERROR*/rn;
869 oo = oo; 871 oo = oo;
870 oo = /*severe:StaticTypeError*/nn; 872 oo = /*severe:STATIC_TYPE_ERROR*/nn;
871 oo = /*severe:StaticTypeError*/nnn; 873 oo = /*severe:STATIC_TYPE_ERROR*/nnn;
872 874
873 nn = /*severe:StaticTypeError*/r; 875 nn = /*severe:STATIC_TYPE_ERROR*/r;
874 nn = /*severe:StaticTypeError*/o; 876 nn = /*severe:STATIC_TYPE_ERROR*/o;
875 nn = /*warning:DownCastComposite*/n; 877 nn = /*warning:DOWN_CAST_COMPOSITE*/n;
876 nn = /*severe:StaticTypeError*/rr; 878 nn = /*severe:STATIC_TYPE_ERROR*/rr;
877 nn = /*severe:StaticTypeError*/ro; 879 nn = /*severe:STATIC_TYPE_ERROR*/ro;
878 nn = /*severe:StaticTypeError*/rn; 880 nn = /*severe:STATIC_TYPE_ERROR*/rn;
879 nn = /*severe:StaticTypeError*/oo; 881 nn = /*severe:STATIC_TYPE_ERROR*/oo;
880 nn = nn; 882 nn = nn;
881 nn = nnn; 883 nn = nnn;
882 884
883 nnn = /*severe:StaticTypeError*/r; 885 nnn = /*severe:STATIC_TYPE_ERROR*/r;
884 nnn = /*severe:StaticTypeError*/o; 886 nnn = /*severe:STATIC_TYPE_ERROR*/o;
885 nnn = /*warning:DownCastComposite*/n; 887 nnn = /*warning:DOWN_CAST_COMPOSITE*/n;
886 nnn = /*severe:StaticTypeError*/rr; 888 nnn = /*severe:STATIC_TYPE_ERROR*/rr;
887 nnn = /*severe:StaticTypeError*/ro; 889 nnn = /*severe:STATIC_TYPE_ERROR*/ro;
888 nnn = /*severe:StaticTypeError*/rn; 890 nnn = /*severe:STATIC_TYPE_ERROR*/rn;
889 nnn = /*severe:StaticTypeError*/oo; 891 nnn = /*severe:STATIC_TYPE_ERROR*/oo;
890 nnn = /*warning:DownCastComposite*/nn; 892 nnn = /*warning:DOWN_CAST_COMPOSITE*/nn;
891 nnn = nnn; 893 nnn = nnn;
892 } 894 }
893 ''' 895 '''
894 }); 896 });
895 897
896 testChecker('Function subtyping: objects with call methods', { 898 testChecker('Function subtyping: objects with call methods', {
897 '/main.dart': ''' 899 '/main.dart': '''
898 900
899 typedef int I2I(int x); 901 typedef int I2I(int x);
900 typedef num N2N(num x); 902 typedef num N2N(num x);
901 class A { 903 class A {
902 int call(int x) => x; 904 int call(int x) => x;
903 } 905 }
904 class B { 906 class B {
905 num call(num x) => x; 907 num call(num x) => x;
906 } 908 }
907 int i2i(int x) => x; 909 int i2i(int x) => x;
908 num n2n(num x) => x; 910 num n2n(num x) => x;
909 void main() { 911 void main() {
910 { 912 {
911 I2I f; 913 I2I f;
912 f = new A(); 914 f = new A();
913 f = /*severe:StaticTypeError*/new B(); 915 f = /*severe:STATIC_TYPE_ERROR*/new B();
914 f = i2i; 916 f = i2i;
915 f = /*warning:DownCastComposite*/n2n; 917 f = /*warning:DOWN_CAST_COMPOSITE*/n2n;
916 f = /*warning:DownCastComposite*/i2i as Object; 918 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object;
917 f = /*warning:DownCastComposite*/n2n as Function; 919 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function;
918 } 920 }
919 { 921 {
920 N2N f; 922 N2N f;
921 f = /*severe:StaticTypeError*/new A(); 923 f = /*severe:STATIC_TYPE_ERROR*/new A();
922 f = new B(); 924 f = new B();
923 f = /*warning:DownCastComposite*/i2i; 925 f = /*warning:DOWN_CAST_COMPOSITE*/i2i;
924 f = n2n; 926 f = n2n;
925 f = /*warning:DownCastComposite*/i2i as Object; 927 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object;
926 f = /*warning:DownCastComposite*/n2n as Function; 928 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function;
927 } 929 }
928 { 930 {
929 A f; 931 A f;
930 f = new A(); 932 f = new A();
931 f = /*severe:StaticTypeError*/new B(); 933 f = /*severe:STATIC_TYPE_ERROR*/new B();
932 f = /*severe:StaticTypeError*/i2i; 934 f = /*severe:STATIC_TYPE_ERROR*/i2i;
933 f = /*severe:StaticTypeError*/n2n; 935 f = /*severe:STATIC_TYPE_ERROR*/n2n;
934 f = /*info:DownCastImplicit*/i2i as Object; 936 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object;
935 f = /*info:DownCastImplicit*/n2n as Function; 937 f = /*info:DOWN_CAST_IMPLICIT*/n2n as Function;
936 } 938 }
937 { 939 {
938 B f; 940 B f;
939 f = /*severe:StaticTypeError*/new A(); 941 f = /*severe:STATIC_TYPE_ERROR*/new A();
940 f = new B(); 942 f = new B();
941 f = /*severe:StaticTypeError*/i2i; 943 f = /*severe:STATIC_TYPE_ERROR*/i2i;
942 f = /*severe:StaticTypeError*/n2n; 944 f = /*severe:STATIC_TYPE_ERROR*/n2n;
943 f = /*info:DownCastImplicit*/i2i as Object; 945 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object;
944 f = /*info:DownCastImplicit*/n2n as Function; 946 f = /*info:DOWN_CAST_IMPLICIT*/n2n as Function;
945 } 947 }
946 { 948 {
947 Function f; 949 Function f;
948 f = new A(); 950 f = new A();
949 f = new B(); 951 f = new B();
950 f = i2i; 952 f = i2i;
951 f = n2n; 953 f = n2n;
952 f = /*info:DownCastImplicit*/i2i as Object; 954 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object;
953 f = (n2n as Function); 955 f = (n2n as Function);
954 } 956 }
955 } 957 }
956 ''' 958 '''
957 }); 959 });
958 960
959 testChecker('Function typing and subtyping: void', { 961 testChecker('Function typing and subtyping: void', {
960 '/main.dart': ''' 962 '/main.dart': '''
961 963
962 class A { 964 class A {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 } 1003 }
1002 { 1004 {
1003 lOfOs = mOfDs; 1005 lOfOs = mOfDs;
1004 lOfOs = mOfOs; 1006 lOfOs = mOfOs;
1005 lOfOs = mOfAs; 1007 lOfOs = mOfAs;
1006 lOfOs = lOfDs; 1008 lOfOs = lOfDs;
1007 lOfOs = lOfOs; 1009 lOfOs = lOfOs;
1008 lOfOs = lOfAs; 1010 lOfOs = lOfAs;
1009 } 1011 }
1010 { 1012 {
1011 lOfAs = /*warning:DownCastComposite*/mOfDs; 1013 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs;
1012 lOfAs = /*severe:StaticTypeError*/mOfOs; 1014 lOfAs = /*severe:STATIC_TYPE_ERROR*/mOfOs;
1013 lOfAs = mOfAs; 1015 lOfAs = mOfAs;
1014 lOfAs = /*warning:DownCastComposite*/lOfDs; 1016 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs;
1015 lOfAs = /*info:DownCastImplicit*/lOfOs; 1017 lOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
1016 lOfAs = lOfAs; 1018 lOfAs = lOfAs;
1017 } 1019 }
1018 { 1020 {
1019 mOfDs = mOfDs; 1021 mOfDs = mOfDs;
1020 mOfDs = mOfOs; 1022 mOfDs = mOfOs;
1021 mOfDs = mOfAs; 1023 mOfDs = mOfAs;
1022 mOfDs = /*info:DownCastImplicit*/lOfDs; 1024 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfDs;
1023 mOfDs = /*info:DownCastImplicit*/lOfOs; 1025 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
1024 mOfDs = /*warning:DownCastComposite*/lOfAs; 1026 mOfDs = /*warning:DOWN_CAST_COMPOSITE*/lOfAs;
1025 } 1027 }
1026 { 1028 {
1027 mOfOs = mOfDs; 1029 mOfOs = mOfDs;
1028 mOfOs = mOfOs; 1030 mOfOs = mOfOs;
1029 mOfOs = mOfAs; 1031 mOfOs = mOfAs;
1030 mOfOs = /*info:DownCastImplicit*/lOfDs; 1032 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfDs;
1031 mOfOs = /*info:DownCastImplicit*/lOfOs; 1033 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
1032 mOfOs = /*severe:StaticTypeError*/lOfAs; 1034 mOfOs = /*severe:STATIC_TYPE_ERROR*/lOfAs;
1033 } 1035 }
1034 { 1036 {
1035 mOfAs = /*warning:DownCastComposite*/mOfDs; 1037 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs;
1036 mOfAs = /*info:DownCastImplicit*/mOfOs; 1038 mOfAs = /*info:DOWN_CAST_IMPLICIT*/mOfOs;
1037 mOfAs = mOfAs; 1039 mOfAs = mOfAs;
1038 mOfAs = /*warning:DownCastComposite*/lOfDs; 1040 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs;
1039 mOfAs = /*info:DownCastImplicit*/lOfOs; 1041 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
1040 mOfAs = /*info:DownCastImplicit*/lOfAs; 1042 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfAs;
1041 } 1043 }
1042 1044
1043 } 1045 }
1044 ''' 1046 '''
1045 }); 1047 });
1046 1048
1047 testChecker('Type checking literals', { 1049 testChecker('Type checking literals', {
1048 '/main.dart': ''' 1050 '/main.dart': '''
1049 test() { 1051 test() {
1050 num n = 3; 1052 num n = 3;
1051 int i = 3; 1053 int i = 3;
1052 String s = "hello"; 1054 String s = "hello";
1053 { 1055 {
1054 List<int> l = <int>[i]; 1056 List<int> l = <int>[i];
1055 l = <int>[/*severe:StaticTypeError*/s]; 1057 l = <int>[/*severe:STATIC_TYPE_ERROR*/s];
1056 l = <int>[/*info:DownCastImplicit*/n]; 1058 l = <int>[/*info:DOWN_CAST_IMPLICIT*/n];
1057 l = <int>[i, /*info:DownCastImplicit*/n, /*severe:StaticTypeError */s]; 1059 l = <int>[i, /*info:DOWN_CAST_IMPLICIT*/n, /*severe:STATIC_TYPE_E RROR*/s];
1058 } 1060 }
1059 { 1061 {
1060 List l = [i]; 1062 List l = [i];
1061 l = [s]; 1063 l = [s];
1062 l = [n]; 1064 l = [n];
1063 l = [i, n, s]; 1065 l = [i, n, s];
1064 } 1066 }
1065 { 1067 {
1066 Map<String, int> m = <String, int>{s: i}; 1068 Map<String, int> m = <String, int>{s: i};
1067 m = <String, int>{s: /*severe:StaticTypeError*/s}; 1069 m = <String, int>{s: /*severe:STATIC_TYPE_ERROR*/s};
1068 m = <String, int>{s: /*info:DownCastImplicit*/n}; 1070 m = <String, int>{s: /*info:DOWN_CAST_IMPLICIT*/n};
1069 m = <String, int>{s: i, 1071 m = <String, int>{s: i,
1070 s: /*info:DownCastImplicit*/n, 1072 s: /*info:DOWN_CAST_IMPLICIT*/n,
1071 s: /*severe:StaticTypeError*/s}; 1073 s: /*severe:STATIC_TYPE_ERROR*/s};
1072 } 1074 }
1073 // TODO(leafp): We can't currently test for key errors since the 1075 // TODO(leafp): We can't currently test for key errors since the
1074 // error marker binds to the entire entry. 1076 // error marker binds to the entire entry.
1075 { 1077 {
1076 Map m = {s: i}; 1078 Map m = {s: i};
1077 m = {s: s}; 1079 m = {s: s};
1078 m = {s: n}; 1080 m = {s: n};
1079 m = {s: i, 1081 m = {s: i,
1080 s: n, 1082 s: n,
1081 s: s}; 1083 s: s};
1082 m = {i: s, 1084 m = {i: s,
1083 n: s, 1085 n: s,
1084 s: s}; 1086 s: s};
1085 } 1087 }
1086 } 1088 }
1087 ''' 1089 '''
1088 }); 1090 });
1089 1091
1090 testChecker('casts in constant contexts', { 1092 testChecker('casts in constant contexts', {
1091 '/main.dart': ''' 1093 '/main.dart': '''
1092 class A { 1094 class A {
1093 static const num n = 3.0; 1095 static const num n = 3.0;
1094 static const int i = /*info:AssignmentCast*/n; 1096 static const int i = /*info:ASSIGNMENT_CAST*/n;
1095 final int fi; 1097 final int fi;
1096 const A(num a) : this.fi = /*info:DownCastImplicit*/a; 1098 const A(num a) : this.fi = /*info:DOWN_CAST_IMPLICIT*/a;
1097 } 1099 }
1098 class B extends A { 1100 class B extends A {
1099 const B(Object a) : super(/*info:DownCastImplicit*/a); 1101 const B(Object a) : super(/*info:DOWN_CAST_IMPLICIT*/a);
1100 } 1102 }
1101 void foo(Object o) { 1103 void foo(Object o) {
1102 var a = const A(/*info:DownCastImplicit*/o); 1104 var a = const A(/*info:DOWN_CAST_IMPLICIT*/o);
1103 } 1105 }
1104 ''' 1106 '''
1105 }); 1107 });
1106 1108
1107 testChecker('casts in conditionals', { 1109 testChecker('casts in conditionals', {
1108 '/main.dart': ''' 1110 '/main.dart': '''
1109 main() { 1111 main() {
1110 bool b = true; 1112 bool b = true;
1111 num x = b ? 1 : 2.3; 1113 num x = b ? 1 : 2.3;
1112 int y = /*info:AssignmentCast*/b ? 1 : 2.3; 1114 int y = /*info:ASSIGNMENT_CAST*/b ? 1 : 2.3;
1113 String z = !b ? "hello" : null; 1115 String z = !b ? "hello" : null;
1114 z = b ? null : "hello"; 1116 z = b ? null : "hello";
1115 } 1117 }
1116 ''' 1118 '''
1117 }); 1119 });
1118 1120
1119 // This is a regression test for https://github.com/dart-lang/sdk/issues/25071 1121 // This is a regression test for https://github.com/dart-lang/sdk/issues/25071
1120 testChecker('unbound redirecting constructor', { 1122 testChecker('unbound redirecting constructor', {
1121 '/main.dart': ''' 1123 '/main.dart': '''
1122 class Foo { 1124 class Foo {
1123 Foo() : this.init(); 1125 Foo() : this.init();
1124 } 1126 }
1125 ''' 1127 '''
1126 }); 1128 });
1127 1129
1128 testChecker('redirecting constructor', { 1130 testChecker('redirecting constructor', {
1129 '/main.dart': ''' 1131 '/main.dart': '''
1130 class A { 1132 class A {
1131 A(A x) {} 1133 A(A x) {}
1132 A.two() : this(/*severe:StaticTypeError*/3); 1134 A.two() : this(/*severe:STATIC_TYPE_ERROR*/3);
1133 } 1135 }
1134 ''' 1136 '''
1135 }); 1137 });
1136 1138
1137 testChecker('super constructor', { 1139 testChecker('super constructor', {
1138 '/main.dart': ''' 1140 '/main.dart': '''
1139 class A { A(A x) {} } 1141 class A { A(A x) {} }
1140 class B extends A { 1142 class B extends A {
1141 B() : super(/*severe:StaticTypeError*/3); 1143 B() : super(/*severe:STATIC_TYPE_ERROR*/3);
1142 } 1144 }
1143 ''' 1145 '''
1144 }); 1146 });
1145 1147
1146 testChecker('field/field override', { 1148 testChecker('field/field override', {
1147 '/main.dart': ''' 1149 '/main.dart': '''
1148 class A {} 1150 class A {}
1149 class B extends A {} 1151 class B extends A {}
1150 class C extends B {} 1152 class C extends B {}
1151 1153
1152 class Base { 1154 class Base {
1153 B f1; 1155 B f1;
1154 B f2; 1156 B f2;
1155 B f3; 1157 B f3;
1156 B f4; 1158 B f4;
1157 } 1159 }
1158 1160
1159 class Child extends Base { 1161 class Child extends Base {
1160 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/A f1; // invalid for getter 1162 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A f1 ; // invalid for getter
1161 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/C f2; // invalid for setter 1163 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/C f2 ; // invalid for setter
1162 /*severe:InvalidFieldOverride*/var f3; 1164 /*severe:INVALID_FIELD_OVERRIDE*/var f3;
1163 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride,severe:In validMethodOverride*/dynamic f4; 1165 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sever e:INVALID_METHOD_OVERRIDE*/dynamic f4;
1164 } 1166 }
1165 1167
1166 class Child2 implements Base { 1168 class Child2 implements Base {
1167 /*severe:InvalidMethodOverride*/A f1; // invalid for getter 1169 /*severe:INVALID_METHOD_OVERRIDE*/A f1; // invalid for getter
1168 /*severe:InvalidMethodOverride*/C f2; // invalid for setter 1170 /*severe:INVALID_METHOD_OVERRIDE*/C f2; // invalid for setter
1169 var f3; 1171 var f3;
1170 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic f4; 1172 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyn amic f4;
1171 } 1173 }
1172 ''' 1174 '''
1173 }); 1175 });
1174 1176
1175 testChecker('private override', { 1177 testChecker('private override', {
1176 '/helper.dart': ''' 1178 '/helper.dart': '''
1177 import 'main.dart' as main; 1179 import 'main.dart' as main;
1178 1180
1179 class Base { 1181 class Base {
1180 var f1; 1182 var f1;
1181 var _f2; 1183 var _f2;
1182 var _f3; 1184 var _f3;
1183 get _f4 => null; 1185 get _f4 => null;
1184 1186
1185 int _m1(); 1187 int _m1();
1186 } 1188 }
1187 1189
1188 class GrandChild extends main.Child { 1190 class GrandChild extends main.Child {
1189 /*severe:InvalidFieldOverride*/var _f2; 1191 /*severe:INVALID_FIELD_OVERRIDE*/var _f2;
1190 /*severe:InvalidFieldOverride*/var _f3; 1192 /*severe:INVALID_FIELD_OVERRIDE*/var _f3;
1191 var _f4; 1193 var _f4;
1192 1194
1193 /*severe:InvalidMethodOverride*/String _m1(); 1195 /*severe:INVALID_METHOD_OVERRIDE*/String _m1();
1194 } 1196 }
1195 ''', 1197 ''',
1196 '/main.dart': ''' 1198 '/main.dart': '''
1197 import 'helper.dart' as helper; 1199 import 'helper.dart' as helper;
1198 1200
1199 class Child extends helper.Base { 1201 class Child extends helper.Base {
1200 /*severe:InvalidFieldOverride*/var f1; 1202 /*severe:INVALID_FIELD_OVERRIDE*/var f1;
1201 var _f2; 1203 var _f2;
1202 var _f4; 1204 var _f4;
1203 1205
1204 String _m1(); 1206 String _m1();
1205 } 1207 }
1206 ''' 1208 '''
1207 }); 1209 });
1208 1210
1209 testChecker('getter/getter override', { 1211 testChecker('getter/getter override', {
1210 '/main.dart': ''' 1212 '/main.dart': '''
1211 class A {} 1213 class A {}
1212 class B extends A {} 1214 class B extends A {}
1213 class C extends B {} 1215 class C extends B {}
1214 1216
1215 abstract class Base { 1217 abstract class Base {
1216 B get f1; 1218 B get f1;
1217 B get f2; 1219 B get f2;
1218 B get f3; 1220 B get f3;
1219 B get f4; 1221 B get f4;
1220 } 1222 }
1221 1223
1222 class Child extends Base { 1224 class Child extends Base {
1223 /*severe:InvalidMethodOverride*/A get f1 => null; 1225 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null;
1224 C get f2 => null; 1226 C get f2 => null;
1225 get f3 => null; 1227 get f3 => null;
1226 /*severe:InvalidMethodOverride*/dynamic get f4 => null; 1228 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null;
1227 } 1229 }
1228 ''' 1230 '''
1229 }); 1231 });
1230 1232
1231 testChecker('field/getter override', { 1233 testChecker('field/getter override', {
1232 '/main.dart': ''' 1234 '/main.dart': '''
1233 class A {} 1235 class A {}
1234 class B extends A {} 1236 class B extends A {}
1235 class C extends B {} 1237 class C extends B {}
1236 1238
1237 abstract class Base { 1239 abstract class Base {
1238 B f1; 1240 B f1;
1239 B f2; 1241 B f2;
1240 B f3; 1242 B f3;
1241 B f4; 1243 B f4;
1242 } 1244 }
1243 1245
1244 class Child extends Base { 1246 class Child extends Base {
1245 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/A get f1 => null; 1247 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A ge t f1 => null;
1246 /*severe:InvalidFieldOverride*/C get f2 => null; 1248 /*severe:INVALID_FIELD_OVERRIDE*/C get f2 => null;
1247 /*severe:InvalidFieldOverride*/get f3 => null; 1249 /*severe:INVALID_FIELD_OVERRIDE*/get f3 => null;
1248 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/dynamic get f4 => null; 1250 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyna mic get f4 => null;
1249 } 1251 }
1250 1252
1251 class Child2 implements Base { 1253 class Child2 implements Base {
1252 /*severe:InvalidMethodOverride*/A get f1 => null; 1254 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null;
1253 C get f2 => null; 1255 C get f2 => null;
1254 get f3 => null; 1256 get f3 => null;
1255 /*severe:InvalidMethodOverride*/dynamic get f4 => null; 1257 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null;
1256 } 1258 }
1257 ''' 1259 '''
1258 }); 1260 });
1259 1261
1260 testChecker('setter/setter override', { 1262 testChecker('setter/setter override', {
1261 '/main.dart': ''' 1263 '/main.dart': '''
1262 class A {} 1264 class A {}
1263 class B extends A {} 1265 class B extends A {}
1264 class C extends B {} 1266 class C extends B {}
1265 1267
1266 abstract class Base { 1268 abstract class Base {
1267 void set f1(B value); 1269 void set f1(B value);
1268 void set f2(B value); 1270 void set f2(B value);
1269 void set f3(B value); 1271 void set f3(B value);
1270 void set f4(B value); 1272 void set f4(B value);
1271 void set f5(B value); 1273 void set f5(B value);
1272 } 1274 }
1273 1275
1274 class Child extends Base { 1276 class Child extends Base {
1275 void set f1(A value) {} 1277 void set f1(A value) {}
1276 /*severe:InvalidMethodOverride*/void set f2(C value) {} 1278 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {}
1277 void set f3(value) {} 1279 void set f3(value) {}
1278 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {} 1280 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {}
1279 set f5(B value) {} 1281 set f5(B value) {}
1280 } 1282 }
1281 ''' 1283 '''
1282 }); 1284 });
1283 1285
1284 testChecker('field/setter override', { 1286 testChecker('field/setter override', {
1285 '/main.dart': ''' 1287 '/main.dart': '''
1286 class A {} 1288 class A {}
1287 class B extends A {} 1289 class B extends A {}
1288 class C extends B {} 1290 class C extends B {}
1289 1291
1290 class Base { 1292 class Base {
1291 B f1; 1293 B f1;
1292 B f2; 1294 B f2;
1293 B f3; 1295 B f3;
1294 B f4; 1296 B f4;
1295 B f5; 1297 B f5;
1296 } 1298 }
1297 1299
1298 class Child extends Base { 1300 class Child extends Base {
1299 /*severe:InvalidFieldOverride*/B get f1 => null; 1301 /*severe:INVALID_FIELD_OVERRIDE*/B get f1 => null;
1300 /*severe:InvalidFieldOverride*/B get f2 => null; 1302 /*severe:INVALID_FIELD_OVERRIDE*/B get f2 => null;
1301 /*severe:InvalidFieldOverride*/B get f3 => null; 1303 /*severe:INVALID_FIELD_OVERRIDE*/B get f3 => null;
1302 /*severe:InvalidFieldOverride*/B get f4 => null; 1304 /*severe:INVALID_FIELD_OVERRIDE*/B get f4 => null;
1303 /*severe:InvalidFieldOverride*/B get f5 => null; 1305 /*severe:INVALID_FIELD_OVERRIDE*/B get f5 => null;
1304 1306
1305 /*severe:InvalidFieldOverride*/void set f1(A value) {} 1307 /*severe:INVALID_FIELD_OVERRIDE*/void set f1(A value) {}
1306 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/void set f2(C value) {} 1308 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {}
1307 /*severe:InvalidFieldOverride*/void set f3(value) {} 1309 /*severe:INVALID_FIELD_OVERRIDE*/void set f3(value) {}
1308 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/void set f4(dynamic value) {} 1310 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {}
1309 /*severe:InvalidFieldOverride*/set f5(B value) {} 1311 /*severe:INVALID_FIELD_OVERRIDE*/set f5(B value) {}
1310 } 1312 }
1311 1313
1312 class Child2 implements Base { 1314 class Child2 implements Base {
1313 B get f1 => null; 1315 B get f1 => null;
1314 B get f2 => null; 1316 B get f2 => null;
1315 B get f3 => null; 1317 B get f3 => null;
1316 B get f4 => null; 1318 B get f4 => null;
1317 B get f5 => null; 1319 B get f5 => null;
1318 1320
1319 void set f1(A value) {} 1321 void set f1(A value) {}
1320 /*severe:InvalidMethodOverride*/void set f2(C value) {} 1322 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {}
1321 void set f3(value) {} 1323 void set f3(value) {}
1322 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {} 1324 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {}
1323 set f5(B value) {} 1325 set f5(B value) {}
1324 } 1326 }
1325 ''' 1327 '''
1326 }); 1328 });
1327 1329
1328 testChecker('method override', { 1330 testChecker('method override', {
1329 '/main.dart': ''' 1331 '/main.dart': '''
1330 class A {} 1332 class A {}
1331 class B extends A {} 1333 class B extends A {}
1332 class C extends B {} 1334 class C extends B {}
1333 1335
1334 class Base { 1336 class Base {
1335 B m1(B a); 1337 B m1(B a);
1336 B m2(B a); 1338 B m2(B a);
1337 B m3(B a); 1339 B m3(B a);
1338 B m4(B a); 1340 B m4(B a);
1339 B m5(B a); 1341 B m5(B a);
1340 B m6(B a); 1342 B m6(B a);
1341 } 1343 }
1342 1344
1343 class Child extends Base { 1345 class Child extends Base {
1344 /*severe:InvalidMethodOverride*/A m1(A value) {} 1346 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {}
1345 /*severe:InvalidMethodOverride*/C m2(C value) {} 1347 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {}
1346 /*severe:InvalidMethodOverride*/A m3(C value) {} 1348 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) {}
1347 C m4(A value) {} 1349 C m4(A value) {}
1348 m5(value) {} 1350 m5(value) {}
1349 /*severe:InvalidMethodOverride*/dynamic m6(dynamic value) {} 1351 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {}
1350 } 1352 }
1351 ''' 1353 '''
1352 }); 1354 });
1353 1355
1354 testChecker('unary operators', { 1356 testChecker('unary operators', {
1355 '/main.dart': ''' 1357 '/main.dart': '''
1356 class A { 1358 class A {
1357 A operator ~() {} 1359 A operator ~() {}
1358 A operator +(int x) {} 1360 A operator +(int x) {}
1359 A operator -(int x) {} 1361 A operator -(int x) {}
1360 A operator -() {} 1362 A operator -() {}
1361 } 1363 }
1362 1364
1363 foo() => new A(); 1365 foo() => new A();
1364 1366
1365 test() { 1367 test() {
1366 A a = new A(); 1368 A a = new A();
1367 var c = foo(); 1369 var c = foo();
1368 1370
1369 ~a; 1371 ~a;
1370 (/*info:DynamicInvoke*/~d); 1372 (/*info:DYNAMIC_INVOKE*/~d);
1371 1373
1372 !/*severe:StaticTypeError*/a; 1374 !/*severe:STATIC_TYPE_ERROR*/a;
1373 !/*info:DynamicCast*/d; 1375 !/*info:DYNAMIC_CAST*/d;
1374 1376
1375 -a; 1377 -a;
1376 (/*info:DynamicInvoke*/-d); 1378 (/*info:DYNAMIC_INVOKE*/-d);
1377 1379
1378 ++a; 1380 ++a;
1379 --a; 1381 --a;
1380 (/*info:DynamicInvoke*/++d); 1382 (/*info:DYNAMIC_INVOKE*/++d);
1381 (/*info:DynamicInvoke*/--d); 1383 (/*info:DYNAMIC_INVOKE*/--d);
1382 1384
1383 a++; 1385 a++;
1384 a--; 1386 a--;
1385 (/*info:DynamicInvoke*/d++); 1387 (/*info:DYNAMIC_INVOKE*/d++);
1386 (/*info:DynamicInvoke*/d--); 1388 (/*info:DYNAMIC_INVOKE*/d--);
1387 }''' 1389 }'''
1388 }); 1390 });
1389 1391
1390 testChecker('binary and index operators', { 1392 testChecker('binary and index operators', {
1391 '/main.dart': ''' 1393 '/main.dart': '''
1392 class A { 1394 class A {
1393 A operator *(B b) {} 1395 A operator *(B b) {}
1394 A operator /(B b) {} 1396 A operator /(B b) {}
1395 A operator ~/(B b) {} 1397 A operator ~/(B b) {}
1396 A operator %(B b) {} 1398 A operator %(B b) {}
(...skipping 11 matching lines...) Expand all
1408 A operator -(B b) {} 1410 A operator -(B b) {}
1409 } 1411 }
1410 1412
1411 foo() => new A(); 1413 foo() => new A();
1412 1414
1413 test() { 1415 test() {
1414 A a = new A(); 1416 A a = new A();
1415 B b = new B(); 1417 B b = new B();
1416 var c = foo(); 1418 var c = foo();
1417 a = a * b; 1419 a = a * b;
1418 a = a * /*info:DynamicCast*/c; 1420 a = a * /*info:DYNAMIC_CAST*/c;
1419 a = a / b; 1421 a = a / b;
1420 a = a ~/ b; 1422 a = a ~/ b;
1421 a = a % b; 1423 a = a % b;
1422 a = a + b; 1424 a = a + b;
1423 a = a + /*severe:StaticTypeError*/a; 1425 a = a + /*severe:STATIC_TYPE_ERROR*/a;
1424 a = a - b; 1426 a = a - b;
1425 b = /*severe:StaticTypeError*/b - b; 1427 b = /*severe:STATIC_TYPE_ERROR*/b - b;
1426 a = a << b; 1428 a = a << b;
1427 a = a >> b; 1429 a = a >> b;
1428 a = a & b; 1430 a = a & b;
1429 a = a ^ b; 1431 a = a ^ b;
1430 a = a | b; 1432 a = a | b;
1431 c = (/*info:DynamicInvoke*/c + b); 1433 c = (/*info:DYNAMIC_INVOKE*/c + b);
1432 1434
1433 String x = 'hello'; 1435 String x = 'hello';
1434 int y = 42; 1436 int y = 42;
1435 x = x + x; 1437 x = x + x;
1436 x = x + /*info:DynamicCast*/c; 1438 x = x + /*info:DYNAMIC_CAST*/c;
1437 x = x + /*severe:StaticTypeError*/y; 1439 x = x + /*severe:STATIC_TYPE_ERROR*/y;
1438 1440
1439 bool p = true; 1441 bool p = true;
1440 p = p && p; 1442 p = p && p;
1441 p = p && /*info:DynamicCast*/c; 1443 p = p && /*info:DYNAMIC_CAST*/c;
1442 p = (/*info:DynamicCast*/c) && p; 1444 p = (/*info:DYNAMIC_CAST*/c) && p;
1443 p = (/*info:DynamicCast*/c) && /*info:DynamicCast*/c; 1445 p = (/*info:DYNAMIC_CAST*/c) && /*info:DYNAMIC_CAST*/c;
1444 p = (/*severe:StaticTypeError*/y) && p; 1446 p = (/*severe:STATIC_TYPE_ERROR*/y) && p;
1445 p = c == y; 1447 p = c == y;
1446 1448
1447 a = a[b]; 1449 a = a[b];
1448 a = a[/*info:DynamicCast*/c]; 1450 a = a[/*info:DYNAMIC_CAST*/c];
1449 c = (/*info:DynamicInvoke*/c[b]); 1451 c = (/*info:DYNAMIC_INVOKE*/c[b]);
1450 a[/*severe:StaticTypeError*/y]; 1452 a[/*severe:STATIC_TYPE_ERROR*/y];
1451 } 1453 }
1452 ''' 1454 '''
1453 }); 1455 });
1454 1456
1455 testChecker('compound assignments', { 1457 testChecker('compound assignments', {
1456 '/main.dart': ''' 1458 '/main.dart': '''
1457 class A { 1459 class A {
1458 A operator *(B b) {} 1460 A operator *(B b) {}
1459 A operator /(B b) {} 1461 A operator /(B b) {}
1460 A operator ~/(B b) {} 1462 A operator ~/(B b) {}
(...skipping 15 matching lines...) Expand all
1476 1478
1477 class D { 1479 class D {
1478 D operator +(D d) {} 1480 D operator +(D d) {}
1479 } 1481 }
1480 1482
1481 foo() => new A(); 1483 foo() => new A();
1482 1484
1483 test() { 1485 test() {
1484 int x = 0; 1486 int x = 0;
1485 x += 5; 1487 x += 5;
1486 (/*severe:StaticTypeError*/x += 3.14); 1488 (/*severe:STATIC_TYPE_ERROR*/x += 3.14);
1487 1489
1488 double y = 0.0; 1490 double y = 0.0;
1489 y += 5; 1491 y += 5;
1490 y += 3.14; 1492 y += 3.14;
1491 1493
1492 num z = 0; 1494 num z = 0;
1493 z += 5; 1495 z += 5;
1494 z += 3.14; 1496 z += 3.14;
1495 1497
1496 x = /*info:DownCastImplicit*/x + z; 1498 x = /*info:DOWN_CAST_IMPLICIT*/x + z;
1497 x += /*info:DownCastImplicit*/z; 1499 x += /*info:DOWN_CAST_IMPLICIT*/z;
1498 y = /*info:DownCastImplicit*/y + z; 1500 y = /*info:DOWN_CAST_IMPLICIT*/y + z;
1499 y += /*info:DownCastImplicit*/z; 1501 y += /*info:DOWN_CAST_IMPLICIT*/z;
1500 1502
1501 dynamic w = 42; 1503 dynamic w = 42;
1502 x += /*info:DynamicCast*/w; 1504 x += /*info:DYNAMIC_CAST*/w;
1503 y += /*info:DynamicCast*/w; 1505 y += /*info:DYNAMIC_CAST*/w;
1504 z += /*info:DynamicCast*/w; 1506 z += /*info:DYNAMIC_CAST*/w;
1505 1507
1506 A a = new A(); 1508 A a = new A();
1507 B b = new B(); 1509 B b = new B();
1508 var c = foo(); 1510 var c = foo();
1509 a = a * b; 1511 a = a * b;
1510 a *= b; 1512 a *= b;
1511 a *= /*info:DynamicCast*/c; 1513 a *= /*info:DYNAMIC_CAST*/c;
1512 a /= b; 1514 a /= b;
1513 a ~/= b; 1515 a ~/= b;
1514 a %= b; 1516 a %= b;
1515 a += b; 1517 a += b;
1516 a += /*severe:StaticTypeError*/a; 1518 a += /*severe:STATIC_TYPE_ERROR*/a;
1517 a -= b; 1519 a -= b;
1518 (/*severe:StaticTypeError*/b -= b); 1520 (/*severe:STATIC_TYPE_ERROR*/b -= b);
1519 a <<= b; 1521 a <<= b;
1520 a >>= b; 1522 a >>= b;
1521 a &= b; 1523 a &= b;
1522 a ^= b; 1524 a ^= b;
1523 a |= b; 1525 a |= b;
1524 (/*info:DynamicInvoke*/c += b); 1526 (/*info:DYNAMIC_INVOKE*/c += b);
1525 1527
1526 var d = new D(); 1528 var d = new D();
1527 a[b] += d; 1529 a[b] += d;
1528 a[/*info:DynamicCast*/c] += d; 1530 a[/*info:DYNAMIC_CAST*/c] += d;
1529 a[/*severe:StaticTypeError*/z] += d; 1531 a[/*severe:STATIC_TYPE_ERROR*/z] += d;
1530 a[b] += /*info:DynamicCast*/c; 1532 a[b] += /*info:DYNAMIC_CAST*/c;
1531 a[b] += /*severe:StaticTypeError*/z; 1533 a[b] += /*severe:STATIC_TYPE_ERROR*/z;
1532 (/*info:DynamicInvoke*/(/*info:DynamicInvoke*/c[b]) += d); 1534 (/*info:DYNAMIC_INVOKE*/(/*info:DYNAMIC_INVOKE*/c[b]) += d);
1533 } 1535 }
1534 ''' 1536 '''
1535 }); 1537 });
1536 1538
1537 testChecker('super call placement', { 1539 testChecker('super call placement', {
1538 '/main.dart': ''' 1540 '/main.dart': '''
1539 class Base { 1541 class Base {
1540 var x; 1542 var x;
1541 Base() : x = print('Base.1') { print('Base.2'); } 1543 Base() : x = print('Base.1') { print('Base.2'); }
1542 } 1544 }
1543 1545
1544 class Derived extends Base { 1546 class Derived extends Base {
1545 var y, z; 1547 var y, z;
1546 Derived() 1548 Derived()
1547 : y = print('Derived.1'), 1549 : y = print('Derived.1'),
1548 /*severe:InvalidSuperInvocation*/super(), 1550 /*severe:INVALID_SUPER_INVOCATION*/super(),
1549 z = print('Derived.2') { 1551 z = print('Derived.2') {
1550 print('Derived.3'); 1552 print('Derived.3');
1551 } 1553 }
1552 } 1554 }
1553 1555
1554 class Valid extends Base { 1556 class Valid extends Base {
1555 var y, z; 1557 var y, z;
1556 Valid() 1558 Valid()
1557 : y = print('Valid.1'), 1559 : y = print('Valid.1'),
1558 z = print('Valid.2'), 1560 z = print('Valid.2'),
1559 super() { 1561 super() {
1560 print('Valid.3'); 1562 print('Valid.3');
1561 } 1563 }
1562 } 1564 }
1563 1565
1564 class AlsoValid extends Base { 1566 class AlsoValid extends Base {
1565 AlsoValid() : super(); 1567 AlsoValid() : super();
1566 } 1568 }
1567 1569
1568 main() => new Derived(); 1570 main() => new Derived();
1569 ''' 1571 '''
1570 }); 1572 });
1571 1573
1572 testChecker('for loop variable', { 1574 testChecker('for loop variable', {
1573 '/main.dart': ''' 1575 '/main.dart': '''
1574 foo() { 1576 foo() {
1575 for (int i = 0; i < 10; i++) { 1577 for (int i = 0; i < 10; i++) {
1576 i = /*severe:StaticTypeError*/"hi"; 1578 i = /*severe:STATIC_TYPE_ERROR*/"hi";
1577 } 1579 }
1578 } 1580 }
1579 bar() { 1581 bar() {
1580 for (var i = 0; i < 10; i++) { 1582 for (var i = 0; i < 10; i++) {
1581 int j = i + 1; 1583 int j = i + 1;
1582 } 1584 }
1583 } 1585 }
1584 ''' 1586 '''
1585 }); 1587 });
1586 1588
1587 group('invalid overrides', () { 1589 group('invalid overrides', () {
1588 testChecker('child override', { 1590 testChecker('child override', {
1589 '/main.dart': ''' 1591 '/main.dart': '''
1590 class A {} 1592 class A {}
1591 class B {} 1593 class B {}
1592 1594
1593 class Base { 1595 class Base {
1594 A f; 1596 A f;
1595 } 1597 }
1596 1598
1597 class T1 extends Base { 1599 class T1 extends Base {
1598 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/B get f => null; 1600 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B get f => null;
1599 } 1601 }
1600 1602
1601 class T2 extends Base { 1603 class T2 extends Base {
1602 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/set f( B b) => null; 1604 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/se t f(B b) => null;
1603 } 1605 }
1604 1606
1605 class T3 extends Base { 1607 class T3 extends Base {
1606 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride*/final B f; 1608 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/fi nal B f;
1607 } 1609 }
1608 class T4 extends Base { 1610 class T4 extends Base {
1609 // two: one for the getter one for the setter. 1611 // two: one for the getter one for the setter.
1610 /*severe:InvalidFieldOverride,severe:InvalidMethodOverride,severe: InvalidMethodOverride*/B f; 1612 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sev ere:INVALID_METHOD_OVERRIDE*/B f;
1611 } 1613 }
1612 1614
1613 class T5 implements Base { 1615 class T5 implements Base {
1614 /*severe:InvalidMethodOverride*/B get f => null; 1616 /*severe:INVALID_METHOD_OVERRIDE*/B get f => null;
1615 } 1617 }
1616 1618
1617 class T6 implements Base { 1619 class T6 implements Base {
1618 /*severe:InvalidMethodOverride*/set f(B b) => null; 1620 /*severe:INVALID_METHOD_OVERRIDE*/set f(B b) => null;
1619 } 1621 }
1620 1622
1621 class T7 implements Base { 1623 class T7 implements Base {
1622 /*severe:InvalidMethodOverride*/final B f; 1624 /*severe:INVALID_METHOD_OVERRIDE*/final B f;
1623 } 1625 }
1624 class T8 implements Base { 1626 class T8 implements Base {
1625 // two: one for the getter one for the setter. 1627 // two: one for the getter one for the setter.
1626 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/B f; 1628 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B f;
1627 } 1629 }
1628 ''' 1630 '''
1629 }); 1631 });
1630 1632
1631 testChecker('child override 2', { 1633 testChecker('child override 2', {
1632 '/main.dart': ''' 1634 '/main.dart': '''
1633 class A {} 1635 class A {}
1634 class B {} 1636 class B {}
1635 1637
1636 class Base { 1638 class Base {
1637 m(A a) {} 1639 m(A a) {}
1638 } 1640 }
1639 1641
1640 class Test extends Base { 1642 class Test extends Base {
1641 /*severe:InvalidMethodOverride*/m(B a) {} 1643 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1642 } 1644 }
1643 ''' 1645 '''
1644 }); 1646 });
1645 testChecker('grandchild override', { 1647 testChecker('grandchild override', {
1646 '/main.dart': ''' 1648 '/main.dart': '''
1647 class A {} 1649 class A {}
1648 class B {} 1650 class B {}
1649 1651
1650 class Grandparent { 1652 class Grandparent {
1651 m(A a) {} 1653 m(A a) {}
1652 int x; 1654 int x;
1653 } 1655 }
1654 class Parent extends Grandparent { 1656 class Parent extends Grandparent {
1655 } 1657 }
1656 1658
1657 class Test extends Parent { 1659 class Test extends Parent {
1658 /*severe:InvalidMethodOverride*/m(B a) {} 1660 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1659 /*severe:InvalidFieldOverride*/int x; 1661 /*severe:INVALID_FIELD_OVERRIDE*/int x;
1660 } 1662 }
1661 ''' 1663 '''
1662 }); 1664 });
1663 1665
1664 testChecker('double override', { 1666 testChecker('double override', {
1665 '/main.dart': ''' 1667 '/main.dart': '''
1666 class A {} 1668 class A {}
1667 class B {} 1669 class B {}
1668 1670
1669 class Grandparent { 1671 class Grandparent {
1670 m(A a) {} 1672 m(A a) {}
1671 } 1673 }
1672 class Parent extends Grandparent { 1674 class Parent extends Grandparent {
1673 m(A a) {} 1675 m(A a) {}
1674 } 1676 }
1675 1677
1676 class Test extends Parent { 1678 class Test extends Parent {
1677 // Reported only once 1679 // Reported only once
1678 /*severe:InvalidMethodOverride*/m(B a) {} 1680 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1679 } 1681 }
1680 ''' 1682 '''
1681 }); 1683 });
1682 1684
1683 testChecker('double override 2', { 1685 testChecker('double override 2', {
1684 '/main.dart': ''' 1686 '/main.dart': '''
1685 class A {} 1687 class A {}
1686 class B {} 1688 class B {}
1687 1689
1688 class Grandparent { 1690 class Grandparent {
1689 m(A a) {} 1691 m(A a) {}
1690 } 1692 }
1691 class Parent extends Grandparent { 1693 class Parent extends Grandparent {
1692 /*severe:InvalidMethodOverride*/m(B a) {} 1694 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1693 } 1695 }
1694 1696
1695 class Test extends Parent { 1697 class Test extends Parent {
1696 m(B a) {} 1698 m(B a) {}
1697 } 1699 }
1698 ''' 1700 '''
1699 }); 1701 });
1700 1702
1701 testChecker('mixin override to base', { 1703 testChecker('mixin override to base', {
1702 '/main.dart': ''' 1704 '/main.dart': '''
1703 class A {} 1705 class A {}
1704 class B {} 1706 class B {}
1705 1707
1706 class Base { 1708 class Base {
1707 m(A a) {} 1709 m(A a) {}
1708 int x; 1710 int x;
1709 } 1711 }
1710 1712
1711 class M1 { 1713 class M1 {
1712 m(B a) {} 1714 m(B a) {}
1713 } 1715 }
1714 1716
1715 class M2 { 1717 class M2 {
1716 int x; 1718 int x;
1717 } 1719 }
1718 1720
1719 class T1 extends Base with /*severe:InvalidMethodOverride*/M1 {} 1721 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1 {}
1720 class T2 extends Base with /*severe:InvalidMethodOverride*/M1, /*sev ere:InvalidFieldOverride*/M2 {} 1722 class T2 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1, /*s evere:INVALID_FIELD_OVERRIDE*/M2 {}
1721 class T3 extends Base with /*severe:InvalidFieldOverride*/M2, /*seve re:InvalidMethodOverride*/M1 {} 1723 class T3 extends Base with /*severe:INVALID_FIELD_OVERRIDE*/M2, /*se vere:INVALID_METHOD_OVERRIDE*/M1 {}
1722 ''' 1724 '''
1723 }); 1725 });
1724 1726
1725 testChecker('mixin override to mixin', { 1727 testChecker('mixin override to mixin', {
1726 '/main.dart': ''' 1728 '/main.dart': '''
1727 class A {} 1729 class A {}
1728 class B {} 1730 class B {}
1729 1731
1730 class Base { 1732 class Base {
1731 } 1733 }
1732 1734
1733 class M1 { 1735 class M1 {
1734 m(B a) {} 1736 m(B a) {}
1735 int x; 1737 int x;
1736 } 1738 }
1737 1739
1738 class M2 { 1740 class M2 {
1739 m(A a) {} 1741 m(A a) {}
1740 int x; 1742 int x;
1741 } 1743 }
1742 1744
1743 class T1 extends Base with M1, /*severe:InvalidMethodOverride,severe :InvalidFieldOverride*/M2 {} 1745 class T1 extends Base with M1, /*severe:INVALID_METHOD_OVERRIDE,seve re:INVALID_FIELD_OVERRIDE*/M2 {}
1744 ''' 1746 '''
1745 }); 1747 });
1746 1748
1747 // This is a regression test for a bug in an earlier implementation were 1749 // This is a regression test for a bug in an earlier implementation were
1748 // names were hiding errors if the first mixin override looked correct, 1750 // names were hiding errors if the first mixin override looked correct,
1749 // but subsequent ones did not. 1751 // but subsequent ones did not.
1750 testChecker('no duplicate mixin override', { 1752 testChecker('no duplicate mixin override', {
1751 '/main.dart': ''' 1753 '/main.dart': '''
1752 class A {} 1754 class A {}
1753 class B {} 1755 class B {}
1754 1756
1755 class Base { 1757 class Base {
1756 m(A a) {} 1758 m(A a) {}
1757 } 1759 }
1758 1760
1759 class M1 { 1761 class M1 {
1760 m(A a) {} 1762 m(A a) {}
1761 } 1763 }
1762 1764
1763 class M2 { 1765 class M2 {
1764 m(B a) {} 1766 m(B a) {}
1765 } 1767 }
1766 1768
1767 class M3 { 1769 class M3 {
1768 m(B a) {} 1770 m(B a) {}
1769 } 1771 }
1770 1772
1771 class T1 extends Base 1773 class T1 extends Base
1772 with M1, /*severe:InvalidMethodOverride*/M2, M3 {} 1774 with M1, /*severe:INVALID_METHOD_OVERRIDE*/M2, M3 {}
1773 ''' 1775 '''
1774 }); 1776 });
1775 1777
1776 testChecker('class override of interface', { 1778 testChecker('class override of interface', {
1777 '/main.dart': ''' 1779 '/main.dart': '''
1778 class A {} 1780 class A {}
1779 class B {} 1781 class B {}
1780 1782
1781 abstract class I { 1783 abstract class I {
1782 m(A a); 1784 m(A a);
1783 } 1785 }
1784 1786
1785 class T1 implements I { 1787 class T1 implements I {
1786 /*severe:InvalidMethodOverride*/m(B a) {} 1788 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1787 } 1789 }
1788 ''' 1790 '''
1789 }); 1791 });
1790 1792
1791 testChecker('base class override to child interface', { 1793 testChecker('base class override to child interface', {
1792 '/main.dart': ''' 1794 '/main.dart': '''
1793 class A {} 1795 class A {}
1794 class B {} 1796 class B {}
1795 1797
1796 abstract class I { 1798 abstract class I {
1797 m(A a); 1799 m(A a);
1798 } 1800 }
1799 1801
1800 class Base { 1802 class Base {
1801 m(B a) {} 1803 m(B a) {}
1802 } 1804 }
1803 1805
1804 1806
1805 class T1 /*severe:InvalidMethodOverride*/extends Base implements I { 1807 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I {
1806 } 1808 }
1807 ''' 1809 '''
1808 }); 1810 });
1809 1811
1810 testChecker('mixin override of interface', { 1812 testChecker('mixin override of interface', {
1811 '/main.dart': ''' 1813 '/main.dart': '''
1812 class A {} 1814 class A {}
1813 class B {} 1815 class B {}
1814 1816
1815 abstract class I { 1817 abstract class I {
1816 m(A a); 1818 m(A a);
1817 } 1819 }
1818 1820
1819 class M { 1821 class M {
1820 m(B a) {} 1822 m(B a) {}
1821 } 1823 }
1822 1824
1823 class T1 extends Object with /*severe:InvalidMethodOverride*/M 1825 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
1824 implements I {} 1826 implements I {}
1825 ''' 1827 '''
1826 }); 1828 });
1827 1829
1828 // This is a case were it is incorrect to say that the base class 1830 // This is a case were it is incorrect to say that the base class
1829 // incorrectly overrides the interface. 1831 // incorrectly overrides the interface.
1830 testChecker( 1832 testChecker(
1831 'no errors if subclass correctly overrides base and interface', { 1833 'no errors if subclass correctly overrides base and interface', {
1832 '/main.dart': ''' 1834 '/main.dart': '''
1833 class A {} 1835 class A {}
1834 class B {} 1836 class B {}
1835 1837
1836 class Base { 1838 class Base {
1837 m(A a) {} 1839 m(A a) {}
1838 } 1840 }
1839 1841
1840 class I1 { 1842 class I1 {
1841 m(B a) {} 1843 m(B a) {}
1842 } 1844 }
1843 1845
1844 class T1 /*severe:InvalidMethodOverride*/extends Base 1846 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
1845 implements I1 {} 1847 implements I1 {}
1846 1848
1847 class T2 extends Base implements I1 { 1849 class T2 extends Base implements I1 {
1848 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a ) {} 1850 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {}
1849 } 1851 }
1850 1852
1851 class T3 extends Object with /*severe:InvalidMethodOverride*/Base 1853 class T3 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base
1852 implements I1 {} 1854 implements I1 {}
1853 1855
1854 class T4 extends Object with Base implements I1 { 1856 class T4 extends Object with Base implements I1 {
1855 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a ) {} 1857 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {}
1856 } 1858 }
1857 ''' 1859 '''
1858 }); 1860 });
1859 }); 1861 });
1860 1862
1861 group('class override of grand interface', () { 1863 group('class override of grand interface', () {
1862 testChecker('interface of interface of child', { 1864 testChecker('interface of interface of child', {
1863 '/main.dart': ''' 1865 '/main.dart': '''
1864 class A {} 1866 class A {}
1865 class B {} 1867 class B {}
1866 1868
1867 abstract class I1 { 1869 abstract class I1 {
1868 m(A a); 1870 m(A a);
1869 } 1871 }
1870 abstract class I2 implements I1 {} 1872 abstract class I2 implements I1 {}
1871 1873
1872 class T1 implements I2 { 1874 class T1 implements I2 {
1873 /*severe:InvalidMethodOverride*/m(B a) {} 1875 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1874 } 1876 }
1875 ''' 1877 '''
1876 }); 1878 });
1877 testChecker('superclass of interface of child', { 1879 testChecker('superclass of interface of child', {
1878 '/main.dart': ''' 1880 '/main.dart': '''
1879 class A {} 1881 class A {}
1880 class B {} 1882 class B {}
1881 1883
1882 abstract class I1 { 1884 abstract class I1 {
1883 m(A a); 1885 m(A a);
1884 } 1886 }
1885 abstract class I2 extends I1 {} 1887 abstract class I2 extends I1 {}
1886 1888
1887 class T1 implements I2 { 1889 class T1 implements I2 {
1888 /*severe:InvalidMethodOverride*/m(B a) {} 1890 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1889 } 1891 }
1890 ''' 1892 '''
1891 }); 1893 });
1892 testChecker('mixin of interface of child', { 1894 testChecker('mixin of interface of child', {
1893 '/main.dart': ''' 1895 '/main.dart': '''
1894 class A {} 1896 class A {}
1895 class B {} 1897 class B {}
1896 1898
1897 abstract class M1 { 1899 abstract class M1 {
1898 m(A a); 1900 m(A a);
1899 } 1901 }
1900 abstract class I2 extends Object with M1 {} 1902 abstract class I2 extends Object with M1 {}
1901 1903
1902 class T1 implements I2 { 1904 class T1 implements I2 {
1903 /*severe:InvalidMethodOverride*/m(B a) {} 1905 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1904 } 1906 }
1905 ''' 1907 '''
1906 }); 1908 });
1907 testChecker('interface of abstract superclass', { 1909 testChecker('interface of abstract superclass', {
1908 '/main.dart': ''' 1910 '/main.dart': '''
1909 class A {} 1911 class A {}
1910 class B {} 1912 class B {}
1911 1913
1912 abstract class I1 { 1914 abstract class I1 {
1913 m(A a); 1915 m(A a);
1914 } 1916 }
1915 abstract class Base implements I1 {} 1917 abstract class Base implements I1 {}
1916 1918
1917 class T1 extends Base { 1919 class T1 extends Base {
1918 /*severe:InvalidMethodOverride*/m(B a) {} 1920 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1919 } 1921 }
1920 ''' 1922 '''
1921 }); 1923 });
1922 testChecker('interface of concrete superclass', { 1924 testChecker('interface of concrete superclass', {
1923 '/main.dart': ''' 1925 '/main.dart': '''
1924 class A {} 1926 class A {}
1925 class B {} 1927 class B {}
1926 1928
1927 abstract class I1 { 1929 abstract class I1 {
1928 m(A a); 1930 m(A a);
(...skipping 21 matching lines...) Expand all
1950 1952
1951 abstract class I1 { 1953 abstract class I1 {
1952 m(A a); 1954 m(A a);
1953 } 1955 }
1954 abstract class I2 implements I1 {} 1956 abstract class I2 implements I1 {}
1955 1957
1956 class M { 1958 class M {
1957 m(B a) {} 1959 m(B a) {}
1958 } 1960 }
1959 1961
1960 class T1 extends Object with /*severe:InvalidMethodOverride*/M 1962 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
1961 implements I2 { 1963 implements I2 {
1962 } 1964 }
1963 ''' 1965 '''
1964 }); 1966 });
1965 testChecker('superclass of interface of child', { 1967 testChecker('superclass of interface of child', {
1966 '/main.dart': ''' 1968 '/main.dart': '''
1967 class A {} 1969 class A {}
1968 class B {} 1970 class B {}
1969 1971
1970 abstract class I1 { 1972 abstract class I1 {
1971 m(A a); 1973 m(A a);
1972 } 1974 }
1973 abstract class I2 extends I1 {} 1975 abstract class I2 extends I1 {}
1974 1976
1975 class M { 1977 class M {
1976 m(B a) {} 1978 m(B a) {}
1977 } 1979 }
1978 1980
1979 class T1 extends Object with /*severe:InvalidMethodOverride*/M 1981 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
1980 implements I2 { 1982 implements I2 {
1981 } 1983 }
1982 ''' 1984 '''
1983 }); 1985 });
1984 testChecker('mixin of interface of child', { 1986 testChecker('mixin of interface of child', {
1985 '/main.dart': ''' 1987 '/main.dart': '''
1986 class A {} 1988 class A {}
1987 class B {} 1989 class B {}
1988 1990
1989 abstract class M1 { 1991 abstract class M1 {
1990 m(A a); 1992 m(A a);
1991 } 1993 }
1992 abstract class I2 extends Object with M1 {} 1994 abstract class I2 extends Object with M1 {}
1993 1995
1994 class M { 1996 class M {
1995 m(B a) {} 1997 m(B a) {}
1996 } 1998 }
1997 1999
1998 class T1 extends Object with /*severe:InvalidMethodOverride*/M 2000 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
1999 implements I2 { 2001 implements I2 {
2000 } 2002 }
2001 ''' 2003 '''
2002 }); 2004 });
2003 testChecker('interface of abstract superclass', { 2005 testChecker('interface of abstract superclass', {
2004 '/main.dart': ''' 2006 '/main.dart': '''
2005 class A {} 2007 class A {}
2006 class B {} 2008 class B {}
2007 2009
2008 abstract class I1 { 2010 abstract class I1 {
2009 m(A a); 2011 m(A a);
2010 } 2012 }
2011 abstract class Base implements I1 {} 2013 abstract class Base implements I1 {}
2012 2014
2013 class M { 2015 class M {
2014 m(B a) {} 2016 m(B a) {}
2015 } 2017 }
2016 2018
2017 class T1 extends Base with /*severe:InvalidMethodOverride*/M { 2019 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M {
2018 } 2020 }
2019 ''' 2021 '''
2020 }); 2022 });
2021 testChecker('interface of concrete superclass', { 2023 testChecker('interface of concrete superclass', {
2022 '/main.dart': ''' 2024 '/main.dart': '''
2023 class A {} 2025 class A {}
2024 class B {} 2026 class B {}
2025 2027
2026 abstract class I1 { 2028 abstract class I1 {
2027 m(A a); 2029 m(A a);
(...skipping 21 matching lines...) Expand all
2049 2051
2050 abstract class I1 { 2052 abstract class I1 {
2051 m(A a); 2053 m(A a);
2052 } 2054 }
2053 abstract class I2 implements I1 {} 2055 abstract class I2 implements I1 {}
2054 2056
2055 class Base { 2057 class Base {
2056 m(B a) {} 2058 m(B a) {}
2057 } 2059 }
2058 2060
2059 class T1 /*severe:InvalidMethodOverride*/extends Base 2061 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2060 implements I2 { 2062 implements I2 {
2061 } 2063 }
2062 ''' 2064 '''
2063 }); 2065 });
2064 testChecker('superclass of interface of child', { 2066 testChecker('superclass of interface of child', {
2065 '/main.dart': ''' 2067 '/main.dart': '''
2066 class A {} 2068 class A {}
2067 class B {} 2069 class B {}
2068 2070
2069 abstract class I1 { 2071 abstract class I1 {
2070 m(A a); 2072 m(A a);
2071 } 2073 }
2072 abstract class I2 extends I1 {} 2074 abstract class I2 extends I1 {}
2073 2075
2074 class Base { 2076 class Base {
2075 m(B a) {} 2077 m(B a) {}
2076 } 2078 }
2077 2079
2078 class T1 /*severe:InvalidMethodOverride*/extends Base 2080 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2079 implements I2 { 2081 implements I2 {
2080 } 2082 }
2081 ''' 2083 '''
2082 }); 2084 });
2083 testChecker('mixin of interface of child', { 2085 testChecker('mixin of interface of child', {
2084 '/main.dart': ''' 2086 '/main.dart': '''
2085 class A {} 2087 class A {}
2086 class B {} 2088 class B {}
2087 2089
2088 abstract class M1 { 2090 abstract class M1 {
2089 m(A a); 2091 m(A a);
2090 } 2092 }
2091 abstract class I2 extends Object with M1 {} 2093 abstract class I2 extends Object with M1 {}
2092 2094
2093 class Base { 2095 class Base {
2094 m(B a) {} 2096 m(B a) {}
2095 } 2097 }
2096 2098
2097 class T1 /*severe:InvalidMethodOverride*/extends Base 2099 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2098 implements I2 { 2100 implements I2 {
2099 } 2101 }
2100 ''' 2102 '''
2101 }); 2103 });
2102 testChecker('interface of abstract superclass', { 2104 testChecker('interface of abstract superclass', {
2103 '/main.dart': ''' 2105 '/main.dart': '''
2104 class A {} 2106 class A {}
2105 class B {} 2107 class B {}
2106 2108
2107 abstract class I1 { 2109 abstract class I1 {
2108 m(A a); 2110 m(A a);
2109 } 2111 }
2110 2112
2111 abstract class Base implements I1 { 2113 abstract class Base implements I1 {
2112 /*severe:InvalidMethodOverride*/m(B a) {} 2114 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2113 } 2115 }
2114 2116
2115 class T1 extends Base { 2117 class T1 extends Base {
2116 // we consider the base class incomplete because it is 2118 // we consider the base class incomplete because it is
2117 // abstract, so we report the error here too. 2119 // abstract, so we report the error here too.
2118 // TODO(sigmund): consider tracking overrides in a fine-grain 2120 // TODO(sigmund): consider tracking overrides in a fine-grain
2119 // manner, then this and the double-overrides would not be 2121 // manner, then this and the double-overrides would not be
2120 // reported. 2122 // reported.
2121 /*severe:InvalidMethodOverride*/m(B a) {} 2123 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2122 } 2124 }
2123 ''' 2125 '''
2124 }); 2126 });
2125 testChecker('interface of concrete superclass', { 2127 testChecker('interface of concrete superclass', {
2126 '/main.dart': ''' 2128 '/main.dart': '''
2127 class A {} 2129 class A {}
2128 class B {} 2130 class B {}
2129 2131
2130 abstract class I1 { 2132 abstract class I1 {
2131 m(A a); 2133 m(A a);
2132 } 2134 }
2133 2135
2134 class Base implements I1 { 2136 class Base implements I1 {
2135 /*severe:InvalidMethodOverride*/m(B a) {} 2137 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2136 } 2138 }
2137 2139
2138 class T1 extends Base { 2140 class T1 extends Base {
2139 m(B a) {} 2141 m(B a) {}
2140 } 2142 }
2141 ''' 2143 '''
2142 }); 2144 });
2143 }); 2145 });
2144 2146
2145 group('no duplicate reports from overriding interfaces', () { 2147 group('no duplicate reports from overriding interfaces', () {
2146 testChecker('type overrides same method in multiple interfaces', { 2148 testChecker('type overrides same method in multiple interfaces', {
2147 '/main.dart': ''' 2149 '/main.dart': '''
2148 class A {} 2150 class A {}
2149 class B {} 2151 class B {}
2150 2152
2151 abstract class I1 { 2153 abstract class I1 {
2152 m(A a); 2154 m(A a);
2153 } 2155 }
2154 abstract class I2 implements I1 { 2156 abstract class I2 implements I1 {
2155 m(A a); 2157 m(A a);
2156 } 2158 }
2157 2159
2158 class Base { 2160 class Base {
2159 } 2161 }
2160 2162
2161 class T1 implements I2 { 2163 class T1 implements I2 {
2162 /*severe:InvalidMethodOverride*/m(B a) {} 2164 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2163 } 2165 }
2164 ''' 2166 '''
2165 }); 2167 });
2166 2168
2167 testChecker('type and base type override same method in interface', { 2169 testChecker('type and base type override same method in interface', {
2168 '/main.dart': ''' 2170 '/main.dart': '''
2169 class A {} 2171 class A {}
2170 class B {} 2172 class B {}
2171 2173
2172 abstract class I1 { 2174 abstract class I1 {
2173 m(A a); 2175 m(A a);
2174 } 2176 }
2175 2177
2176 class Base { 2178 class Base {
2177 m(B a); 2179 m(B a);
2178 } 2180 }
2179 2181
2180 // Note: no error reported in `extends Base` to avoid duplicating 2182 // Note: no error reported in `extends Base` to avoid duplicating
2181 // the error in T1. 2183 // the error in T1.
2182 class T1 extends Base implements I1 { 2184 class T1 extends Base implements I1 {
2183 /*severe:InvalidMethodOverride*/m(B a) {} 2185 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2184 } 2186 }
2185 2187
2186 // If there is no error in the class, we do report the error at 2188 // If there is no error in the class, we do report the error at
2187 // the base class: 2189 // the base class:
2188 class T2 /*severe:InvalidMethodOverride*/extends Base 2190 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2189 implements I1 { 2191 implements I1 {
2190 } 2192 }
2191 ''' 2193 '''
2192 }); 2194 });
2193 2195
2194 testChecker('type and mixin override same method in interface', { 2196 testChecker('type and mixin override same method in interface', {
2195 '/main.dart': ''' 2197 '/main.dart': '''
2196 class A {} 2198 class A {}
2197 class B {} 2199 class B {}
2198 2200
2199 abstract class I1 { 2201 abstract class I1 {
2200 m(A a); 2202 m(A a);
2201 } 2203 }
2202 2204
2203 class M { 2205 class M {
2204 m(B a); 2206 m(B a);
2205 } 2207 }
2206 2208
2207 class T1 extends Object with M implements I1 { 2209 class T1 extends Object with M implements I1 {
2208 /*severe:InvalidMethodOverride*/m(B a) {} 2210 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2209 } 2211 }
2210 2212
2211 class T2 extends Object with /*severe:InvalidMethodOverride*/M 2213 class T2 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2212 implements I1 { 2214 implements I1 {
2213 } 2215 }
2214 ''' 2216 '''
2215 }); 2217 });
2216 2218
2217 testChecker('two grand types override same method in interface', { 2219 testChecker('two grand types override same method in interface', {
2218 '/main.dart': ''' 2220 '/main.dart': '''
2219 class A {} 2221 class A {}
2220 class B {} 2222 class B {}
2221 2223
2222 abstract class I1 { 2224 abstract class I1 {
2223 m(A a); 2225 m(A a);
2224 } 2226 }
2225 2227
2226 class Grandparent { 2228 class Grandparent {
2227 m(B a) {} 2229 m(B a) {}
2228 } 2230 }
2229 2231
2230 class Parent1 extends Grandparent { 2232 class Parent1 extends Grandparent {
2231 m(B a) {} 2233 m(B a) {}
2232 } 2234 }
2233 class Parent2 extends Grandparent { 2235 class Parent2 extends Grandparent {
2234 } 2236 }
2235 2237
2236 // Note: otherwise both errors would be reported on this line 2238 // Note: otherwise both errors would be reported on this line
2237 class T1 /*severe:InvalidMethodOverride*/extends Parent1 2239 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent1
2238 implements I1 { 2240 implements I1 {
2239 } 2241 }
2240 class T2 /*severe:InvalidMethodOverride*/extends Parent2 2242 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent2
2241 implements I1 { 2243 implements I1 {
2242 } 2244 }
2243 ''' 2245 '''
2244 }); 2246 });
2245 2247
2246 testChecker('two mixins override same method in interface', { 2248 testChecker('two mixins override same method in interface', {
2247 '/main.dart': ''' 2249 '/main.dart': '''
2248 class A {} 2250 class A {}
2249 class B {} 2251 class B {}
2250 2252
2251 abstract class I1 { 2253 abstract class I1 {
2252 m(A a); 2254 m(A a);
2253 } 2255 }
2254 2256
2255 class M1 { 2257 class M1 {
2256 m(B a) {} 2258 m(B a) {}
2257 } 2259 }
2258 2260
2259 class M2 { 2261 class M2 {
2260 m(B a) {} 2262 m(B a) {}
2261 } 2263 }
2262 2264
2263 // Here we want to report both, because the error location is 2265 // Here we want to report both, because the error location is
2264 // different. 2266 // different.
2265 // TODO(sigmund): should we merge these as well? 2267 // TODO(sigmund): should we merge these as well?
2266 class T1 extends Object 2268 class T1 extends Object
2267 with /*severe:InvalidMethodOverride*/M1 2269 with /*severe:INVALID_METHOD_OVERRIDE*/M1
2268 with /*severe:InvalidMethodOverride*/M2 2270 with /*severe:INVALID_METHOD_OVERRIDE*/M2
2269 implements I1 { 2271 implements I1 {
2270 } 2272 }
2271 ''' 2273 '''
2272 }); 2274 });
2273 2275
2274 testChecker('base type and mixin override same method in interface', { 2276 testChecker('base type and mixin override same method in interface', {
2275 '/main.dart': ''' 2277 '/main.dart': '''
2276 class A {} 2278 class A {}
2277 class B {} 2279 class B {}
2278 2280
2279 abstract class I1 { 2281 abstract class I1 {
2280 m(A a); 2282 m(A a);
2281 } 2283 }
2282 2284
2283 class Base { 2285 class Base {
2284 m(B a) {} 2286 m(B a) {}
2285 } 2287 }
2286 2288
2287 class M { 2289 class M {
2288 m(B a) {} 2290 m(B a) {}
2289 } 2291 }
2290 2292
2291 // Here we want to report both, because the error location is 2293 // Here we want to report both, because the error location is
2292 // different. 2294 // different.
2293 // TODO(sigmund): should we merge these as well? 2295 // TODO(sigmund): should we merge these as well?
2294 class T1 /*severe:InvalidMethodOverride*/extends Base 2296 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2295 with /*severe:InvalidMethodOverride*/M 2297 with /*severe:INVALID_METHOD_OVERRIDE*/M
2296 implements I1 { 2298 implements I1 {
2297 } 2299 }
2298 ''' 2300 '''
2299 }); 2301 });
2300 }); 2302 });
2301 2303
2302 testChecker('invalid runtime checks', { 2304 testChecker('invalid runtime checks', {
2303 '/main.dart': ''' 2305 '/main.dart': '''
2304 typedef int I2I(int x); 2306 typedef int I2I(int x);
2305 typedef int D2I(x); 2307 typedef int D2I(x);
2306 typedef int II2I(int x, int y); 2308 typedef int II2I(int x, int y);
2307 typedef int DI2I(x, int y); 2309 typedef int DI2I(x, int y);
2308 typedef int ID2I(int x, y); 2310 typedef int ID2I(int x, y);
2309 typedef int DD2I(x, y); 2311 typedef int DD2I(x, y);
2310 2312
2311 typedef I2D(int x); 2313 typedef I2D(int x);
2312 typedef D2D(x); 2314 typedef D2D(x);
2313 typedef II2D(int x, int y); 2315 typedef II2D(int x, int y);
2314 typedef DI2D(x, int y); 2316 typedef DI2D(x, int y);
2315 typedef ID2D(int x, y); 2317 typedef ID2D(int x, y);
2316 typedef DD2D(x, y); 2318 typedef DD2D(x, y);
2317 2319
2318 int foo(int x) => x; 2320 int foo(int x) => x;
2319 int bar(int x, int y) => x + y; 2321 int bar(int x, int y) => x + y;
2320 2322
2321 void main() { 2323 void main() {
2322 bool b; 2324 bool b;
2323 b = /*info:NonGroundTypeCheckInfo*/foo is I2I; 2325 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/foo is I2I;
2324 b = /*info:NonGroundTypeCheckInfo*/foo is D2I; 2326 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/foo is D2I;
2325 b = /*info:NonGroundTypeCheckInfo*/foo is I2D; 2327 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/foo is I2D;
2326 b = foo is D2D; 2328 b = foo is D2D;
2327 2329
2328 b = /*info:NonGroundTypeCheckInfo*/bar is II2I; 2330 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is II2I;
2329 b = /*info:NonGroundTypeCheckInfo*/bar is DI2I; 2331 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is DI2I;
2330 b = /*info:NonGroundTypeCheckInfo*/bar is ID2I; 2332 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is ID2I;
2331 b = /*info:NonGroundTypeCheckInfo*/bar is II2D; 2333 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is II2D;
2332 b = /*info:NonGroundTypeCheckInfo*/bar is DD2I; 2334 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is DD2I;
2333 b = /*info:NonGroundTypeCheckInfo*/bar is DI2D; 2335 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is DI2D;
2334 b = /*info:NonGroundTypeCheckInfo*/bar is ID2D; 2336 b = /*info:NON_GROUND_TYPE_CHECK_INFO*/bar is ID2D;
2335 b = bar is DD2D; 2337 b = bar is DD2D;
2336 2338
2337 // For as, the validity of checks is deferred to runtime. 2339 // For as, the validity of checks is deferred to runtime.
2338 Function f; 2340 Function f;
2339 f = foo as I2I; 2341 f = foo as I2I;
2340 f = foo as D2I; 2342 f = foo as D2I;
2341 f = foo as I2D; 2343 f = foo as I2D;
2342 f = foo as D2D; 2344 f = foo as D2D;
2343 2345
2344 f = bar as II2I; 2346 f = bar as II2I;
(...skipping 11 matching lines...) Expand all
2356 group('function modifiers', () { 2358 group('function modifiers', () {
2357 testChecker('async', { 2359 testChecker('async', {
2358 '/main.dart': ''' 2360 '/main.dart': '''
2359 import 'dart:async'; 2361 import 'dart:async';
2360 import 'dart:math' show Random; 2362 import 'dart:math' show Random;
2361 2363
2362 dynamic x; 2364 dynamic x;
2363 2365
2364 foo1() async => x; 2366 foo1() async => x;
2365 Future foo2() async => x; 2367 Future foo2() async => x;
2366 Future<int> foo3() async => (/*info:DynamicCast*/x); 2368 Future<int> foo3() async => (/*info:DYNAMIC_CAST*/x);
2367 Future<int> foo4() async => (/*severe:StaticTypeError*/new Future<int>.v alue(/*info:DynamicCast*/x)); 2369 Future<int> foo4() async => (/*severe:STATIC_TYPE_ERROR*/new Future<int> .value(/*info:DYNAMIC_CAST*/x));
2368 2370
2369 bar1() async { return x; } 2371 bar1() async { return x; }
2370 Future bar2() async { return x; } 2372 Future bar2() async { return x; }
2371 Future<int> bar3() async { return (/*info:DynamicCast*/x); } 2373 Future<int> bar3() async { return (/*info:DYNAMIC_CAST*/x); }
2372 Future<int> bar4() async { return (/*severe:StaticTypeError*/new Future< int>.value(/*info:DynamicCast*/x)); } 2374 Future<int> bar4() async { return (/*severe:STATIC_TYPE_ERROR*/new Futur e<int>.value(/*info:DYNAMIC_CAST*/x)); }
2373 2375
2374 int y; 2376 int y;
2375 Future<int> z; 2377 Future<int> z;
2376 2378
2377 void baz() async { 2379 void baz() async {
2378 int a = /*info:DynamicCast*/await x; 2380 int a = /*info:DYNAMIC_CAST*/await x;
2379 int b = await y; 2381 int b = await y;
2380 int c = await z; 2382 int c = await z;
2381 String d = /*severe:StaticTypeError*/await z; 2383 String d = /*severe:STATIC_TYPE_ERROR*/await z;
2382 } 2384 }
2383 2385
2384 Future<bool> get issue_264 async { 2386 Future<bool> get issue_264 async {
2385 await 42; 2387 await 42;
2386 if (new Random().nextBool()) { 2388 if (new Random().nextBool()) {
2387 return true; 2389 return true;
2388 } else { 2390 } else {
2389 return /*severe:StaticTypeError*/new Future<bool>.value(false); 2391 return /*severe:STATIC_TYPE_ERROR*/new Future<bool>.value(false);
2390 } 2392 }
2391 } 2393 }
2392 ''' 2394 '''
2393 }); 2395 });
2394 2396
2395 testChecker('async*', { 2397 testChecker('async*', {
2396 '/main.dart': ''' 2398 '/main.dart': '''
2397 import 'dart:async'; 2399 import 'dart:async';
2398 2400
2399 dynamic x; 2401 dynamic x;
2400 2402
2401 bar1() async* { yield x; } 2403 bar1() async* { yield x; }
2402 Stream bar2() async* { yield x; } 2404 Stream bar2() async* { yield x; }
2403 Stream<int> bar3() async* { yield (/*info:DynamicCast*/x); } 2405 Stream<int> bar3() async* { yield (/*info:DYNAMIC_CAST*/x); }
2404 Stream<int> bar4() async* { yield (/*severe:StaticTypeError*/new Stream< int>()); } 2406 Stream<int> bar4() async* { yield (/*severe:STATIC_TYPE_ERROR*/new Strea m<int>()); }
2405 2407
2406 baz1() async* { yield* (/*info:DynamicCast*/x); } 2408 baz1() async* { yield* (/*info:DYNAMIC_CAST*/x); }
2407 Stream baz2() async* { yield* (/*info:DynamicCast*/x); } 2409 Stream baz2() async* { yield* (/*info:DYNAMIC_CAST*/x); }
2408 Stream<int> baz3() async* { yield* (/*warning:DownCastComposite*/x); } 2410 Stream<int> baz3() async* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); }
2409 Stream<int> baz4() async* { yield* new Stream<int>(); } 2411 Stream<int> baz4() async* { yield* new Stream<int>(); }
2410 Stream<int> baz5() async* { yield* (/*info:InferredTypeAllocation*/new S tream()); } 2412 Stream<int> baz5() async* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/new Stream()); }
2411 ''' 2413 '''
2412 }); 2414 });
2413 2415
2414 testChecker('sync*', { 2416 testChecker('sync*', {
2415 '/main.dart': ''' 2417 '/main.dart': '''
2416 import 'dart:async'; 2418 import 'dart:async';
2417 2419
2418 dynamic x; 2420 dynamic x;
2419 2421
2420 bar1() sync* { yield x; } 2422 bar1() sync* { yield x; }
2421 Iterable bar2() sync* { yield x; } 2423 Iterable bar2() sync* { yield x; }
2422 Iterable<int> bar3() sync* { yield (/*info:DynamicCast*/x); } 2424 Iterable<int> bar3() sync* { yield (/*info:DYNAMIC_CAST*/x); }
2423 Iterable<int> bar4() sync* { yield (/*severe:StaticTypeError*/new Iterab le<int>()); } 2425 Iterable<int> bar4() sync* { yield (/*severe:STATIC_TYPE_ERROR*/new Iter able<int>()); }
2424 2426
2425 baz1() sync* { yield* (/*info:DynamicCast*/x); } 2427 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2426 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } 2428 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2427 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } 2429 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); }
2428 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } 2430 Iterable<int> baz4() sync* { yield* new Iterable<int>(); }
2429 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new Iterable()); } 2431 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); }
2430 ''' 2432 '''
2431 }); 2433 });
2432 }); 2434 });
2433 } 2435 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698