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

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

Issue 1673843003: improve debugging of strong mode checker/inference tests (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 months 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 analyzer.test.src.task.strong.checker_test; 8 library analyzer.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 13
14 void main() { 14 void main() {
15 testChecker('ternary operator', { 15 initStrongModeTests();
16 '/main.dart': ''' 16
17 test('ternary operator', () {
18 checkFile('''
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;
(...skipping 17 matching lines...) Expand all
44 void main() { 46 void main() {
45 Object obj = 42; 47 Object obj = 42;
46 dynamic dyn = 42; 48 dynamic dyn = 42;
47 int i = 42; 49 int i = 42;
48 50
49 // Check the boolean conversion of the condition. 51 // Check the boolean conversion of the condition.
50 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true); 52 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true);
51 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true); 53 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true);
52 print((/*info:DYNAMIC_CAST*/dyn) ? false : true); 54 print((/*info:DYNAMIC_CAST*/dyn) ? false : true);
53 } 55 }
54 ''' 56 ''');
55 }); 57 });
56 58
57 testChecker('if/for/do/while statements use boolean conversion', { 59 test('if/for/do/while statements use boolean conversion', () {
58 '/main.dart': ''' 60 checkFile('''
59 main() { 61 main() {
60 dynamic d = 42; 62 dynamic d = 42;
61 Object obj = 42; 63 Object obj = 42;
62 int i = 42; 64 int i = 42;
63 bool b = false; 65 bool b = false;
64 66
65 if (b) {} 67 if (b) {}
66 if (/*info:DYNAMIC_CAST*/dyn) {} 68 if (/*info:DYNAMIC_CAST*/dyn) {}
67 if (/*info:DOWN_CAST_IMPLICIT*/obj) {} 69 if (/*info:DOWN_CAST_IMPLICIT*/obj) {}
68 if (/*severe:STATIC_TYPE_ERROR*/i) {} 70 if (/*severe:STATIC_TYPE_ERROR*/i) {}
69 71
70 while (b) {} 72 while (b) {}
71 while (/*info:DYNAMIC_CAST*/dyn) {} 73 while (/*info:DYNAMIC_CAST*/dyn) {}
72 while (/*info:DOWN_CAST_IMPLICIT*/obj) {} 74 while (/*info:DOWN_CAST_IMPLICIT*/obj) {}
73 while (/*severe:STATIC_TYPE_ERROR*/i) {} 75 while (/*severe:STATIC_TYPE_ERROR*/i) {}
74 76
75 do {} while (b); 77 do {} while (b);
76 do {} while (/*info:DYNAMIC_CAST*/dyn); 78 do {} while (/*info:DYNAMIC_CAST*/dyn);
77 do {} while (/*info:DOWN_CAST_IMPLICIT*/obj); 79 do {} while (/*info:DOWN_CAST_IMPLICIT*/obj);
78 do {} while (/*severe:STATIC_TYPE_ERROR*/i); 80 do {} while (/*severe:STATIC_TYPE_ERROR*/i);
79 81
80 for (;b;) {} 82 for (;b;) {}
81 for (;/*info:DYNAMIC_CAST*/dyn;) {} 83 for (;/*info:DYNAMIC_CAST*/dyn;) {}
82 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} 84 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {}
83 for (;/*severe:STATIC_TYPE_ERROR*/i;) {} 85 for (;/*severe:STATIC_TYPE_ERROR*/i;) {}
84 } 86 }
85 ''' 87 ''');
86 }); 88 });
87 89
88 testChecker('dynamic invocation', { 90 test('dynamic invocation', () {
89 '/main.dart': ''' 91 checkFile('''
90 92
91 class A { 93 class A {
92 dynamic call(dynamic x) => x; 94 dynamic call(dynamic x) => x;
93 } 95 }
94 class B extends A { 96 class B extends A {
95 int call(int x) => x; 97 int call(int x) => x;
96 double col(double x) => x; 98 double col(double x) => x;
97 } 99 }
98 void main() { 100 void main() {
99 { 101 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 (/*info:DYNAMIC_INVOKE*/g.col(42.0)); 134 (/*info:DYNAMIC_INVOKE*/g.col(42.0));
133 (/*info:DYNAMIC_INVOKE*/g.foo(42.0)); 135 (/*info:DYNAMIC_INVOKE*/g.foo(42.0));
134 (/*info:DYNAMIC_INVOKE*/g.x); 136 (/*info:DYNAMIC_INVOKE*/g.x);
135 A f = new B(); 137 A f = new B();
136 f.call(32.0); 138 f.call(32.0);
137 (/*info:DYNAMIC_INVOKE*/f.col(42.0)); 139 (/*info:DYNAMIC_INVOKE*/f.col(42.0));
138 (/*info:DYNAMIC_INVOKE*/f.foo(42.0)); 140 (/*info:DYNAMIC_INVOKE*/f.foo(42.0));
139 (/*info:DYNAMIC_INVOKE*/f.x); 141 (/*info:DYNAMIC_INVOKE*/f.x);
140 } 142 }
141 } 143 }
142 ''' 144 ''');
143 }); 145 });
144 146
145 testChecker('conversion and dynamic invoke', { 147 test('conversion and dynamic invoke', () {
146 '/helper.dart': ''' 148 addFile(
149 '''
147 dynamic toString = (int x) => x + 42; 150 dynamic toString = (int x) => x + 42;
148 dynamic hashCode = "hello"; 151 dynamic hashCode = "hello";
149 ''', 152 ''',
150 '/main.dart': ''' 153 name: '/helper.dart');
154 checkFile('''
151 import 'helper.dart' as helper; 155 import 'helper.dart' as helper;
152 156
153 class A { 157 class A {
154 String x = "hello world"; 158 String x = "hello world";
155 159
156 void baz1(y) => x + /*info:DYNAMIC_CAST*/y; 160 void baz1(y) => x + /*info:DYNAMIC_CAST*/y;
157 static baz2(y) => /*info:DYNAMIC_INVOKE*/y + y; 161 static baz2(y) => /*info:DYNAMIC_INVOKE*/y + y;
158 } 162 }
159 163
160 void foo(String str) { 164 void foo(String str) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 (/*info:DYNAMIC_INVOKE*/toString()); 216 (/*info:DYNAMIC_INVOKE*/toString());
213 217
214 (/*info:DYNAMIC_INVOKE*/helper.toString()); 218 (/*info:DYNAMIC_INVOKE*/helper.toString());
215 var toStringClosure2 = helper.toString; 219 var toStringClosure2 = helper.toString;
216 (/*info:DYNAMIC_INVOKE*/toStringClosure2()); 220 (/*info:DYNAMIC_INVOKE*/toStringClosure2());
217 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode; 221 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode;
218 222
219 baz().toString(); 223 baz().toString();
220 baz().hashCode; 224 baz().hashCode;
221 } 225 }
222 ''' 226 ''');
223 }); 227 });
224 228
225 testChecker('Constructors', { 229 test('Constructors', () {
226 '/main.dart': ''' 230 checkFile('''
227 const num z = 25; 231 const num z = 25;
228 Object obj = "world"; 232 Object obj = "world";
229 233
230 class A { 234 class A {
231 int x; 235 int x;
232 String y; 236 String y;
233 237
234 A(this.x) : this.y = /*severe:STATIC_TYPE_ERROR*/42; 238 A(this.x) : this.y = /*severe:STATIC_TYPE_ERROR*/42;
235 239
236 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_ CAST*/p; 240 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_ CAST*/p;
237 241
238 A.c2(this.x, this.y); 242 A.c2(this.x, this.y);
239 243
240 A.c3(/*severe:INVALID_PARAMETER_DECLARATION*/num this.x, String this.y); 244 A.c3(/*severe:INVALID_PARAMETER_DECLARATION*/num this.x, String this.y);
241 } 245 }
242 246
243 class B extends A { 247 class B extends A {
244 B() : super(/*severe:STATIC_TYPE_ERROR*/"hello"); 248 B() : super(/*severe:STATIC_TYPE_ERROR*/"hello");
245 249
246 B.c2(int x, String y) : super.c2(/*severe:STATIC_TYPE_ERROR*/y, 250 B.c2(int x, String y) : super.c2(/*severe:STATIC_TYPE_ERROR*/y,
247 /*severe:STATIC_TYPE_ERROR*/x); 251 /*severe:STATIC_TYPE_ERROR*/x);
248 252
249 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/y); 253 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/y);
250 } 254 }
251 255
252 void main() { 256 void main() {
253 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR */z); 257 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR */z);
254 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_ IMPLICIT*/obj); 258 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_ IMPLICIT*/obj);
255 } 259 }
256 ''' 260 ''');
257 }); 261 });
258 262
259 testChecker('Unbound variable', { 263 test('Unbound variable', () {
260 '/main.dart': ''' 264 checkFile('''
261 void main() { 265 void main() {
262 dynamic y = /*pass should be severe:STATIC_TYPE_ERROR*/unboundVariable; 266 dynamic y = /*pass should be severe:STATIC_TYPE_ERROR*/unboundVariable;
263 } 267 }
264 ''' 268 ''');
265 }); 269 });
266 270
267 testChecker('Unbound type name', { 271 test('Unbound type name', () {
268 '/main.dart': ''' 272 checkFile('''
269 void main() { 273 void main() {
270 /*pass should be severe:STATIC_TYPE_ERROR*/AToB y; 274 /*pass should be severe:STATIC_TYPE_ERROR*/AToB y;
271 } 275 }
272 ''' 276 ''');
273 }); 277 });
274 278
275 // Regression test for https://github.com/dart-lang/sdk/issues/25069 279 // Regression test for https://github.com/dart-lang/sdk/issues/25069
276 testChecker('Void subtyping', { 280 test('Void subtyping', () {
277 '/main.dart': ''' 281 checkFile('''
278 typedef int Foo(); 282 typedef int Foo();
279 void foo() {} 283 void foo() {}
280 void main () { 284 void main () {
281 Foo x = /*severe:STATIC_TYPE_ERROR*/foo(); 285 Foo x = /*severe:STATIC_TYPE_ERROR*/foo();
282 } 286 }
283 ''' 287 ''');
284 }); 288 });
285 289
286 group('Ground type subtyping:', () { 290 group('Ground type subtyping:', () {
287 testChecker('dynamic is top', { 291 test('dynamic is top', () {
288 '/main.dart': ''' 292 checkFile('''
289 293
290 class A {} 294 class A {}
291 class B extends A {} 295 class B extends A {}
292 296
293 void main() { 297 void main() {
294 dynamic y; 298 dynamic y;
295 Object o; 299 Object o;
296 int i = 0; 300 int i = 0;
297 double d = 0.0; 301 double d = 0.0;
298 num n; 302 num n;
299 A a; 303 A a;
300 B b; 304 B b;
301 y = o; 305 y = o;
302 y = i; 306 y = i;
303 y = d; 307 y = d;
304 y = n; 308 y = n;
305 y = a; 309 y = a;
306 y = b; 310 y = b;
307 } 311 }
308 ''' 312 ''');
309 }); 313 });
310 314
311 testChecker('dynamic downcasts', { 315 test('dynamic downcasts', () {
312 '/main.dart': ''' 316 checkFile('''
313 317
314 class A {} 318 class A {}
315 class B extends A {} 319 class B extends A {}
316 320
317 void main() { 321 void main() {
318 dynamic y; 322 dynamic y;
319 Object o; 323 Object o;
320 int i = 0; 324 int i = 0;
321 double d = 0.0; 325 double d = 0.0;
322 num n; 326 num n;
323 A a; 327 A a;
324 B b; 328 B b;
325 o = y; 329 o = y;
326 i = /*info:DYNAMIC_CAST*/y; 330 i = /*info:DYNAMIC_CAST*/y;
327 d = /*info:DYNAMIC_CAST*/y; 331 d = /*info:DYNAMIC_CAST*/y;
328 n = /*info:DYNAMIC_CAST*/y; 332 n = /*info:DYNAMIC_CAST*/y;
329 a = /*info:DYNAMIC_CAST*/y; 333 a = /*info:DYNAMIC_CAST*/y;
330 b = /*info:DYNAMIC_CAST*/y; 334 b = /*info:DYNAMIC_CAST*/y;
331 } 335 }
332 ''' 336 ''');
333 }); 337 });
334 338
335 testChecker('assigning a class', { 339 test('assigning a class', () {
336 '/main.dart': ''' 340 checkFile('''
337 341
338 class A {} 342 class A {}
339 class B extends A {} 343 class B extends A {}
340 344
341 void main() { 345 void main() {
342 dynamic y; 346 dynamic y;
343 Object o; 347 Object o;
344 int i = 0; 348 int i = 0;
345 double d = 0.0; 349 double d = 0.0;
346 num n; 350 num n;
347 A a; 351 A a;
348 B b; 352 B b;
349 y = a; 353 y = a;
350 o = a; 354 o = a;
351 i = /*severe:STATIC_TYPE_ERROR*/a; 355 i = /*severe:STATIC_TYPE_ERROR*/a;
352 d = /*severe:STATIC_TYPE_ERROR*/a; 356 d = /*severe:STATIC_TYPE_ERROR*/a;
353 n = /*severe:STATIC_TYPE_ERROR*/a; 357 n = /*severe:STATIC_TYPE_ERROR*/a;
354 a = a; 358 a = a;
355 b = /*info:DOWN_CAST_IMPLICIT*/a; 359 b = /*info:DOWN_CAST_IMPLICIT*/a;
356 } 360 }
357 ''' 361 ''');
358 }); 362 });
359 363
360 testChecker('assigning a subclass', { 364 test('assigning a subclass', () {
361 '/main.dart': ''' 365 checkFile('''
362 366
363 class A {} 367 class A {}
364 class B extends A {} 368 class B extends A {}
365 class C extends A {} 369 class C extends A {}
366 370
367 void main() { 371 void main() {
368 dynamic y; 372 dynamic y;
369 Object o; 373 Object o;
370 int i = 0; 374 int i = 0;
371 double d = 0.0; 375 double d = 0.0;
372 num n; 376 num n;
373 A a; 377 A a;
374 B b; 378 B b;
375 C c; 379 C c;
376 y = b; 380 y = b;
377 o = b; 381 o = b;
378 i = /*severe:STATIC_TYPE_ERROR*/b; 382 i = /*severe:STATIC_TYPE_ERROR*/b;
379 d = /*severe:STATIC_TYPE_ERROR*/b; 383 d = /*severe:STATIC_TYPE_ERROR*/b;
380 n = /*severe:STATIC_TYPE_ERROR*/b; 384 n = /*severe:STATIC_TYPE_ERROR*/b;
381 a = b; 385 a = b;
382 b = b; 386 b = b;
383 c = /*severe:STATIC_TYPE_ERROR*/b; 387 c = /*severe:STATIC_TYPE_ERROR*/b;
384 } 388 }
385 ''' 389 ''');
386 }); 390 });
387 391
388 testChecker('interfaces', { 392 test('interfaces', () {
389 '/main.dart': ''' 393 checkFile('''
390 394
391 class A {} 395 class A {}
392 class B extends A {} 396 class B extends A {}
393 class C extends A {} 397 class C extends A {}
394 class D extends B implements C {} 398 class D extends B implements C {}
395 399
396 void main() { 400 void main() {
397 A top; 401 A top;
398 B left; 402 B left;
399 C right; 403 C right;
(...skipping 16 matching lines...) Expand all
416 right = right; 420 right = right;
417 right = bot; 421 right = bot;
418 } 422 }
419 { 423 {
420 bot = /*info:DOWN_CAST_IMPLICIT*/top; 424 bot = /*info:DOWN_CAST_IMPLICIT*/top;
421 bot = /*info:DOWN_CAST_IMPLICIT*/left; 425 bot = /*info:DOWN_CAST_IMPLICIT*/left;
422 bot = /*info:DOWN_CAST_IMPLICIT*/right; 426 bot = /*info:DOWN_CAST_IMPLICIT*/right;
423 bot = bot; 427 bot = bot;
424 } 428 }
425 } 429 }
426 ''' 430 ''');
427 }); 431 });
428 }); 432 });
429 433
430 group('Function typing and subtyping:', () { 434 group('Function typing and subtyping:', () {
431 testChecker('int and object', { 435 test('int and object', () {
432 '/main.dart': ''' 436 checkFile('''
433 437
434 typedef Object Top(int x); // Top of the lattice 438 typedef Object Top(int x); // Top of the lattice
435 typedef int Left(int x); // Left branch 439 typedef int Left(int x); // Left branch
436 typedef int Left2(int x); // Left branch 440 typedef int Left2(int x); // Left branch
437 typedef Object Right(Object x); // Right branch 441 typedef Object Right(Object x); // Right branch
438 typedef int Bot(Object x); // Bottom of the lattice 442 typedef int Bot(Object x); // Bottom of the lattice
439 443
440 Object globalTop(int x) => x; 444 Object globalTop(int x) => x;
441 int globalLeft(int x) => x; 445 int globalLeft(int x) => x;
442 Object globalRight(Object x) => x; 446 Object globalRight(Object x) => x;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 f = bot; 481 f = bot;
478 } 482 }
479 { 483 {
480 Bot f; 484 Bot f;
481 f = /*warning:DOWN_CAST_COMPOSITE*/top; 485 f = /*warning:DOWN_CAST_COMPOSITE*/top;
482 f = /*warning:DOWN_CAST_COMPOSITE*/left; 486 f = /*warning:DOWN_CAST_COMPOSITE*/left;
483 f = /*warning:DOWN_CAST_COMPOSITE*/right; 487 f = /*warning:DOWN_CAST_COMPOSITE*/right;
484 f = bot; 488 f = bot;
485 } 489 }
486 } 490 }
487 ''' 491 ''');
488 }); 492 });
489 493
490 testChecker('classes', { 494 test('classes', () {
491 '/main.dart': ''' 495 checkFile('''
492 496
493 class A {} 497 class A {}
494 class B extends A {} 498 class B extends A {}
495 499
496 typedef A Top(B x); // Top of the lattice 500 typedef A Top(B x); // Top of the lattice
497 typedef B Left(B x); // Left branch 501 typedef B Left(B x); // Left branch
498 typedef B Left2(B x); // Left branch 502 typedef B Left2(B x); // Left branch
499 typedef A Right(A x); // Right branch 503 typedef A Right(A x); // Right branch
500 typedef B Bot(A x); // Bottom of the lattice 504 typedef B Bot(A x); // Bottom of the lattice
501 505
(...skipping 30 matching lines...) Expand all
532 f = bot; 536 f = bot;
533 } 537 }
534 { 538 {
535 Bot f; 539 Bot f;
536 f = /*severe:STATIC_TYPE_ERROR*/top; 540 f = /*severe:STATIC_TYPE_ERROR*/top;
537 f = /*severe:STATIC_TYPE_ERROR*/left; 541 f = /*severe:STATIC_TYPE_ERROR*/left;
538 f = /*severe:STATIC_TYPE_ERROR*/right; 542 f = /*severe:STATIC_TYPE_ERROR*/right;
539 f = bot; 543 f = bot;
540 } 544 }
541 } 545 }
542 ''' 546 ''');
543 }); 547 });
544 548
545 testChecker('dynamic', { 549 test('dynamic', () {
546 '/main.dart': ''' 550 checkFile('''
547 551
548 class A {} 552 class A {}
549 553
550 typedef dynamic Top(dynamic x); // Top of the lattice 554 typedef dynamic Top(dynamic x); // Top of the lattice
551 typedef dynamic Left(A x); // Left branch 555 typedef dynamic Left(A x); // Left branch
552 typedef A Right(dynamic x); // Right branch 556 typedef A Right(dynamic x); // Right branch
553 typedef A Bottom(A x); // Bottom of the lattice 557 typedef A Bottom(A x); // Bottom of the lattice
554 558
555 dynamic left(A x) => x; 559 dynamic left(A x) => x;
556 A bot(A x) => x; 560 A bot(A x) => x;
(...skipping 23 matching lines...) Expand all
580 f = bot; 584 f = bot;
581 } 585 }
582 { 586 {
583 Bottom f; 587 Bottom f;
584 f = /*severe:STATIC_TYPE_ERROR*/top; 588 f = /*severe:STATIC_TYPE_ERROR*/top;
585 f = /*severe:STATIC_TYPE_ERROR*/left; 589 f = /*severe:STATIC_TYPE_ERROR*/left;
586 f = /*severe:STATIC_TYPE_ERROR*/right; 590 f = /*severe:STATIC_TYPE_ERROR*/right;
587 f = bot; 591 f = bot;
588 } 592 }
589 } 593 }
590 ''' 594 ''');
591 }); 595 });
592 596
593 testChecker('function literal variance', { 597 test('function literal variance', () {
594 '/main.dart': ''' 598 checkFile('''
595 599
596 class A {} 600 class A {}
597 class B extends A {} 601 class B extends A {}
598 602
599 typedef T Function2<S, T>(S z); 603 typedef T Function2<S, T>(S z);
600 604
601 A top(B x) => x; 605 A top(B x) => x;
602 B left(B x) => x; 606 B left(B x) => x;
603 A right(A x) => x; 607 A right(A x) => x;
604 B bot(A x) => x as B; 608 B bot(A x) => x as B;
(...skipping 21 matching lines...) Expand all
626 f = bot; 630 f = bot;
627 } 631 }
628 { 632 {
629 Function2<A, B> f; 633 Function2<A, B> f;
630 f = /*severe:STATIC_TYPE_ERROR*/top; 634 f = /*severe:STATIC_TYPE_ERROR*/top;
631 f = /*severe:STATIC_TYPE_ERROR*/left; 635 f = /*severe:STATIC_TYPE_ERROR*/left;
632 f = /*severe:STATIC_TYPE_ERROR*/right; 636 f = /*severe:STATIC_TYPE_ERROR*/right;
633 f = bot; 637 f = bot;
634 } 638 }
635 } 639 }
636 ''' 640 ''');
637 }); 641 });
638 642
639 testChecker('function variable variance', { 643 test('function variable variance', () {
640 '/main.dart': ''' 644 checkFile('''
641 645
642 class A {} 646 class A {}
643 class B extends A {} 647 class B extends A {}
644 648
645 typedef T Function2<S, T>(S z); 649 typedef T Function2<S, T>(S z);
646 650
647 void main() { 651 void main() {
648 { 652 {
649 Function2<B, A> top; 653 Function2<B, A> top;
650 Function2<B, B> left; 654 Function2<B, B> left;
(...skipping 14 matching lines...) Expand all
665 right = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this? 669 right = /*warning:DOWN_CAST_COMPOSITE*/left; // Should we reject this?
666 right = right; 670 right = right;
667 right = bot; 671 right = bot;
668 672
669 bot = /*warning:DOWN_CAST_COMPOSITE*/top; 673 bot = /*warning:DOWN_CAST_COMPOSITE*/top;
670 bot = /*warning:DOWN_CAST_COMPOSITE*/left; 674 bot = /*warning:DOWN_CAST_COMPOSITE*/left;
671 bot = /*warning:DOWN_CAST_COMPOSITE*/right; 675 bot = /*warning:DOWN_CAST_COMPOSITE*/right;
672 bot = bot; 676 bot = bot;
673 } 677 }
674 } 678 }
675 ''' 679 ''');
676 }); 680 });
677 681
678 testChecker('static method variance', { 682 test('static method variance', () {
679 '/main.dart': ''' 683 checkFile('''
680 684
681 class A {} 685 class A {}
682 class B extends A {} 686 class B extends A {}
683 687
684 class C { 688 class C {
685 static A top(B x) => x; 689 static A top(B x) => x;
686 static B left(B x) => x; 690 static B left(B x) => x;
687 static A right(A x) => x; 691 static A right(A x) => x;
688 static B bot(A x) => x as B; 692 static B bot(A x) => x as B;
689 } 693 }
(...skipping 23 matching lines...) Expand all
713 f = C.bot; 717 f = C.bot;
714 } 718 }
715 { 719 {
716 Function2<A, B> f; 720 Function2<A, B> f;
717 f = /*severe:STATIC_TYPE_ERROR*/C.top; 721 f = /*severe:STATIC_TYPE_ERROR*/C.top;
718 f = /*severe:STATIC_TYPE_ERROR*/C.left; 722 f = /*severe:STATIC_TYPE_ERROR*/C.left;
719 f = /*severe:STATIC_TYPE_ERROR*/C.right; 723 f = /*severe:STATIC_TYPE_ERROR*/C.right;
720 f = C.bot; 724 f = C.bot;
721 } 725 }
722 } 726 }
723 ''' 727 ''');
724 }); 728 });
725 729
726 testChecker('instance method variance', { 730 test('instance method variance', () {
727 '/main.dart': ''' 731 checkFile('''
728 732
729 class A {} 733 class A {}
730 class B extends A {} 734 class B extends A {}
731 735
732 class C { 736 class C {
733 A top(B x) => x; 737 A top(B x) => x;
734 B left(B x) => x; 738 B left(B x) => x;
735 A right(A x) => x; 739 A right(A x) => x;
736 B bot(A x) => x as B; 740 B bot(A x) => x as B;
737 } 741 }
(...skipping 24 matching lines...) Expand all
762 f = c.bot; 766 f = c.bot;
763 } 767 }
764 { 768 {
765 Function2<A, B> f; 769 Function2<A, B> f;
766 f = /*warning:DOWN_CAST_COMPOSITE*/c.top; 770 f = /*warning:DOWN_CAST_COMPOSITE*/c.top;
767 f = /*warning:DOWN_CAST_COMPOSITE*/c.left; 771 f = /*warning:DOWN_CAST_COMPOSITE*/c.left;
768 f = /*warning:DOWN_CAST_COMPOSITE*/c.right; 772 f = /*warning:DOWN_CAST_COMPOSITE*/c.right;
769 f = c.bot; 773 f = c.bot;
770 } 774 }
771 } 775 }
772 ''' 776 ''');
773 }); 777 });
774 778
775 testChecker('higher order function literals 1', { 779 test('higher order function literals 1', () {
776 '/main.dart': ''' 780 checkFile('''
777 781
778 class A {} 782 class A {}
779 class B extends A {} 783 class B extends A {}
780 784
781 typedef T Function2<S, T>(S z); 785 typedef T Function2<S, T>(S z);
782 786
783 typedef A BToA(B x); // Top of the base lattice 787 typedef A BToA(B x); // Top of the base lattice
784 typedef B AToB(A x); // Bot of the base lattice 788 typedef B AToB(A x); // Bot of the base lattice
785 789
786 BToA top(AToB f) => f; 790 BToA top(AToB f) => f;
(...skipping 25 matching lines...) Expand all
812 f = bot; 816 f = bot;
813 } 817 }
814 { 818 {
815 Function2<BToA, AToB> f; // Bot 819 Function2<BToA, AToB> f; // Bot
816 f = bot; 820 f = bot;
817 f = /*severe:STATIC_TYPE_ERROR*/left; 821 f = /*severe:STATIC_TYPE_ERROR*/left;
818 f = /*severe:STATIC_TYPE_ERROR*/top; 822 f = /*severe:STATIC_TYPE_ERROR*/top;
819 f = /*severe:STATIC_TYPE_ERROR*/left; 823 f = /*severe:STATIC_TYPE_ERROR*/left;
820 } 824 }
821 } 825 }
822 ''' 826 ''');
823 }); 827 });
824 828
825 testChecker('higher order function literals 2', { 829 test('higher order function literals 2', () {
826 '/main.dart': ''' 830 checkFile('''
827 831
828 class A {} 832 class A {}
829 class B extends A {} 833 class B extends A {}
830 834
831 typedef T Function2<S, T>(S z); 835 typedef T Function2<S, T>(S z);
832 836
833 typedef A BToA(B x); // Top of the base lattice 837 typedef A BToA(B x); // Top of the base lattice
834 typedef B AToB(A x); // Bot of the base lattice 838 typedef B AToB(A x); // Bot of the base lattice
835 839
836 Function2<B, A> top(AToB f) => f; 840 Function2<B, A> top(AToB f) => f;
(...skipping 25 matching lines...) Expand all
862 f = bot; 866 f = bot;
863 } 867 }
864 { 868 {
865 Function2<BToA, AToB> f; // Bot 869 Function2<BToA, AToB> f; // Bot
866 f = bot; 870 f = bot;
867 f = /*severe:STATIC_TYPE_ERROR*/left; 871 f = /*severe:STATIC_TYPE_ERROR*/left;
868 f = /*severe:STATIC_TYPE_ERROR*/top; 872 f = /*severe:STATIC_TYPE_ERROR*/top;
869 f = /*severe:STATIC_TYPE_ERROR*/left; 873 f = /*severe:STATIC_TYPE_ERROR*/left;
870 } 874 }
871 } 875 }
872 ''' 876 ''');
873 }); 877 });
874 878
875 testChecker('higher order function literals 3', { 879 test('higher order function literals 3', () {
876 '/main.dart': ''' 880 checkFile('''
877 881
878 class A {} 882 class A {}
879 class B extends A {} 883 class B extends A {}
880 884
881 typedef T Function2<S, T>(S z); 885 typedef T Function2<S, T>(S z);
882 886
883 typedef A BToA(B x); // Top of the base lattice 887 typedef A BToA(B x); // Top of the base lattice
884 typedef B AToB(A x); // Bot of the base lattice 888 typedef B AToB(A x); // Bot of the base lattice
885 889
886 BToA top(Function2<A, B> f) => f; 890 BToA top(Function2<A, B> f) => f;
(...skipping 25 matching lines...) Expand all
912 f = bot; 916 f = bot;
913 } 917 }
914 { 918 {
915 Function2<BToA, AToB> f; // Bot 919 Function2<BToA, AToB> f; // Bot
916 f = bot; 920 f = bot;
917 f = /*severe:STATIC_TYPE_ERROR*/left; 921 f = /*severe:STATIC_TYPE_ERROR*/left;
918 f = /*severe:STATIC_TYPE_ERROR*/top; 922 f = /*severe:STATIC_TYPE_ERROR*/top;
919 f = /*severe:STATIC_TYPE_ERROR*/left; 923 f = /*severe:STATIC_TYPE_ERROR*/left;
920 } 924 }
921 } 925 }
922 ''' 926 ''');
923 }); 927 });
924 928
925 testChecker('higher order function variables', { 929 test('higher order function variables', () {
926 '/main.dart': ''' 930 checkFile('''
927 931
928 class A {} 932 class A {}
929 class B extends A {} 933 class B extends A {}
930 934
931 typedef T Function2<S, T>(S z); 935 typedef T Function2<S, T>(S z);
932 936
933 void main() { 937 void main() {
934 { 938 {
935 Function2<Function2<A, B>, Function2<B, A>> top; 939 Function2<Function2<A, B>, Function2<B, A>> top;
936 Function2<Function2<B, A>, Function2<B, A>> right; 940 Function2<Function2<B, A>, Function2<B, A>> right;
(...skipping 16 matching lines...) Expand all
953 /*warning:DOWN_CAST_COMPOSITE should be severe:STATIC_TYPE_ERROR*/le ft; 957 /*warning:DOWN_CAST_COMPOSITE should be severe:STATIC_TYPE_ERROR*/le ft;
954 right = right; 958 right = right;
955 right = bot; 959 right = bot;
956 960
957 bot = /*warning:DOWN_CAST_COMPOSITE*/top; 961 bot = /*warning:DOWN_CAST_COMPOSITE*/top;
958 bot = /*warning:DOWN_CAST_COMPOSITE*/left; 962 bot = /*warning:DOWN_CAST_COMPOSITE*/left;
959 bot = /*warning:DOWN_CAST_COMPOSITE*/right; 963 bot = /*warning:DOWN_CAST_COMPOSITE*/right;
960 bot = bot; 964 bot = bot;
961 } 965 }
962 } 966 }
963 ''' 967 ''');
964 }); 968 });
965 969
966 testChecker('named and optional parameters', { 970 test('named and optional parameters', () {
967 '/main.dart': ''' 971 checkFile('''
968 972
969 class A {} 973 class A {}
970 974
971 typedef A FR(A x); 975 typedef A FR(A x);
972 typedef A FO([A x]); 976 typedef A FO([A x]);
973 typedef A FN({A x}); 977 typedef A FN({A x});
974 typedef A FRR(A x, A y); 978 typedef A FRR(A x, A y);
975 typedef A FRO(A x, [A y]); 979 typedef A FRO(A x, [A y]);
976 typedef A FRN(A x, {A n}); 980 typedef A FRN(A x, {A n});
977 typedef A FOO([A x, A y]); 981 typedef A FOO([A x, A y]);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 nnn = /*severe:STATIC_TYPE_ERROR*/r; 1076 nnn = /*severe:STATIC_TYPE_ERROR*/r;
1073 nnn = /*severe:STATIC_TYPE_ERROR*/o; 1077 nnn = /*severe:STATIC_TYPE_ERROR*/o;
1074 nnn = /*warning:DOWN_CAST_COMPOSITE*/n; 1078 nnn = /*warning:DOWN_CAST_COMPOSITE*/n;
1075 nnn = /*severe:STATIC_TYPE_ERROR*/rr; 1079 nnn = /*severe:STATIC_TYPE_ERROR*/rr;
1076 nnn = /*severe:STATIC_TYPE_ERROR*/ro; 1080 nnn = /*severe:STATIC_TYPE_ERROR*/ro;
1077 nnn = /*severe:STATIC_TYPE_ERROR*/rn; 1081 nnn = /*severe:STATIC_TYPE_ERROR*/rn;
1078 nnn = /*severe:STATIC_TYPE_ERROR*/oo; 1082 nnn = /*severe:STATIC_TYPE_ERROR*/oo;
1079 nnn = /*warning:DOWN_CAST_COMPOSITE*/nn; 1083 nnn = /*warning:DOWN_CAST_COMPOSITE*/nn;
1080 nnn = nnn; 1084 nnn = nnn;
1081 } 1085 }
1082 ''' 1086 ''');
1083 }); 1087 });
1084 1088
1085 testChecker('Function subtyping: objects with call methods', { 1089 test('Function subtyping: objects with call methods', () {
1086 '/main.dart': ''' 1090 checkFile('''
1087 1091
1088 typedef int I2I(int x); 1092 typedef int I2I(int x);
1089 typedef num N2N(num x); 1093 typedef num N2N(num x);
1090 class A { 1094 class A {
1091 int call(int x) => x; 1095 int call(int x) => x;
1092 } 1096 }
1093 class B { 1097 class B {
1094 num call(num x) => x; 1098 num call(num x) => x;
1095 } 1099 }
1096 int i2i(int x) => x; 1100 int i2i(int x) => x;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 { 1139 {
1136 Function f; 1140 Function f;
1137 f = new A(); 1141 f = new A();
1138 f = new B(); 1142 f = new B();
1139 f = i2i; 1143 f = i2i;
1140 f = n2n; 1144 f = n2n;
1141 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; 1145 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object;
1142 f = (n2n as Function); 1146 f = (n2n as Function);
1143 } 1147 }
1144 } 1148 }
1145 ''' 1149 ''');
1146 }); 1150 });
1147 1151
1148 testChecker('void', { 1152 test('void', () {
1149 '/main.dart': ''' 1153 checkFile('''
1150 1154
1151 class A { 1155 class A {
1152 void bar() => null; 1156 void bar() => null;
1153 void foo() => bar; // allowed 1157 void foo() => bar; // allowed
1154 } 1158 }
1155 ''' 1159 ''');
1156 }); 1160 });
1157 1161
1158 testChecker('uninferred closure', { 1162 test('uninferred closure', () {
1159 '/main.dart': ''' 1163 checkFile('''
1160 typedef num Num2Num(num x); 1164 typedef num Num2Num(num x);
1161 void main() { 1165 void main() {
1162 Num2Num g = /*info:INFERRED_TYPE_CLOSURE,severe:STATIC_TYPE_ERROR*/(int x) { return x; }; 1166 Num2Num g = /*info:INFERRED_TYPE_CLOSURE,severe:STATIC_TYPE_ERROR*/(int x) { return x; };
1163 print(g(42)); 1167 print(g(42));
1164 } 1168 }
1165 ''' 1169 ''');
1166 }); 1170 });
1167 }); 1171 });
1168 1172
1169 testChecker('Relaxed casts', { 1173 test('Relaxed casts', () {
1170 '/main.dart': ''' 1174 checkFile('''
1171 1175
1172 class A {} 1176 class A {}
1173 1177
1174 class L<T> {} 1178 class L<T> {}
1175 class M<T> extends L<T> {} 1179 class M<T> extends L<T> {}
1176 // L<dynamic|Object> 1180 // L<dynamic|Object>
1177 // / \ 1181 // / \
1178 // M<dynamic|Object> L<A> 1182 // M<dynamic|Object> L<A>
1179 // \ / 1183 // \ /
1180 // M<A> 1184 // M<A>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 { 1238 {
1235 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs; 1239 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs;
1236 mOfAs = /*info:DOWN_CAST_IMPLICIT*/mOfOs; 1240 mOfAs = /*info:DOWN_CAST_IMPLICIT*/mOfOs;
1237 mOfAs = mOfAs; 1241 mOfAs = mOfAs;
1238 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs; 1242 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs;
1239 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; 1243 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
1240 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfAs; 1244 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfAs;
1241 } 1245 }
1242 1246
1243 } 1247 }
1244 ''' 1248 ''');
1245 }); 1249 });
1246 1250
1247 testChecker('Type checking literals', { 1251 test('Type checking literals', () {
1248 '/main.dart': ''' 1252 checkFile('''
1249 test() { 1253 test() {
1250 num n = 3; 1254 num n = 3;
1251 int i = 3; 1255 int i = 3;
1252 String s = "hello"; 1256 String s = "hello";
1253 { 1257 {
1254 List<int> l = <int>[i]; 1258 List<int> l = <int>[i];
1255 l = <int>[/*severe:STATIC_TYPE_ERROR*/s]; 1259 l = <int>[/*severe:STATIC_TYPE_ERROR*/s];
1256 l = <int>[/*info:DOWN_CAST_IMPLICIT*/n]; 1260 l = <int>[/*info:DOWN_CAST_IMPLICIT*/n];
1257 l = <int>[i, /*info:DOWN_CAST_IMPLICIT*/n, /*severe:STATIC_TYPE_E RROR*/s]; 1261 l = <int>[i, /*info:DOWN_CAST_IMPLICIT*/n, /*severe:STATIC_TYPE_E RROR*/s];
1258 } 1262 }
(...skipping 18 matching lines...) Expand all
1277 m = {s: s}; 1281 m = {s: s};
1278 m = {s: n}; 1282 m = {s: n};
1279 m = {s: i, 1283 m = {s: i,
1280 s: n, 1284 s: n,
1281 s: s}; 1285 s: s};
1282 m = {i: s, 1286 m = {i: s,
1283 n: s, 1287 n: s,
1284 s: s}; 1288 s: s};
1285 } 1289 }
1286 } 1290 }
1287 ''' 1291 ''');
1288 }); 1292 });
1289 1293
1290 testChecker('casts in constant contexts', { 1294 test('casts in constant contexts', () {
1291 '/main.dart': ''' 1295 checkFile('''
1292 class A { 1296 class A {
1293 static const num n = 3.0; 1297 static const num n = 3.0;
1294 static const int i = /*info:ASSIGNMENT_CAST*/n; 1298 static const int i = /*info:ASSIGNMENT_CAST*/n;
1295 final int fi; 1299 final int fi;
1296 const A(num a) : this.fi = /*info:DOWN_CAST_IMPLICIT*/a; 1300 const A(num a) : this.fi = /*info:DOWN_CAST_IMPLICIT*/a;
1297 } 1301 }
1298 class B extends A { 1302 class B extends A {
1299 const B(Object a) : super(/*info:DOWN_CAST_IMPLICIT*/a); 1303 const B(Object a) : super(/*info:DOWN_CAST_IMPLICIT*/a);
1300 } 1304 }
1301 void foo(Object o) { 1305 void foo(Object o) {
1302 var a = const A(/*info:DOWN_CAST_IMPLICIT*/o); 1306 var a = const A(/*info:DOWN_CAST_IMPLICIT*/o);
1303 } 1307 }
1304 ''' 1308 ''');
1305 }); 1309 });
1306 1310
1307 testChecker('casts in conditionals', { 1311 test('casts in conditionals', () {
1308 '/main.dart': ''' 1312 checkFile('''
1309 main() { 1313 main() {
1310 bool b = true; 1314 bool b = true;
1311 num x = b ? 1 : 2.3; 1315 num x = b ? 1 : 2.3;
1312 int y = /*info:ASSIGNMENT_CAST*/b ? 1 : 2.3; 1316 int y = /*info:ASSIGNMENT_CAST*/b ? 1 : 2.3;
1313 String z = !b ? "hello" : null; 1317 String z = !b ? "hello" : null;
1314 z = b ? null : "hello"; 1318 z = b ? null : "hello";
1315 } 1319 }
1316 ''' 1320 ''');
1317 }); 1321 });
1318 1322
1319 // This is a regression test for https://github.com/dart-lang/sdk/issues/25071 1323 // This is a regression test for https://github.com/dart-lang/sdk/issues/25071
1320 testChecker('unbound redirecting constructor', { 1324 test('unbound redirecting constructor', () {
1321 '/main.dart': ''' 1325 checkFile('''
1322 class Foo { 1326 class Foo {
1323 Foo() : this.init(); 1327 Foo() : this.init();
1324 } 1328 }
1325 ''' 1329 ''');
1326 }); 1330 });
1327 1331
1328 testChecker('redirecting constructor', { 1332 test('redirecting constructor', () {
1329 '/main.dart': ''' 1333 checkFile('''
1330 class A { 1334 class A {
1331 A(A x) {} 1335 A(A x) {}
1332 A.two() : this(/*severe:STATIC_TYPE_ERROR*/3); 1336 A.two() : this(/*severe:STATIC_TYPE_ERROR*/3);
1333 } 1337 }
1334 ''' 1338 ''');
1335 }); 1339 });
1336 1340
1337 testChecker('super constructor', { 1341 test('super constructor', () {
1338 '/main.dart': ''' 1342 checkFile('''
1339 class A { A(A x) {} } 1343 class A { A(A x) {} }
1340 class B extends A { 1344 class B extends A {
1341 B() : super(/*severe:STATIC_TYPE_ERROR*/3); 1345 B() : super(/*severe:STATIC_TYPE_ERROR*/3);
1342 } 1346 }
1343 ''' 1347 ''');
1344 }); 1348 });
1345 1349
1346 testChecker('factory constructor downcast', { 1350 test('factory constructor downcast', () {
1347 '/main.dart': r''' 1351 checkFile(r'''
1348 class Animal { 1352 class Animal {
1349 Animal(); 1353 Animal();
1350 factory Animal.cat() => return new Cat(); 1354 factory Animal.cat() => return new Cat();
1351 } 1355 }
1352 1356
1353 class Cat extends Animal {} 1357 class Cat extends Animal {}
1354 1358
1355 void main() { 1359 void main() {
1356 Cat c = /*info:ASSIGNMENT_CAST*/new Animal.cat(); 1360 Cat c = /*info:ASSIGNMENT_CAST*/new Animal.cat();
1357 c = /*severe:STATIC_TYPE_ERROR*/new Animal(); 1361 c = /*severe:STATIC_TYPE_ERROR*/new Animal();
1358 }''' 1362 }''');
1359 }); 1363 });
1360 1364
1361 testChecker('field/field override', { 1365 test('field/field override', () {
1362 '/main.dart': ''' 1366 checkFile('''
1363 class A {} 1367 class A {}
1364 class B extends A {} 1368 class B extends A {}
1365 class C extends B {} 1369 class C extends B {}
1366 1370
1367 class Base { 1371 class Base {
1368 B f1; 1372 B f1;
1369 B f2; 1373 B f2;
1370 B f3; 1374 B f3;
1371 B f4; 1375 B f4;
1372 } 1376 }
1373 1377
1374 class Child extends Base { 1378 class Child extends Base {
1375 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A f1 ; // invalid for getter 1379 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A f1 ; // invalid for getter
1376 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/C f2 ; // invalid for setter 1380 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/C f2 ; // invalid for setter
1377 /*severe:INVALID_FIELD_OVERRIDE*/var f3; 1381 /*severe:INVALID_FIELD_OVERRIDE*/var f3;
1378 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sever e:INVALID_METHOD_OVERRIDE*/dynamic f4; 1382 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sever e:INVALID_METHOD_OVERRIDE*/dynamic f4;
1379 } 1383 }
1380 1384
1381 class Child2 implements Base { 1385 class Child2 implements Base {
1382 /*severe:INVALID_METHOD_OVERRIDE*/A f1; // invalid for getter 1386 /*severe:INVALID_METHOD_OVERRIDE*/A f1; // invalid for getter
1383 /*severe:INVALID_METHOD_OVERRIDE*/C f2; // invalid for setter 1387 /*severe:INVALID_METHOD_OVERRIDE*/C f2; // invalid for setter
1384 var f3; 1388 var f3;
1385 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyn amic f4; 1389 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyn amic f4;
1386 } 1390 }
1387 ''' 1391 ''');
1388 }); 1392 });
1389 1393
1390 testChecker('private override', { 1394 test('private override', () {
1391 '/helper.dart': ''' 1395 addFile(
1396 '''
1392 import 'main.dart' as main; 1397 import 'main.dart' as main;
1393 1398
1394 class Base { 1399 class Base {
1395 var f1; 1400 var f1;
1396 var _f2; 1401 var _f2;
1397 var _f3; 1402 var _f3;
1398 get _f4 => null; 1403 get _f4 => null;
1399 1404
1400 int _m1(); 1405 int _m1();
1401 } 1406 }
1402 1407
1403 class GrandChild extends main.Child { 1408 class GrandChild extends main.Child {
1404 /*severe:INVALID_FIELD_OVERRIDE*/var _f2; 1409 /*severe:INVALID_FIELD_OVERRIDE*/var _f2;
1405 /*severe:INVALID_FIELD_OVERRIDE*/var _f3; 1410 /*severe:INVALID_FIELD_OVERRIDE*/var _f3;
1406 var _f4; 1411 var _f4;
1407 1412
1408 /*severe:INVALID_METHOD_OVERRIDE*/String _m1(); 1413 /*severe:INVALID_METHOD_OVERRIDE*/String _m1();
1409 } 1414 }
1410 ''', 1415 ''',
1411 '/main.dart': ''' 1416 name: '/helper.dart');
1417 checkFile('''
1412 import 'helper.dart' as helper; 1418 import 'helper.dart' as helper;
1413 1419
1414 class Child extends helper.Base { 1420 class Child extends helper.Base {
1415 /*severe:INVALID_FIELD_OVERRIDE*/var f1; 1421 /*severe:INVALID_FIELD_OVERRIDE*/var f1;
1416 var _f2; 1422 var _f2;
1417 var _f4; 1423 var _f4;
1418 1424
1419 String _m1(); 1425 String _m1();
1420 } 1426 }
1421 ''' 1427 ''');
1422 }); 1428 });
1423 1429
1424 testChecker('getter/getter override', { 1430 test('getter/getter override', () {
1425 '/main.dart': ''' 1431 checkFile('''
1426 class A {} 1432 class A {}
1427 class B extends A {} 1433 class B extends A {}
1428 class C extends B {} 1434 class C extends B {}
1429 1435
1430 abstract class Base { 1436 abstract class Base {
1431 B get f1; 1437 B get f1;
1432 B get f2; 1438 B get f2;
1433 B get f3; 1439 B get f3;
1434 B get f4; 1440 B get f4;
1435 } 1441 }
1436 1442
1437 class Child extends Base { 1443 class Child extends Base {
1438 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; 1444 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null;
1439 C get f2 => null; 1445 C get f2 => null;
1440 get f3 => null; 1446 get f3 => null;
1441 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; 1447 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null;
1442 } 1448 }
1443 ''' 1449 ''');
1444 }); 1450 });
1445 1451
1446 testChecker('field/getter override', { 1452 test('field/getter override', () {
1447 '/main.dart': ''' 1453 checkFile('''
1448 class A {} 1454 class A {}
1449 class B extends A {} 1455 class B extends A {}
1450 class C extends B {} 1456 class C extends B {}
1451 1457
1452 abstract class Base { 1458 abstract class Base {
1453 B f1; 1459 B f1;
1454 B f2; 1460 B f2;
1455 B f3; 1461 B f3;
1456 B f4; 1462 B f4;
1457 } 1463 }
1458 1464
1459 class Child extends Base { 1465 class Child extends Base {
1460 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A ge t f1 => null; 1466 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A ge t f1 => null;
1461 /*severe:INVALID_FIELD_OVERRIDE*/C get f2 => null; 1467 /*severe:INVALID_FIELD_OVERRIDE*/C get f2 => null;
1462 /*severe:INVALID_FIELD_OVERRIDE*/get f3 => null; 1468 /*severe:INVALID_FIELD_OVERRIDE*/get f3 => null;
1463 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyna mic get f4 => null; 1469 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyna mic get f4 => null;
1464 } 1470 }
1465 1471
1466 class Child2 implements Base { 1472 class Child2 implements Base {
1467 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; 1473 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null;
1468 C get f2 => null; 1474 C get f2 => null;
1469 get f3 => null; 1475 get f3 => null;
1470 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; 1476 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null;
1471 } 1477 }
1472 ''' 1478 ''');
1473 }); 1479 });
1474 1480
1475 testChecker('setter/setter override', { 1481 test('setter/setter override', () {
1476 '/main.dart': ''' 1482 checkFile('''
1477 class A {} 1483 class A {}
1478 class B extends A {} 1484 class B extends A {}
1479 class C extends B {} 1485 class C extends B {}
1480 1486
1481 abstract class Base { 1487 abstract class Base {
1482 void set f1(B value); 1488 void set f1(B value);
1483 void set f2(B value); 1489 void set f2(B value);
1484 void set f3(B value); 1490 void set f3(B value);
1485 void set f4(B value); 1491 void set f4(B value);
1486 void set f5(B value); 1492 void set f5(B value);
1487 } 1493 }
1488 1494
1489 class Child extends Base { 1495 class Child extends Base {
1490 void set f1(A value) {} 1496 void set f1(A value) {}
1491 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {} 1497 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {}
1492 void set f3(value) {} 1498 void set f3(value) {}
1493 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {} 1499 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {}
1494 set f5(B value) {} 1500 set f5(B value) {}
1495 } 1501 }
1496 ''' 1502 ''');
1497 }); 1503 });
1498 1504
1499 testChecker('field/setter override', { 1505 test('field/setter override', () {
1500 '/main.dart': ''' 1506 checkFile('''
1501 class A {} 1507 class A {}
1502 class B extends A {} 1508 class B extends A {}
1503 class C extends B {} 1509 class C extends B {}
1504 1510
1505 class Base { 1511 class Base {
1506 B f1; 1512 B f1;
1507 B f2; 1513 B f2;
1508 B f3; 1514 B f3;
1509 B f4; 1515 B f4;
1510 B f5; 1516 B f5;
(...skipping 19 matching lines...) Expand all
1530 B get f3 => null; 1536 B get f3 => null;
1531 B get f4 => null; 1537 B get f4 => null;
1532 B get f5 => null; 1538 B get f5 => null;
1533 1539
1534 void set f1(A value) {} 1540 void set f1(A value) {}
1535 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {} 1541 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {}
1536 void set f3(value) {} 1542 void set f3(value) {}
1537 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {} 1543 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {}
1538 set f5(B value) {} 1544 set f5(B value) {}
1539 } 1545 }
1540 ''' 1546 ''');
1541 }); 1547 });
1542 1548
1543 testChecker('method override', { 1549 test('method override', () {
1544 '/main.dart': ''' 1550 checkFile('''
1545 class A {} 1551 class A {}
1546 class B extends A {} 1552 class B extends A {}
1547 class C extends B {} 1553 class C extends B {}
1548 1554
1549 class Base { 1555 class Base {
1550 B m1(B a); 1556 B m1(B a);
1551 B m2(B a); 1557 B m2(B a);
1552 B m3(B a); 1558 B m3(B a);
1553 B m4(B a); 1559 B m4(B a);
1554 B m5(B a); 1560 B m5(B a);
1555 B m6(B a); 1561 B m6(B a);
1556 } 1562 }
1557 1563
1558 class Child extends Base { 1564 class Child extends Base {
1559 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {} 1565 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {}
1560 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {} 1566 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {}
1561 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) {} 1567 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) {}
1562 C m4(A value) {} 1568 C m4(A value) {}
1563 m5(value) {} 1569 m5(value) {}
1564 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {} 1570 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {}
1565 } 1571 }
1566 ''' 1572 ''');
1567 }); 1573 });
1568 1574
1569 testChecker('generic class method override', { 1575 test('generic class method override', () {
1570 '/main.dart': ''' 1576 checkFile('''
1571 class A {} 1577 class A {}
1572 class B extends A {} 1578 class B extends A {}
1573 1579
1574 class Base<T extends B> { 1580 class Base<T extends B> {
1575 T foo() => null; 1581 T foo() => null;
1576 } 1582 }
1577 1583
1578 class Derived<S extends A> extends Base<B> { 1584 class Derived<S extends A> extends Base<B> {
1579 /*severe:INVALID_METHOD_OVERRIDE*/S foo() => null; 1585 /*severe:INVALID_METHOD_OVERRIDE*/S foo() => null;
1580 } 1586 }
1581 1587
1582 class Derived2<S extends B> extends Base<B> { 1588 class Derived2<S extends B> extends Base<B> {
1583 S foo() => null; 1589 S foo() => null;
1584 } 1590 }
1585 ''' 1591 ''');
1586 }); 1592 });
1587 1593
1588 testChecker('generic method override', { 1594 test('generic method override', () {
1589 '/main.dart': ''' 1595 checkFile('''
1590 class Future<T> { 1596 class Future<T> {
1591 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; 1597 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null;
1592 } 1598 }
1593 1599
1594 class DerivedFuture<T> extends Future<T> { 1600 class DerivedFuture<T> extends Future<T> {
1595 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; 1601 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null;
1596 } 1602 }
1597 1603
1598 class DerivedFuture2<A> extends Future<A> { 1604 class DerivedFuture2<A> extends Future<A> {
1599 /*=B*/ then/*<B>*/(/*=B*/ onValue(A a)) => null; 1605 /*=B*/ then/*<B>*/(/*=B*/ onValue(A a)) => null;
1600 } 1606 }
1601 1607
1602 class DerivedFuture3<T> extends Future<T> { 1608 class DerivedFuture3<T> extends Future<T> {
1603 /*=S*/ then/*<S>*/(Object onValue(T t)) => null; 1609 /*=S*/ then/*<S>*/(Object onValue(T t)) => null;
1604 } 1610 }
1605 1611
1606 class DerivedFuture4<A> extends Future<A> { 1612 class DerivedFuture4<A> extends Future<A> {
1607 /*=B*/ then/*<B>*/(Object onValue(A a)) => null; 1613 /*=B*/ then/*<B>*/(Object onValue(A a)) => null;
1608 } 1614 }
1609 ''' 1615 ''');
1610 }); 1616 });
1611 1617
1612 testChecker('generic function wrong number of arguments', { 1618 test('generic function wrong number of arguments', () {
1613 '/main.dart': r''' 1619 checkFile(r'''
1614 /*=T*/ foo/*<T>*/(/*=T*/ x, /*=T*/ y) => x; 1620 /*=T*/ foo/*<T>*/(/*=T*/ x, /*=T*/ y) => x;
1615 /*=T*/ bar/*<T>*/({/*=T*/ x, /*=T*/ y}) => x; 1621 /*=T*/ bar/*<T>*/({/*=T*/ x, /*=T*/ y}) => x;
1616 1622
1617 main() { 1623 main() {
1618 // resolving thses shouldn't crash. 1624 // resolving thses shouldn't crash.
1619 foo(1, 2, 3); 1625 foo(1, 2, 3);
1620 String x = foo('1', '2', '3'); 1626 String x = foo('1', '2', '3');
1621 foo(1); 1627 foo(1);
1622 String x = foo('1'); 1628 String x = foo('1');
1623 x = /*severe:STATIC_TYPE_ERROR*/foo(1, 2, 3); 1629 x = /*severe:STATIC_TYPE_ERROR*/foo(1, 2, 3);
1624 x = /*severe:STATIC_TYPE_ERROR*/foo(1); 1630 x = /*severe:STATIC_TYPE_ERROR*/foo(1);
1625 1631
1626 // named arguments 1632 // named arguments
1627 bar(y: 1, x: 2, z: 3); 1633 bar(y: 1, x: 2, z: 3);
1628 String x = bar(z: '1', x: '2', y: '3'); 1634 String x = bar(z: '1', x: '2', y: '3');
1629 bar(y: 1); 1635 bar(y: 1);
1630 x = bar(x: '1', z: 42); 1636 x = bar(x: '1', z: 42);
1631 x = /*severe:STATIC_TYPE_ERROR*/bar(y: 1, x: 2, z: 3); 1637 x = /*severe:STATIC_TYPE_ERROR*/bar(y: 1, x: 2, z: 3);
1632 x = /*severe:STATIC_TYPE_ERROR*/bar(x: 1); 1638 x = /*severe:STATIC_TYPE_ERROR*/bar(x: 1);
1633 } 1639 }
1634 ''' 1640 ''');
1635 }); 1641 });
1636 1642
1637 testChecker('type promotion from dynamic', { 1643 test('type promotion from dynamic', () {
1638 '/main.dart': r''' 1644 checkFile(r'''
1639 f() { 1645 f() {
1640 dynamic x; 1646 dynamic x;
1641 if (x is int) { 1647 if (x is int) {
1642 int y = x; 1648 int y = x;
1643 String z = /*severe:STATIC_TYPE_ERROR*/x; 1649 String z = /*severe:STATIC_TYPE_ERROR*/x;
1644 } 1650 }
1645 } 1651 }
1646 g() { 1652 g() {
1647 Object x; 1653 Object x;
1648 if (x is int) { 1654 if (x is int) {
1649 int y = x; 1655 int y = x;
1650 String z = /*severe:STATIC_TYPE_ERROR*/x; 1656 String z = /*severe:STATIC_TYPE_ERROR*/x;
1651 } 1657 }
1652 } 1658 }
1653 ''' 1659 ''');
1654 }); 1660 });
1655 1661
1656 testChecker('unary operators', { 1662 test('unary operators', () {
1657 '/main.dart': ''' 1663 checkFile('''
1658 class A { 1664 class A {
1659 A operator ~() {} 1665 A operator ~() {}
1660 A operator +(int x) {} 1666 A operator +(int x) {}
1661 A operator -(int x) {} 1667 A operator -(int x) {}
1662 A operator -() {} 1668 A operator -() {}
1663 } 1669 }
1664 1670
1665 foo() => new A(); 1671 foo() => new A();
1666 1672
1667 test() { 1673 test() {
(...skipping 11 matching lines...) Expand all
1679 1685
1680 ++a; 1686 ++a;
1681 --a; 1687 --a;
1682 (/*info:DYNAMIC_INVOKE*/++d); 1688 (/*info:DYNAMIC_INVOKE*/++d);
1683 (/*info:DYNAMIC_INVOKE*/--d); 1689 (/*info:DYNAMIC_INVOKE*/--d);
1684 1690
1685 a++; 1691 a++;
1686 a--; 1692 a--;
1687 (/*info:DYNAMIC_INVOKE*/d++); 1693 (/*info:DYNAMIC_INVOKE*/d++);
1688 (/*info:DYNAMIC_INVOKE*/d--); 1694 (/*info:DYNAMIC_INVOKE*/d--);
1689 }''' 1695 }''');
1690 }); 1696 });
1691 1697
1692 testChecker('binary and index operators', { 1698 test('binary and index operators', () {
1693 '/main.dart': ''' 1699 checkFile('''
1694 class A { 1700 class A {
1695 A operator *(B b) {} 1701 A operator *(B b) {}
1696 A operator /(B b) {} 1702 A operator /(B b) {}
1697 A operator ~/(B b) {} 1703 A operator ~/(B b) {}
1698 A operator %(B b) {} 1704 A operator %(B b) {}
1699 A operator +(B b) {} 1705 A operator +(B b) {}
1700 A operator -(B b) {} 1706 A operator -(B b) {}
1701 A operator <<(B b) {} 1707 A operator <<(B b) {}
1702 A operator >>(B b) {} 1708 A operator >>(B b) {}
1703 A operator &(B b) {} 1709 A operator &(B b) {}
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 p = (/*info:DYNAMIC_CAST*/c) && p; 1750 p = (/*info:DYNAMIC_CAST*/c) && p;
1745 p = (/*info:DYNAMIC_CAST*/c) && /*info:DYNAMIC_CAST*/c; 1751 p = (/*info:DYNAMIC_CAST*/c) && /*info:DYNAMIC_CAST*/c;
1746 p = (/*severe:STATIC_TYPE_ERROR*/y) && p; 1752 p = (/*severe:STATIC_TYPE_ERROR*/y) && p;
1747 p = c == y; 1753 p = c == y;
1748 1754
1749 a = a[b]; 1755 a = a[b];
1750 a = a[/*info:DYNAMIC_CAST*/c]; 1756 a = a[/*info:DYNAMIC_CAST*/c];
1751 c = (/*info:DYNAMIC_INVOKE*/c[b]); 1757 c = (/*info:DYNAMIC_INVOKE*/c[b]);
1752 a[/*severe:STATIC_TYPE_ERROR*/y]; 1758 a[/*severe:STATIC_TYPE_ERROR*/y];
1753 } 1759 }
1754 ''' 1760 ''');
1755 }); 1761 });
1756 1762
1757 testChecker('null coalescing operator', { 1763 test('null coalescing operator', () {
1758 '/main.dart': ''' 1764 checkFile('''
1759 class A {} 1765 class A {}
1760 class C<T> {} 1766 class C<T> {}
1761 main() { 1767 main() {
1762 A a, b; 1768 A a, b;
1763 a ??= new A(); 1769 a ??= new A();
1764 b = b ?? new A(); 1770 b = b ?? new A();
1765 1771
1766 // downwards inference 1772 // downwards inference
1767 C<int> c, d; 1773 C<int> c, d;
1768 c ??= /*info:INFERRED_TYPE_ALLOCATION*/new C(); 1774 c ??= /*info:INFERRED_TYPE_ALLOCATION*/new C();
1769 d = d ?? /*info:INFERRED_TYPE_ALLOCATION*/new C(); 1775 d = d ?? /*info:INFERRED_TYPE_ALLOCATION*/new C();
1770 } 1776 }
1771 ''' 1777 ''');
1772 }); 1778 });
1773 1779
1774 testChecker('compound assignments', { 1780 test('compound assignments', () {
1775 '/main.dart': ''' 1781 checkFile('''
1776 class A { 1782 class A {
1777 A operator *(B b) {} 1783 A operator *(B b) {}
1778 A operator /(B b) {} 1784 A operator /(B b) {}
1779 A operator ~/(B b) {} 1785 A operator ~/(B b) {}
1780 A operator %(B b) {} 1786 A operator %(B b) {}
1781 A operator +(B b) {} 1787 A operator +(B b) {}
1782 A operator -(B b) {} 1788 A operator -(B b) {}
1783 A operator <<(B b) {} 1789 A operator <<(B b) {}
1784 A operator >>(B b) {} 1790 A operator >>(B b) {}
1785 A operator &(B b) {} 1791 A operator &(B b) {}
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 (/*info:DYNAMIC_INVOKE*/c += b); 1849 (/*info:DYNAMIC_INVOKE*/c += b);
1844 1850
1845 var d = new D(); 1851 var d = new D();
1846 a[b] += d; 1852 a[b] += d;
1847 a[/*info:DYNAMIC_CAST*/c] += d; 1853 a[/*info:DYNAMIC_CAST*/c] += d;
1848 a[/*severe:STATIC_TYPE_ERROR*/z] += d; 1854 a[/*severe:STATIC_TYPE_ERROR*/z] += d;
1849 a[b] += /*info:DYNAMIC_CAST*/c; 1855 a[b] += /*info:DYNAMIC_CAST*/c;
1850 a[b] += /*severe:STATIC_TYPE_ERROR*/z; 1856 a[b] += /*severe:STATIC_TYPE_ERROR*/z;
1851 (/*info:DYNAMIC_INVOKE*/(/*info:DYNAMIC_INVOKE*/c[b]) += d); 1857 (/*info:DYNAMIC_INVOKE*/(/*info:DYNAMIC_INVOKE*/c[b]) += d);
1852 } 1858 }
1853 ''' 1859 ''');
1854 }); 1860 });
1855 1861
1856 testChecker('super call placement', { 1862 test('super call placement', () {
1857 '/main.dart': ''' 1863 checkFile('''
1858 class Base { 1864 class Base {
1859 var x; 1865 var x;
1860 Base() : x = print('Base.1') { print('Base.2'); } 1866 Base() : x = print('Base.1') { print('Base.2'); }
1861 } 1867 }
1862 1868
1863 class Derived extends Base { 1869 class Derived extends Base {
1864 var y, z; 1870 var y, z;
1865 Derived() 1871 Derived()
1866 : y = print('Derived.1'), 1872 : y = print('Derived.1'),
1867 /*severe:INVALID_SUPER_INVOCATION*/super(), 1873 /*severe:INVALID_SUPER_INVOCATION*/super(),
(...skipping 10 matching lines...) Expand all
1878 super() { 1884 super() {
1879 print('Valid.3'); 1885 print('Valid.3');
1880 } 1886 }
1881 } 1887 }
1882 1888
1883 class AlsoValid extends Base { 1889 class AlsoValid extends Base {
1884 AlsoValid() : super(); 1890 AlsoValid() : super();
1885 } 1891 }
1886 1892
1887 main() => new Derived(); 1893 main() => new Derived();
1888 ''' 1894 ''');
1889 }); 1895 });
1890 1896
1891 testChecker('for loop variable', { 1897 test('for loop variable', () {
1892 '/main.dart': ''' 1898 checkFile('''
1893 foo() { 1899 foo() {
1894 for (int i = 0; i < 10; i++) { 1900 for (int i = 0; i < 10; i++) {
1895 i = /*severe:STATIC_TYPE_ERROR*/"hi"; 1901 i = /*severe:STATIC_TYPE_ERROR*/"hi";
1896 } 1902 }
1897 } 1903 }
1898 bar() { 1904 bar() {
1899 for (var i = 0; i < 10; i++) { 1905 for (var i = 0; i < 10; i++) {
1900 int j = i + 1; 1906 int j = i + 1;
1901 } 1907 }
1902 } 1908 }
1903 ''' 1909 ''');
1904 }); 1910 });
1905 1911
1906 testChecker('loadLibrary', { 1912 test('loadLibrary', () {
1907 '/lib1.dart': '''library lib1;''', 1913 addFile('''library lib1;''', name: '/lib1.dart');
1908 '/main.dart': r''' 1914 checkFile(r'''
1909 import 'lib1.dart' deferred as lib1; 1915 import 'lib1.dart' deferred as lib1;
1910 main() { 1916 main() {
1911 Future f = lib1.loadLibrary(); 1917 Future f = lib1.loadLibrary();
1912 }''' 1918 }''');
1913 }); 1919 });
1914 1920
1915 group('invalid overrides', () { 1921 group('invalid overrides', () {
1916 testChecker('child override', { 1922 test('child override', () {
1917 '/main.dart': ''' 1923 checkFile('''
1918 class A {} 1924 class A {}
1919 class B {} 1925 class B {}
1920 1926
1921 class Base { 1927 class Base {
1922 A f; 1928 A f;
1923 } 1929 }
1924 1930
1925 class T1 extends Base { 1931 class T1 extends Base {
1926 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B get f => null; 1932 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B get f => null;
1927 } 1933 }
(...skipping 18 matching lines...) Expand all
1946 /*severe:INVALID_METHOD_OVERRIDE*/set f(B b) => null; 1952 /*severe:INVALID_METHOD_OVERRIDE*/set f(B b) => null;
1947 } 1953 }
1948 1954
1949 class T7 implements Base { 1955 class T7 implements Base {
1950 /*severe:INVALID_METHOD_OVERRIDE*/final B f; 1956 /*severe:INVALID_METHOD_OVERRIDE*/final B f;
1951 } 1957 }
1952 class T8 implements Base { 1958 class T8 implements Base {
1953 // two: one for the getter one for the setter. 1959 // two: one for the getter one for the setter.
1954 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B f; 1960 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B f;
1955 } 1961 }
1956 ''' 1962 ''');
1957 }); 1963 });
1958 1964
1959 testChecker('child override 2', { 1965 test('child override 2', () {
1960 '/main.dart': ''' 1966 checkFile('''
1961 class A {} 1967 class A {}
1962 class B {} 1968 class B {}
1963 1969
1964 class Base { 1970 class Base {
1965 m(A a) {} 1971 m(A a) {}
1966 } 1972 }
1967 1973
1968 class Test extends Base { 1974 class Test extends Base {
1969 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 1975 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1970 } 1976 }
1971 ''' 1977 ''');
1972 }); 1978 });
1973 testChecker('grandchild override', { 1979 test('grandchild override', () {
1974 '/main.dart': ''' 1980 checkFile('''
1975 class A {} 1981 class A {}
1976 class B {} 1982 class B {}
1977 1983
1978 class Grandparent { 1984 class Grandparent {
1979 m(A a) {} 1985 m(A a) {}
1980 int x; 1986 int x;
1981 } 1987 }
1982 class Parent extends Grandparent { 1988 class Parent extends Grandparent {
1983 } 1989 }
1984 1990
1985 class Test extends Parent { 1991 class Test extends Parent {
1986 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 1992 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
1987 /*severe:INVALID_FIELD_OVERRIDE*/int x; 1993 /*severe:INVALID_FIELD_OVERRIDE*/int x;
1988 } 1994 }
1989 ''' 1995 ''');
1990 }); 1996 });
1991 1997
1992 testChecker('double override', { 1998 test('double override', () {
1993 '/main.dart': ''' 1999 checkFile('''
1994 class A {} 2000 class A {}
1995 class B {} 2001 class B {}
1996 2002
1997 class Grandparent { 2003 class Grandparent {
1998 m(A a) {} 2004 m(A a) {}
1999 } 2005 }
2000 class Parent extends Grandparent { 2006 class Parent extends Grandparent {
2001 m(A a) {} 2007 m(A a) {}
2002 } 2008 }
2003 2009
2004 class Test extends Parent { 2010 class Test extends Parent {
2005 // Reported only once 2011 // Reported only once
2006 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2012 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2007 } 2013 }
2008 ''' 2014 ''');
2009 }); 2015 });
2010 2016
2011 testChecker('double override 2', { 2017 test('double override 2', () {
2012 '/main.dart': ''' 2018 checkFile('''
2013 class A {} 2019 class A {}
2014 class B {} 2020 class B {}
2015 2021
2016 class Grandparent { 2022 class Grandparent {
2017 m(A a) {} 2023 m(A a) {}
2018 } 2024 }
2019 class Parent extends Grandparent { 2025 class Parent extends Grandparent {
2020 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2026 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2021 } 2027 }
2022 2028
2023 class Test extends Parent { 2029 class Test extends Parent {
2024 m(B a) {} 2030 m(B a) {}
2025 } 2031 }
2026 ''' 2032 ''');
2027 }); 2033 });
2028 2034
2029 testChecker('mixin override to base', { 2035 test('mixin override to base', () {
2030 '/main.dart': ''' 2036 checkFile('''
2031 class A {} 2037 class A {}
2032 class B {} 2038 class B {}
2033 2039
2034 class Base { 2040 class Base {
2035 m(A a) {} 2041 m(A a) {}
2036 int x; 2042 int x;
2037 } 2043 }
2038 2044
2039 class M1 { 2045 class M1 {
2040 m(B a) {} 2046 m(B a) {}
2041 } 2047 }
2042 2048
2043 class M2 { 2049 class M2 {
2044 int x; 2050 int x;
2045 } 2051 }
2046 2052
2047 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1 {} 2053 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1 {}
2048 class T2 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1, /*s evere:INVALID_FIELD_OVERRIDE*/M2 {} 2054 class T2 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1, /*s evere:INVALID_FIELD_OVERRIDE*/M2 {}
2049 class T3 extends Base with /*severe:INVALID_FIELD_OVERRIDE*/M2, /*se vere:INVALID_METHOD_OVERRIDE*/M1 {} 2055 class T3 extends Base with /*severe:INVALID_FIELD_OVERRIDE*/M2, /*se vere:INVALID_METHOD_OVERRIDE*/M1 {}
2050 ''' 2056 ''');
2051 }); 2057 });
2052 2058
2053 testChecker('mixin override to mixin', { 2059 test('mixin override to mixin', () {
2054 '/main.dart': ''' 2060 checkFile('''
2055 class A {} 2061 class A {}
2056 class B {} 2062 class B {}
2057 2063
2058 class Base { 2064 class Base {
2059 } 2065 }
2060 2066
2061 class M1 { 2067 class M1 {
2062 m(B a) {} 2068 m(B a) {}
2063 int x; 2069 int x;
2064 } 2070 }
2065 2071
2066 class M2 { 2072 class M2 {
2067 m(A a) {} 2073 m(A a) {}
2068 int x; 2074 int x;
2069 } 2075 }
2070 2076
2071 class T1 extends Base with M1, /*severe:INVALID_METHOD_OVERRIDE,seve re:INVALID_FIELD_OVERRIDE*/M2 {} 2077 class T1 extends Base with M1, /*severe:INVALID_METHOD_OVERRIDE,seve re:INVALID_FIELD_OVERRIDE*/M2 {}
2072 ''' 2078 ''');
2073 }); 2079 });
2074 2080
2075 // This is a regression test for a bug in an earlier implementation were 2081 // This is a regression test for a bug in an earlier implementation were
2076 // names were hiding errors if the first mixin override looked correct, 2082 // names were hiding errors if the first mixin override looked correct,
2077 // but subsequent ones did not. 2083 // but subsequent ones did not.
2078 testChecker('no duplicate mixin override', { 2084 test('no duplicate mixin override', () {
2079 '/main.dart': ''' 2085 checkFile('''
2080 class A {} 2086 class A {}
2081 class B {} 2087 class B {}
2082 2088
2083 class Base { 2089 class Base {
2084 m(A a) {} 2090 m(A a) {}
2085 } 2091 }
2086 2092
2087 class M1 { 2093 class M1 {
2088 m(A a) {} 2094 m(A a) {}
2089 } 2095 }
2090 2096
2091 class M2 { 2097 class M2 {
2092 m(B a) {} 2098 m(B a) {}
2093 } 2099 }
2094 2100
2095 class M3 { 2101 class M3 {
2096 m(B a) {} 2102 m(B a) {}
2097 } 2103 }
2098 2104
2099 class T1 extends Base 2105 class T1 extends Base
2100 with M1, /*severe:INVALID_METHOD_OVERRIDE*/M2, M3 {} 2106 with M1, /*severe:INVALID_METHOD_OVERRIDE*/M2, M3 {}
2101 ''' 2107 ''');
2102 }); 2108 });
2103 2109
2104 testChecker('class override of interface', { 2110 test('class override of interface', () {
2105 '/main.dart': ''' 2111 checkFile('''
2106 class A {} 2112 class A {}
2107 class B {} 2113 class B {}
2108 2114
2109 abstract class I { 2115 abstract class I {
2110 m(A a); 2116 m(A a);
2111 } 2117 }
2112 2118
2113 class T1 implements I { 2119 class T1 implements I {
2114 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2120 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2115 } 2121 }
2116 ''' 2122 ''');
2117 }); 2123 });
2118 2124
2119 testChecker('base class override to child interface', { 2125 test('base class override to child interface', () {
2120 '/main.dart': ''' 2126 checkFile('''
2121 class A {} 2127 class A {}
2122 class B {} 2128 class B {}
2123 2129
2124 abstract class I { 2130 abstract class I {
2125 m(A a); 2131 m(A a);
2126 } 2132 }
2127 2133
2128 class Base { 2134 class Base {
2129 m(B a) {} 2135 m(B a) {}
2130 } 2136 }
2131 2137
2132 2138
2133 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I { 2139 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I {
2134 } 2140 }
2135 ''' 2141 ''');
2136 }); 2142 });
2137 2143
2138 testChecker('mixin override of interface', { 2144 test('mixin override of interface', () {
2139 '/main.dart': ''' 2145 checkFile('''
2140 class A {} 2146 class A {}
2141 class B {} 2147 class B {}
2142 2148
2143 abstract class I { 2149 abstract class I {
2144 m(A a); 2150 m(A a);
2145 } 2151 }
2146 2152
2147 class M { 2153 class M {
2148 m(B a) {} 2154 m(B a) {}
2149 } 2155 }
2150 2156
2151 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2157 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2152 implements I {} 2158 implements I {}
2153 ''' 2159 ''');
2154 }); 2160 });
2155 2161
2156 // This is a case were it is incorrect to say that the base class 2162 // This is a case were it is incorrect to say that the base class
2157 // incorrectly overrides the interface. 2163 // incorrectly overrides the interface.
2158 testChecker( 2164 test('no errors if subclass correctly overrides base and interface', () {
2159 'no errors if subclass correctly overrides base and interface', { 2165 checkFile('''
2160 '/main.dart': '''
2161 class A {} 2166 class A {}
2162 class B {} 2167 class B {}
2163 2168
2164 class Base { 2169 class Base {
2165 m(A a) {} 2170 m(A a) {}
2166 } 2171 }
2167 2172
2168 class I1 { 2173 class I1 {
2169 m(B a) {} 2174 m(B a) {}
2170 } 2175 }
2171 2176
2172 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2177 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2173 implements I1 {} 2178 implements I1 {}
2174 2179
2175 class T2 extends Base implements I1 { 2180 class T2 extends Base implements I1 {
2176 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} 2181 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {}
2177 } 2182 }
2178 2183
2179 class T3 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base 2184 class T3 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base
2180 implements I1 {} 2185 implements I1 {}
2181 2186
2182 class T4 extends Object with Base implements I1 { 2187 class T4 extends Object with Base implements I1 {
2183 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} 2188 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {}
2184 } 2189 }
2185 ''' 2190 ''');
2186 }); 2191 });
2187 }); 2192 });
2188 2193
2189 group('class override of grand interface', () { 2194 group('class override of grand interface', () {
2190 testChecker('interface of interface of child', { 2195 test('interface of interface of child', () {
2191 '/main.dart': ''' 2196 checkFile('''
2192 class A {} 2197 class A {}
2193 class B {} 2198 class B {}
2194 2199
2195 abstract class I1 { 2200 abstract class I1 {
2196 m(A a); 2201 m(A a);
2197 } 2202 }
2198 abstract class I2 implements I1 {} 2203 abstract class I2 implements I1 {}
2199 2204
2200 class T1 implements I2 { 2205 class T1 implements I2 {
2201 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2206 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2202 } 2207 }
2203 ''' 2208 ''');
2204 }); 2209 });
2205 testChecker('superclass of interface of child', { 2210 test('superclass of interface of child', () {
2206 '/main.dart': ''' 2211 checkFile('''
2207 class A {} 2212 class A {}
2208 class B {} 2213 class B {}
2209 2214
2210 abstract class I1 { 2215 abstract class I1 {
2211 m(A a); 2216 m(A a);
2212 } 2217 }
2213 abstract class I2 extends I1 {} 2218 abstract class I2 extends I1 {}
2214 2219
2215 class T1 implements I2 { 2220 class T1 implements I2 {
2216 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2221 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2217 } 2222 }
2218 ''' 2223 ''');
2219 }); 2224 });
2220 testChecker('mixin of interface of child', { 2225 test('mixin of interface of child', () {
2221 '/main.dart': ''' 2226 checkFile('''
2222 class A {} 2227 class A {}
2223 class B {} 2228 class B {}
2224 2229
2225 abstract class M1 { 2230 abstract class M1 {
2226 m(A a); 2231 m(A a);
2227 } 2232 }
2228 abstract class I2 extends Object with M1 {} 2233 abstract class I2 extends Object with M1 {}
2229 2234
2230 class T1 implements I2 { 2235 class T1 implements I2 {
2231 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2236 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2232 } 2237 }
2233 ''' 2238 ''');
2234 }); 2239 });
2235 testChecker('interface of abstract superclass', { 2240 test('interface of abstract superclass', () {
2236 '/main.dart': ''' 2241 checkFile('''
2237 class A {} 2242 class A {}
2238 class B {} 2243 class B {}
2239 2244
2240 abstract class I1 { 2245 abstract class I1 {
2241 m(A a); 2246 m(A a);
2242 } 2247 }
2243 abstract class Base implements I1 {} 2248 abstract class Base implements I1 {}
2244 2249
2245 class T1 extends Base { 2250 class T1 extends Base {
2246 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2251 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2247 } 2252 }
2248 ''' 2253 ''');
2249 }); 2254 });
2250 testChecker('interface of concrete superclass', { 2255 test('interface of concrete superclass', () {
2251 '/main.dart': ''' 2256 checkFile('''
2252 class A {} 2257 class A {}
2253 class B {} 2258 class B {}
2254 2259
2255 abstract class I1 { 2260 abstract class I1 {
2256 m(A a); 2261 m(A a);
2257 } 2262 }
2258 2263
2259 // See issue #25 2264 // See issue #25
2260 /*pass should be warning:AnalyzerError*/class Base implements I1 { 2265 /*pass should be warning:AnalyzerError*/class Base implements I1 {
2261 } 2266 }
2262 2267
2263 class T1 extends Base { 2268 class T1 extends Base {
2264 // not reported technically because if the class is concrete, 2269 // not reported technically because if the class is concrete,
2265 // it should implement all its interfaces and hence it is 2270 // it should implement all its interfaces and hence it is
2266 // sufficient to check overrides against it. 2271 // sufficient to check overrides against it.
2267 m(B a) {} 2272 m(B a) {}
2268 } 2273 }
2269 ''' 2274 ''');
2270 }); 2275 });
2271 }); 2276 });
2272 2277
2273 group('mixin override of grand interface', () { 2278 group('mixin override of grand interface', () {
2274 testChecker('interface of interface of child', { 2279 test('interface of interface of child', () {
2275 '/main.dart': ''' 2280 checkFile('''
2276 class A {} 2281 class A {}
2277 class B {} 2282 class B {}
2278 2283
2279 abstract class I1 { 2284 abstract class I1 {
2280 m(A a); 2285 m(A a);
2281 } 2286 }
2282 abstract class I2 implements I1 {} 2287 abstract class I2 implements I1 {}
2283 2288
2284 class M { 2289 class M {
2285 m(B a) {} 2290 m(B a) {}
2286 } 2291 }
2287 2292
2288 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2293 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2289 implements I2 { 2294 implements I2 {
2290 } 2295 }
2291 ''' 2296 ''');
2292 }); 2297 });
2293 testChecker('superclass of interface of child', { 2298 test('superclass of interface of child', () {
2294 '/main.dart': ''' 2299 checkFile('''
2295 class A {} 2300 class A {}
2296 class B {} 2301 class B {}
2297 2302
2298 abstract class I1 { 2303 abstract class I1 {
2299 m(A a); 2304 m(A a);
2300 } 2305 }
2301 abstract class I2 extends I1 {} 2306 abstract class I2 extends I1 {}
2302 2307
2303 class M { 2308 class M {
2304 m(B a) {} 2309 m(B a) {}
2305 } 2310 }
2306 2311
2307 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2312 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2308 implements I2 { 2313 implements I2 {
2309 } 2314 }
2310 ''' 2315 ''');
2311 }); 2316 });
2312 testChecker('mixin of interface of child', { 2317 test('mixin of interface of child', () {
2313 '/main.dart': ''' 2318 checkFile('''
2314 class A {} 2319 class A {}
2315 class B {} 2320 class B {}
2316 2321
2317 abstract class M1 { 2322 abstract class M1 {
2318 m(A a); 2323 m(A a);
2319 } 2324 }
2320 abstract class I2 extends Object with M1 {} 2325 abstract class I2 extends Object with M1 {}
2321 2326
2322 class M { 2327 class M {
2323 m(B a) {} 2328 m(B a) {}
2324 } 2329 }
2325 2330
2326 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2331 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2327 implements I2 { 2332 implements I2 {
2328 } 2333 }
2329 ''' 2334 ''');
2330 }); 2335 });
2331 testChecker('interface of abstract superclass', { 2336 test('interface of abstract superclass', () {
2332 '/main.dart': ''' 2337 checkFile('''
2333 class A {} 2338 class A {}
2334 class B {} 2339 class B {}
2335 2340
2336 abstract class I1 { 2341 abstract class I1 {
2337 m(A a); 2342 m(A a);
2338 } 2343 }
2339 abstract class Base implements I1 {} 2344 abstract class Base implements I1 {}
2340 2345
2341 class M { 2346 class M {
2342 m(B a) {} 2347 m(B a) {}
2343 } 2348 }
2344 2349
2345 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M { 2350 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M {
2346 } 2351 }
2347 ''' 2352 ''');
2348 }); 2353 });
2349 testChecker('interface of concrete superclass', { 2354 test('interface of concrete superclass', () {
2350 '/main.dart': ''' 2355 checkFile('''
2351 class A {} 2356 class A {}
2352 class B {} 2357 class B {}
2353 2358
2354 abstract class I1 { 2359 abstract class I1 {
2355 m(A a); 2360 m(A a);
2356 } 2361 }
2357 2362
2358 // See issue #25 2363 // See issue #25
2359 /*pass should be warning:AnalyzerError*/class Base implements I1 { 2364 /*pass should be warning:AnalyzerError*/class Base implements I1 {
2360 } 2365 }
2361 2366
2362 class M { 2367 class M {
2363 m(B a) {} 2368 m(B a) {}
2364 } 2369 }
2365 2370
2366 class T1 extends Base with M { 2371 class T1 extends Base with M {
2367 } 2372 }
2368 ''' 2373 ''');
2369 }); 2374 });
2370 }); 2375 });
2371 2376
2372 group('superclass override of grand interface', () { 2377 group('superclass override of grand interface', () {
2373 testChecker('interface of interface of child', { 2378 test('interface of interface of child', () {
2374 '/main.dart': ''' 2379 checkFile('''
2375 class A {} 2380 class A {}
2376 class B {} 2381 class B {}
2377 2382
2378 abstract class I1 { 2383 abstract class I1 {
2379 m(A a); 2384 m(A a);
2380 } 2385 }
2381 abstract class I2 implements I1 {} 2386 abstract class I2 implements I1 {}
2382 2387
2383 class Base { 2388 class Base {
2384 m(B a) {} 2389 m(B a) {}
2385 } 2390 }
2386 2391
2387 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2392 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2388 implements I2 { 2393 implements I2 {
2389 } 2394 }
2390 ''' 2395 ''');
2391 }); 2396 });
2392 testChecker('superclass of interface of child', { 2397 test('superclass of interface of child', () {
2393 '/main.dart': ''' 2398 checkFile('''
2394 class A {} 2399 class A {}
2395 class B {} 2400 class B {}
2396 2401
2397 abstract class I1 { 2402 abstract class I1 {
2398 m(A a); 2403 m(A a);
2399 } 2404 }
2400 abstract class I2 extends I1 {} 2405 abstract class I2 extends I1 {}
2401 2406
2402 class Base { 2407 class Base {
2403 m(B a) {} 2408 m(B a) {}
2404 } 2409 }
2405 2410
2406 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2411 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2407 implements I2 { 2412 implements I2 {
2408 } 2413 }
2409 ''' 2414 ''');
2410 }); 2415 });
2411 testChecker('mixin of interface of child', { 2416 test('mixin of interface of child', () {
2412 '/main.dart': ''' 2417 checkFile('''
2413 class A {} 2418 class A {}
2414 class B {} 2419 class B {}
2415 2420
2416 abstract class M1 { 2421 abstract class M1 {
2417 m(A a); 2422 m(A a);
2418 } 2423 }
2419 abstract class I2 extends Object with M1 {} 2424 abstract class I2 extends Object with M1 {}
2420 2425
2421 class Base { 2426 class Base {
2422 m(B a) {} 2427 m(B a) {}
2423 } 2428 }
2424 2429
2425 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2430 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2426 implements I2 { 2431 implements I2 {
2427 } 2432 }
2428 ''' 2433 ''');
2429 }); 2434 });
2430 testChecker('interface of abstract superclass', { 2435 test('interface of abstract superclass', () {
2431 '/main.dart': ''' 2436 checkFile('''
2432 class A {} 2437 class A {}
2433 class B {} 2438 class B {}
2434 2439
2435 abstract class I1 { 2440 abstract class I1 {
2436 m(A a); 2441 m(A a);
2437 } 2442 }
2438 2443
2439 abstract class Base implements I1 { 2444 abstract class Base implements I1 {
2440 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2445 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2441 } 2446 }
2442 2447
2443 class T1 extends Base { 2448 class T1 extends Base {
2444 // we consider the base class incomplete because it is 2449 // we consider the base class incomplete because it is
2445 // abstract, so we report the error here too. 2450 // abstract, so we report the error here too.
2446 // TODO(sigmund): consider tracking overrides in a fine-grain 2451 // TODO(sigmund): consider tracking overrides in a fine-grain
2447 // manner, then this and the double-overrides would not be 2452 // manner, then this and the double-overrides would not be
2448 // reported. 2453 // reported.
2449 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2454 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2450 } 2455 }
2451 ''' 2456 ''');
2452 }); 2457 });
2453 testChecker('interface of concrete superclass', { 2458 test('interface of concrete superclass', () {
2454 '/main.dart': ''' 2459 checkFile('''
2455 class A {} 2460 class A {}
2456 class B {} 2461 class B {}
2457 2462
2458 abstract class I1 { 2463 abstract class I1 {
2459 m(A a); 2464 m(A a);
2460 } 2465 }
2461 2466
2462 class Base implements I1 { 2467 class Base implements I1 {
2463 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2468 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2464 } 2469 }
2465 2470
2466 class T1 extends Base { 2471 class T1 extends Base {
2467 m(B a) {} 2472 m(B a) {}
2468 } 2473 }
2469 ''' 2474 ''');
2470 }); 2475 });
2471 }); 2476 });
2472 2477
2473 group('no duplicate reports from overriding interfaces', () { 2478 group('no duplicate reports from overriding interfaces', () {
2474 testChecker('type overrides same method in multiple interfaces', { 2479 test('type overrides same method in multiple interfaces', () {
2475 '/main.dart': ''' 2480 checkFile('''
2476 class A {} 2481 class A {}
2477 class B {} 2482 class B {}
2478 2483
2479 abstract class I1 { 2484 abstract class I1 {
2480 m(A a); 2485 m(A a);
2481 } 2486 }
2482 abstract class I2 implements I1 { 2487 abstract class I2 implements I1 {
2483 m(A a); 2488 m(A a);
2484 } 2489 }
2485 2490
2486 class Base { 2491 class Base {
2487 } 2492 }
2488 2493
2489 class T1 implements I2 { 2494 class T1 implements I2 {
2490 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2495 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2491 } 2496 }
2492 ''' 2497 ''');
2493 }); 2498 });
2494 2499
2495 testChecker('type and base type override same method in interface', { 2500 test('type and base type override same method in interface', () {
2496 '/main.dart': ''' 2501 checkFile('''
2497 class A {} 2502 class A {}
2498 class B {} 2503 class B {}
2499 2504
2500 abstract class I1 { 2505 abstract class I1 {
2501 m(A a); 2506 m(A a);
2502 } 2507 }
2503 2508
2504 class Base { 2509 class Base {
2505 m(B a); 2510 m(B a);
2506 } 2511 }
2507 2512
2508 // Note: no error reported in `extends Base` to avoid duplicating 2513 // Note: no error reported in `extends Base` to avoid duplicating
2509 // the error in T1. 2514 // the error in T1.
2510 class T1 extends Base implements I1 { 2515 class T1 extends Base implements I1 {
2511 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2516 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2512 } 2517 }
2513 2518
2514 // If there is no error in the class, we do report the error at 2519 // If there is no error in the class, we do report the error at
2515 // the base class: 2520 // the base class:
2516 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2521 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2517 implements I1 { 2522 implements I1 {
2518 } 2523 }
2519 ''' 2524 ''');
2520 }); 2525 });
2521 2526
2522 testChecker('type and mixin override same method in interface', { 2527 test('type and mixin override same method in interface', () {
2523 '/main.dart': ''' 2528 checkFile('''
2524 class A {} 2529 class A {}
2525 class B {} 2530 class B {}
2526 2531
2527 abstract class I1 { 2532 abstract class I1 {
2528 m(A a); 2533 m(A a);
2529 } 2534 }
2530 2535
2531 class M { 2536 class M {
2532 m(B a); 2537 m(B a);
2533 } 2538 }
2534 2539
2535 class T1 extends Object with M implements I1 { 2540 class T1 extends Object with M implements I1 {
2536 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2541 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2537 } 2542 }
2538 2543
2539 class T2 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2544 class T2 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2540 implements I1 { 2545 implements I1 {
2541 } 2546 }
2542 ''' 2547 ''');
2543 }); 2548 });
2544 2549
2545 testChecker('two grand types override same method in interface', { 2550 test('two grand types override same method in interface', () {
2546 '/main.dart': ''' 2551 checkFile('''
2547 class A {} 2552 class A {}
2548 class B {} 2553 class B {}
2549 2554
2550 abstract class I1 { 2555 abstract class I1 {
2551 m(A a); 2556 m(A a);
2552 } 2557 }
2553 2558
2554 class Grandparent { 2559 class Grandparent {
2555 m(B a) {} 2560 m(B a) {}
2556 } 2561 }
2557 2562
2558 class Parent1 extends Grandparent { 2563 class Parent1 extends Grandparent {
2559 m(B a) {} 2564 m(B a) {}
2560 } 2565 }
2561 class Parent2 extends Grandparent { 2566 class Parent2 extends Grandparent {
2562 } 2567 }
2563 2568
2564 // Note: otherwise both errors would be reported on this line 2569 // Note: otherwise both errors would be reported on this line
2565 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent1 2570 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent1
2566 implements I1 { 2571 implements I1 {
2567 } 2572 }
2568 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent2 2573 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent2
2569 implements I1 { 2574 implements I1 {
2570 } 2575 }
2571 ''' 2576 ''');
2572 }); 2577 });
2573 2578
2574 testChecker('two mixins override same method in interface', { 2579 test('two mixins override same method in interface', () {
2575 '/main.dart': ''' 2580 checkFile('''
2576 class A {} 2581 class A {}
2577 class B {} 2582 class B {}
2578 2583
2579 abstract class I1 { 2584 abstract class I1 {
2580 m(A a); 2585 m(A a);
2581 } 2586 }
2582 2587
2583 class M1 { 2588 class M1 {
2584 m(B a) {} 2589 m(B a) {}
2585 } 2590 }
2586 2591
2587 class M2 { 2592 class M2 {
2588 m(B a) {} 2593 m(B a) {}
2589 } 2594 }
2590 2595
2591 // Here we want to report both, because the error location is 2596 // Here we want to report both, because the error location is
2592 // different. 2597 // different.
2593 // TODO(sigmund): should we merge these as well? 2598 // TODO(sigmund): should we merge these as well?
2594 class T1 extends Object 2599 class T1 extends Object
2595 with /*severe:INVALID_METHOD_OVERRIDE*/M1 2600 with /*severe:INVALID_METHOD_OVERRIDE*/M1
2596 with /*severe:INVALID_METHOD_OVERRIDE*/M2 2601 with /*severe:INVALID_METHOD_OVERRIDE*/M2
2597 implements I1 { 2602 implements I1 {
2598 } 2603 }
2599 ''' 2604 ''');
2600 }); 2605 });
2601 2606
2602 testChecker('base type and mixin override same method in interface', { 2607 test('base type and mixin override same method in interface', () {
2603 '/main.dart': ''' 2608 checkFile('''
2604 class A {} 2609 class A {}
2605 class B {} 2610 class B {}
2606 2611
2607 abstract class I1 { 2612 abstract class I1 {
2608 m(A a); 2613 m(A a);
2609 } 2614 }
2610 2615
2611 class Base { 2616 class Base {
2612 m(B a) {} 2617 m(B a) {}
2613 } 2618 }
2614 2619
2615 class M { 2620 class M {
2616 m(B a) {} 2621 m(B a) {}
2617 } 2622 }
2618 2623
2619 // Here we want to report both, because the error location is 2624 // Here we want to report both, because the error location is
2620 // different. 2625 // different.
2621 // TODO(sigmund): should we merge these as well? 2626 // TODO(sigmund): should we merge these as well?
2622 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2627 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2623 with /*severe:INVALID_METHOD_OVERRIDE*/M 2628 with /*severe:INVALID_METHOD_OVERRIDE*/M
2624 implements I1 { 2629 implements I1 {
2625 } 2630 }
2626 ''' 2631 ''');
2627 }); 2632 });
2628 }); 2633 });
2629 2634
2630 testChecker('invalid runtime checks', { 2635 test('invalid runtime checks', () {
2631 '/main.dart': ''' 2636 checkFile('''
2632 typedef int I2I(int x); 2637 typedef int I2I(int x);
2633 typedef int D2I(x); 2638 typedef int D2I(x);
2634 typedef int II2I(int x, int y); 2639 typedef int II2I(int x, int y);
2635 typedef int DI2I(x, int y); 2640 typedef int DI2I(x, int y);
2636 typedef int ID2I(int x, y); 2641 typedef int ID2I(int x, y);
2637 typedef int DD2I(x, y); 2642 typedef int DD2I(x, y);
2638 2643
2639 typedef I2D(int x); 2644 typedef I2D(int x);
2640 typedef D2D(x); 2645 typedef D2D(x);
2641 typedef II2D(int x, int y); 2646 typedef II2D(int x, int y);
(...skipping 29 matching lines...) Expand all
2671 2676
2672 f = bar as II2I; 2677 f = bar as II2I;
2673 f = bar as DI2I; 2678 f = bar as DI2I;
2674 f = bar as ID2I; 2679 f = bar as ID2I;
2675 f = bar as II2D; 2680 f = bar as II2D;
2676 f = bar as DD2I; 2681 f = bar as DD2I;
2677 f = bar as DI2D; 2682 f = bar as DI2D;
2678 f = bar as ID2D; 2683 f = bar as ID2D;
2679 f = bar as DD2D; 2684 f = bar as DD2D;
2680 } 2685 }
2681 ''' 2686 ''');
2682 }); 2687 });
2683 2688
2684 group('function modifiers', () { 2689 group('function modifiers', () {
2685 testChecker('async', { 2690 test('async', () {
2686 '/main.dart': ''' 2691 checkFile('''
2687 import 'dart:async'; 2692 import 'dart:async';
2688 import 'dart:math' show Random; 2693 import 'dart:math' show Random;
2689 2694
2690 dynamic x; 2695 dynamic x;
2691 2696
2692 foo1() async => x; 2697 foo1() async => x;
2693 Future foo2() async => x; 2698 Future foo2() async => x;
2694 Future<int> foo3() async => (/*info:DYNAMIC_CAST*/x); 2699 Future<int> foo3() async => (/*info:DYNAMIC_CAST*/x);
2695 Future<int> foo4() async => (new Future<int>.value(/*info:DYNAMIC_CAST*/ x)); 2700 Future<int> foo4() async => (new Future<int>.value(/*info:DYNAMIC_CAST*/ x));
2696 Future<int> foo5() async => (/*severe:STATIC_TYPE_ERROR*/new Future<Stri ng>.value(/*info:DYNAMIC_CAST*/x)); 2701 Future<int> foo5() async => (/*severe:STATIC_TYPE_ERROR*/new Future<Stri ng>.value(/*info:DYNAMIC_CAST*/x));
(...skipping 15 matching lines...) Expand all
2712 } 2717 }
2713 2718
2714 Future<bool> get issue_264 async { 2719 Future<bool> get issue_264 async {
2715 await 42; 2720 await 42;
2716 if (new Random().nextBool()) { 2721 if (new Random().nextBool()) {
2717 return true; 2722 return true;
2718 } else { 2723 } else {
2719 return new Future<bool>.value(false); 2724 return new Future<bool>.value(false);
2720 } 2725 }
2721 } 2726 }
2722 ''' 2727 ''');
2723 }); 2728 });
2724 2729
2725 testChecker('async*', { 2730 test('async*', () {
2726 '/main.dart': ''' 2731 checkFile('''
2727 import 'dart:async'; 2732 import 'dart:async';
2728 2733
2729 dynamic x; 2734 dynamic x;
2730 2735
2731 bar1() async* { yield x; } 2736 bar1() async* { yield x; }
2732 Stream bar2() async* { yield x; } 2737 Stream bar2() async* { yield x; }
2733 Stream<int> bar3() async* { yield (/*info:DYNAMIC_CAST*/x); } 2738 Stream<int> bar3() async* { yield (/*info:DYNAMIC_CAST*/x); }
2734 Stream<int> bar4() async* { yield (/*severe:STATIC_TYPE_ERROR*/new Strea m<int>()); } 2739 Stream<int> bar4() async* { yield (/*severe:STATIC_TYPE_ERROR*/new Strea m<int>()); }
2735 2740
2736 baz1() async* { yield* (/*info:DYNAMIC_CAST*/x); } 2741 baz1() async* { yield* (/*info:DYNAMIC_CAST*/x); }
2737 Stream baz2() async* { yield* (/*info:DYNAMIC_CAST*/x); } 2742 Stream baz2() async* { yield* (/*info:DYNAMIC_CAST*/x); }
2738 Stream<int> baz3() async* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } 2743 Stream<int> baz3() async* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); }
2739 Stream<int> baz4() async* { yield* new Stream<int>(); } 2744 Stream<int> baz4() async* { yield* new Stream<int>(); }
2740 Stream<int> baz5() async* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/new Stream()); } 2745 Stream<int> baz5() async* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/new Stream()); }
2741 ''' 2746 ''');
2742 }); 2747 });
2743 2748
2744 testChecker('sync*', { 2749 test('sync*', () {
2745 '/main.dart': ''' 2750 checkFile('''
2746 import 'dart:async'; 2751 import 'dart:async';
2747 2752
2748 dynamic x; 2753 dynamic x;
2749 2754
2750 bar1() sync* { yield x; } 2755 bar1() sync* { yield x; }
2751 Iterable bar2() sync* { yield x; } 2756 Iterable bar2() sync* { yield x; }
2752 Iterable<int> bar3() sync* { yield (/*info:DYNAMIC_CAST*/x); } 2757 Iterable<int> bar3() sync* { yield (/*info:DYNAMIC_CAST*/x); }
2753 Iterable<int> bar4() sync* { yield (/*severe:STATIC_TYPE_ERROR*/new Iter able<int>()); } 2758 Iterable<int> bar4() sync* { yield (/*severe:STATIC_TYPE_ERROR*/new Iter able<int>()); }
2754 2759
2755 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2760 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2756 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2761 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); }
2757 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } 2762 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); }
2758 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } 2763 Iterable<int> baz4() sync* { yield* new Iterable<int>(); }
2759 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); } 2764 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); }
2760 ''' 2765 ''');
2761 }); 2766 });
2762 }); 2767 });
2763 } 2768 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698