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

Side by Side Diff: test/checker/checker_test.dart

Issue 1273343002: fix testChecker to include test inside (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 4 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 | test/checker/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 /// General type checking tests 5 /// General type checking tests
6 library dev_compiler.test.checker_test; 6 library dev_compiler.test.checker_test;
7 7
8 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
9 9
10 import '../testing.dart'; 10 import '../testing.dart';
11 11
12 void main() { 12 void main() {
13 test('ternary operator', () { 13 testChecker('ternary operator', {
14 testChecker({ 14 '/main.dart': '''
15 '/main.dart': '''
16 abstract class Comparable<T> { 15 abstract class Comparable<T> {
17 int compareTo(T other); 16 int compareTo(T other);
18 static int compare(Comparable a, Comparable b) => a.compareTo(b); 17 static int compare(Comparable a, Comparable b) => a.compareTo(b);
19 } 18 }
20 typedef int Comparator<T>(T a, T b); 19 typedef int Comparator<T>(T a, T b);
21 20
22 typedef bool _Predicate<T>(T value); 21 typedef bool _Predicate<T>(T value);
23 22
24 class SplayTreeMap<K, V> { 23 class SplayTreeMap<K, V> {
25 Comparator<K> _comparator; 24 Comparator<K> _comparator;
(...skipping 15 matching lines...) Expand all
41 Object obj = 42; 40 Object obj = 42;
42 dynamic dyn = 42; 41 dynamic dyn = 42;
43 int i = 42; 42 int i = 42;
44 43
45 // Check the boolean conversion of the condition. 44 // Check the boolean conversion of the condition.
46 print((/*severe:StaticTypeError*/i) ? false : true); 45 print((/*severe:StaticTypeError*/i) ? false : true);
47 print((/*warning:DownCastImplicit*/obj) ? false : true); 46 print((/*warning:DownCastImplicit*/obj) ? false : true);
48 print((/*info:DynamicCast*/dyn) ? false : true); 47 print((/*info:DynamicCast*/dyn) ? false : true);
49 } 48 }
50 ''' 49 '''
51 });
52 }); 50 });
53 51
54 test( 52 testChecker('if/for/do/while statements use boolean conversion', {
55 'if/for/do/while statements use boolean conversion', 53 '/main.dart': '''
56 () => testChecker({
57 '/main.dart': '''
58 main() { 54 main() {
59 dynamic d = 42; 55 dynamic d = 42;
60 Object obj = 42; 56 Object obj = 42;
61 int i = 42; 57 int i = 42;
62 bool b = false; 58 bool b = false;
63 59
64 if (b) {} 60 if (b) {}
65 if (/*info:DynamicCast*/dyn) {} 61 if (/*info:DynamicCast*/dyn) {}
66 if (/*warning:DownCastImplicit*/obj) {} 62 if (/*warning:DownCastImplicit*/obj) {}
67 if (/*severe:StaticTypeError*/i) {} 63 if (/*severe:StaticTypeError*/i) {}
68 64
69 while (b) {} 65 while (b) {}
70 while (/*info:DynamicCast*/dyn) {} 66 while (/*info:DynamicCast*/dyn) {}
71 while (/*warning:DownCastImplicit*/obj) {} 67 while (/*warning:DownCastImplicit*/obj) {}
72 while (/*severe:StaticTypeError*/i) {} 68 while (/*severe:StaticTypeError*/i) {}
73 69
74 do {} while (b); 70 do {} while (b);
75 do {} while (/*info:DynamicCast*/dyn); 71 do {} while (/*info:DynamicCast*/dyn);
76 do {} while (/*warning:DownCastImplicit*/obj); 72 do {} while (/*warning:DownCastImplicit*/obj);
77 do {} while (/*severe:StaticTypeError*/i); 73 do {} while (/*severe:StaticTypeError*/i);
78 74
79 for (;b;) {} 75 for (;b;) {}
80 for (;/*info:DynamicCast*/dyn;) {} 76 for (;/*info:DynamicCast*/dyn;) {}
81 for (;/*warning:DownCastImplicit*/obj;) {} 77 for (;/*warning:DownCastImplicit*/obj;) {}
82 for (;/*severe:StaticTypeError*/i;) {} 78 for (;/*severe:StaticTypeError*/i;) {}
83 } 79 }
84 ''' 80 '''
85 })); 81 });
86 82
87 test('dynamic invocation', () { 83 testChecker('dynamic invocation', {
88 testChecker({ 84 '/main.dart': '''
89 '/main.dart': '''
90 85
91 class A { 86 class A {
92 dynamic call(dynamic x) => x; 87 dynamic call(dynamic x) => x;
93 } 88 }
94 class B extends A { 89 class B extends A {
95 int call(int x) => x; 90 int call(int x) => x;
96 double col(double x) => x; 91 double col(double x) => x;
97 } 92 }
98 void main() { 93 void main() {
99 { 94 {
(...skipping 23 matching lines...) Expand all
123 { 118 {
124 A f = new B(); 119 A f = new B();
125 int x; 120 int x;
126 double y; 121 double y;
127 x = /*info:DynamicCast, info:DynamicInvoke*/f(3); 122 x = /*info:DynamicCast, info:DynamicInvoke*/f(3);
128 y = /*info:DynamicCast, info:DynamicInvoke*/f(3); 123 y = /*info:DynamicCast, info:DynamicInvoke*/f(3);
129 (/*info:DynamicInvoke*/f(3.0)); 124 (/*info:DynamicInvoke*/f(3.0));
130 } 125 }
131 } 126 }
132 ''' 127 '''
133 });
134 }); 128 });
135 129
136 test('conversion and dynamic invoke', () { 130 testChecker('conversion and dynamic invoke', {
137 testChecker({ 131 '/helper.dart': '''
138 '/helper.dart': '''
139 dynamic toString = (int x) => x + 42; 132 dynamic toString = (int x) => x + 42;
140 dynamic hashCode = "hello"; 133 dynamic hashCode = "hello";
141 ''', 134 ''',
142 '/main.dart': ''' 135 '/main.dart': '''
143 import 'helper.dart' as helper; 136 import 'helper.dart' as helper;
144 137
145 class A { 138 class A {
146 String x = "hello world"; 139 String x = "hello world";
147 140
148 void baz1(y) => x + /*info:DynamicCast*/y; 141 void baz1(y) => x + /*info:DynamicCast*/y;
149 static baz2(y) => /*info:DynamicInvoke*/y + y; 142 static baz2(y) => /*info:DynamicInvoke*/y + y;
150 } 143 }
151 144
152 void foo(String str) { 145 void foo(String str) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 198
206 (/*info:DynamicInvoke*/helper.toString()); 199 (/*info:DynamicInvoke*/helper.toString());
207 var toStringClosure2 = helper.toString; 200 var toStringClosure2 = helper.toString;
208 (/*info:DynamicInvoke*/toStringClosure2()); 201 (/*info:DynamicInvoke*/toStringClosure2());
209 int hashCode = /*info:DynamicCast*/helper.hashCode; 202 int hashCode = /*info:DynamicCast*/helper.hashCode;
210 203
211 baz().toString(); 204 baz().toString();
212 baz().hashCode; 205 baz().hashCode;
213 } 206 }
214 ''' 207 '''
215 });
216 }); 208 });
217 209
218 test('Primitives', () { 210 testChecker('Primitives', {
219 testChecker({ 211 '/main.dart': '''
220 '/main.dart': '''
221 int /*severe:InvalidVariableDeclaration*/a; 212 int /*severe:InvalidVariableDeclaration*/a;
222 double /*severe:InvalidVariableDeclaration*/b; 213 double /*severe:InvalidVariableDeclaration*/b;
223 num c; 214 num c;
224 215
225 class A { 216 class A {
226 int a; 217 int a;
227 double b; 218 double b;
228 num c; 219 num c;
229 220
230 static int /*severe:InvalidVariableDeclaration*/x; 221 static int /*severe:InvalidVariableDeclaration*/x;
(...skipping 27 matching lines...) Expand all
258 // num is nullable 249 // num is nullable
259 z = null; 250 z = null;
260 z = x; 251 z = x;
261 z = y; 252 z = y;
262 253
263 // bool is nullable 254 // bool is nullable
264 b = null; 255 b = null;
265 b = true; 256 b = true;
266 } 257 }
267 ''' 258 '''
268 }, nonnullableTypes: <String>[ 259 }, nonnullableTypes: <String>[
269 'int', 260 'int',
270 'double' 261 'double'
271 ]); 262 ]);
272 });
273 263
274 test('Primitives and generics', () { 264 testChecker('Primitives and generics', {
275 testChecker({ 265 '/main.dart': '''
276 '/main.dart': '''
277 class A<T> { 266 class A<T> {
278 // TODO(vsm): This needs a static info indicating a runtime 267 // TODO(vsm): This needs a static info indicating a runtime
279 // check at construction. 268 // check at construction.
280 T x; 269 T x;
281 270
282 // TODO(vsm): Should this be a different type of DownCast? 271 // TODO(vsm): Should this be a different type of DownCast?
283 T foo() => /*warning:DownCastImplicit*/null; 272 T foo() => /*warning:DownCastImplicit*/null;
284 273
285 void bar() { 274 void bar() {
286 int /*severe:InvalidVariableDeclaration*/x; 275 int /*severe:InvalidVariableDeclaration*/x;
(...skipping 16 matching lines...) Expand all
303 292
304 class C<T extends num> { 293 class C<T extends num> {
305 // TODO(vsm): This needs a static info indicating a runtime 294 // TODO(vsm): This needs a static info indicating a runtime
306 // check at construction. 295 // check at construction.
307 T x; 296 T x;
308 297
309 // TODO(vsm): Should this be a different type of DownCast? 298 // TODO(vsm): Should this be a different type of DownCast?
310 T foo() => /*warning:DownCastImplicit*/null; 299 T foo() => /*warning:DownCastImplicit*/null;
311 } 300 }
312 ''' 301 '''
313 }, nonnullableTypes: <String>[ 302 }, nonnullableTypes: <String>[
314 'int', 303 'int',
315 'double' 304 'double'
316 ]); 305 ]);
317 });
318 306
319 test('Constructors', () { 307 testChecker('Constructors', {
320 testChecker({ 308 '/main.dart': '''
321 '/main.dart': '''
322 const num z = 25; 309 const num z = 25;
323 Object obj = "world"; 310 Object obj = "world";
324 311
325 class A { 312 class A {
326 int x; 313 int x;
327 String y; 314 String y;
328 315
329 A(this.x) : this.y = /*severe:StaticTypeError*/42; 316 A(this.x) : this.y = /*severe:StaticTypeError*/42;
330 317
331 A.c1(p): this.x = /*warning:DownCastImplicit*/z, this.y = /*info:Dynamic Cast*/p; 318 A.c1(p): this.x = /*warning:DownCastImplicit*/z, this.y = /*info:Dynamic Cast*/p;
(...skipping 10 matching lines...) Expand all
342 /*severe:StaticTypeError*/x); 329 /*severe:StaticTypeError*/x);
343 330
344 B.c3(num x, Object y) : super.c3(x, /*warning:DownCastImplicit*/y); 331 B.c3(num x, Object y) : super.c3(x, /*warning:DownCastImplicit*/y);
345 } 332 }
346 333
347 void main() { 334 void main() {
348 A a = new A.c2(/*warning:DownCastImplicit*/z, /*severe:StaticTypeError* /z); 335 A a = new A.c2(/*warning:DownCastImplicit*/z, /*severe:StaticTypeError* /z);
349 var b = new B.c2(/*severe:StaticTypeError*/"hello", /*warning:DownCastI mplicit*/obj); 336 var b = new B.c2(/*severe:StaticTypeError*/"hello", /*warning:DownCastI mplicit*/obj);
350 } 337 }
351 ''' 338 '''
352 });
353 }); 339 });
354 340
355 test('Unbound variable', () { 341 testChecker('Unbound variable', {
356 testChecker({ 342 '/main.dart': '''
357 '/main.dart': '''
358 void main() { 343 void main() {
359 dynamic y = /*pass should be severe:StaticTypeError*/unboundVariable; 344 dynamic y = /*pass should be severe:StaticTypeError*/unboundVariable;
360 } 345 }
361 ''' 346 '''
362 });
363 }); 347 });
364 348
365 test('Unbound type name', () { 349 testChecker('Unbound type name', {
366 testChecker({ 350 '/main.dart': '''
367 '/main.dart': '''
368 void main() { 351 void main() {
369 /*pass should be severe:StaticTypeError*/AToB y; 352 /*pass should be severe:StaticTypeError*/AToB y;
370 } 353 }
371 ''' 354 '''
372 });
373 }); 355 });
374 356
375 test('Ground type subtyping: dynamic is top', () { 357 testChecker('Ground type subtyping: dynamic is top', {
376 testChecker({ 358 '/main.dart': '''
377 '/main.dart': '''
378 359
379 class A {} 360 class A {}
380 class B extends A {} 361 class B extends A {}
381 362
382 void main() { 363 void main() {
383 dynamic y; 364 dynamic y;
384 Object o; 365 Object o;
385 int i = 0; 366 int i = 0;
386 double d = 0.0; 367 double d = 0.0;
387 num n; 368 num n;
388 A a; 369 A a;
389 B b; 370 B b;
390 y = o; 371 y = o;
391 y = i; 372 y = i;
392 y = d; 373 y = d;
393 y = n; 374 y = n;
394 y = a; 375 y = a;
395 y = b; 376 y = b;
396 } 377 }
397 ''' 378 '''
398 });
399 }); 379 });
400 380
401 test('Ground type subtyping: dynamic downcasts', () { 381 testChecker('Ground type subtyping: dynamic downcasts', {
402 testChecker({ 382 '/main.dart': '''
403 '/main.dart': '''
404 383
405 class A {} 384 class A {}
406 class B extends A {} 385 class B extends A {}
407 386
408 void main() { 387 void main() {
409 dynamic y; 388 dynamic y;
410 Object o; 389 Object o;
411 int i = 0; 390 int i = 0;
412 double d = 0.0; 391 double d = 0.0;
413 num n; 392 num n;
414 A a; 393 A a;
415 B b; 394 B b;
416 o = y; 395 o = y;
417 i = /*info:DynamicCast*/y; 396 i = /*info:DynamicCast*/y;
418 d = /*info:DynamicCast*/y; 397 d = /*info:DynamicCast*/y;
419 n = /*info:DynamicCast*/y; 398 n = /*info:DynamicCast*/y;
420 a = /*info:DynamicCast*/y; 399 a = /*info:DynamicCast*/y;
421 b = /*info:DynamicCast*/y; 400 b = /*info:DynamicCast*/y;
422 } 401 }
423 ''' 402 '''
424 });
425 }); 403 });
426 404
427 test('Ground type subtyping: assigning a class', () { 405 testChecker('Ground type subtyping: assigning a class', {
428 testChecker({ 406 '/main.dart': '''
429 '/main.dart': '''
430 407
431 class A {} 408 class A {}
432 class B extends A {} 409 class B extends A {}
433 410
434 void main() { 411 void main() {
435 dynamic y; 412 dynamic y;
436 Object o; 413 Object o;
437 int i = 0; 414 int i = 0;
438 double d = 0.0; 415 double d = 0.0;
439 num n; 416 num n;
440 A a; 417 A a;
441 B b; 418 B b;
442 y = a; 419 y = a;
443 o = a; 420 o = a;
444 i = /*severe:StaticTypeError*/a; 421 i = /*severe:StaticTypeError*/a;
445 d = /*severe:StaticTypeError*/a; 422 d = /*severe:StaticTypeError*/a;
446 n = /*severe:StaticTypeError*/a; 423 n = /*severe:StaticTypeError*/a;
447 a = a; 424 a = a;
448 b = /*warning:DownCastImplicit*/a; 425 b = /*warning:DownCastImplicit*/a;
449 } 426 }
450 ''' 427 '''
451 });
452 }); 428 });
453 429
454 test('Ground type subtyping: assigning a subclass', () { 430 testChecker('Ground type subtyping: assigning a subclass', {
455 testChecker({ 431 '/main.dart': '''
456 '/main.dart': '''
457 432
458 class A {} 433 class A {}
459 class B extends A {} 434 class B extends A {}
460 class C extends A {} 435 class C extends A {}
461 436
462 void main() { 437 void main() {
463 dynamic y; 438 dynamic y;
464 Object o; 439 Object o;
465 int i = 0; 440 int i = 0;
466 double d = 0.0; 441 double d = 0.0;
467 num n; 442 num n;
468 A a; 443 A a;
469 B b; 444 B b;
470 C c; 445 C c;
471 y = b; 446 y = b;
472 o = b; 447 o = b;
473 i = /*severe:StaticTypeError*/b; 448 i = /*severe:StaticTypeError*/b;
474 d = /*severe:StaticTypeError*/b; 449 d = /*severe:StaticTypeError*/b;
475 n = /*severe:StaticTypeError*/b; 450 n = /*severe:StaticTypeError*/b;
476 a = b; 451 a = b;
477 b = b; 452 b = b;
478 c = /*severe:StaticTypeError*/b; 453 c = /*severe:StaticTypeError*/b;
479 } 454 }
480 ''' 455 '''
481 });
482 }); 456 });
483 457
484 test('Ground type subtyping: interfaces', () { 458 testChecker('Ground type subtyping: interfaces', {
485 testChecker({ 459 '/main.dart': '''
486 '/main.dart': '''
487 460
488 class A {} 461 class A {}
489 class B extends A {} 462 class B extends A {}
490 class C extends A {} 463 class C extends A {}
491 class D extends B implements C {} 464 class D extends B implements C {}
492 465
493 void main() { 466 void main() {
494 A top; 467 A top;
495 B left; 468 B left;
496 C right; 469 C right;
(...skipping 17 matching lines...) Expand all
514 right = bot; 487 right = bot;
515 } 488 }
516 { 489 {
517 bot = /*warning:DownCastImplicit*/top; 490 bot = /*warning:DownCastImplicit*/top;
518 bot = /*warning:DownCastImplicit*/left; 491 bot = /*warning:DownCastImplicit*/left;
519 bot = /*warning:DownCastImplicit*/right; 492 bot = /*warning:DownCastImplicit*/right;
520 bot = bot; 493 bot = bot;
521 } 494 }
522 } 495 }
523 ''' 496 '''
524 });
525 }); 497 });
526 498
527 test('Function typing and subtyping: int and object', () { 499 testChecker('Function typing and subtyping: int and object', {
528 testChecker({ 500 '/main.dart': '''
529 '/main.dart': '''
530 501
531 typedef Object Top(int x); // Top of the lattice 502 typedef Object Top(int x); // Top of the lattice
532 typedef int Left(int x); // Left branch 503 typedef int Left(int x); // Left branch
533 typedef int Left2(int x); // Left branch 504 typedef int Left2(int x); // Left branch
534 typedef Object Right(Object x); // Right branch 505 typedef Object Right(Object x); // Right branch
535 typedef int Bot(Object x); // Bottom of the lattice 506 typedef int Bot(Object x); // Bottom of the lattice
536 507
537 Object top(int x) => x; 508 Object top(int x) => x;
538 int left(int x) => x; 509 int left(int x) => x;
539 Object right(Object x) => x; 510 Object right(Object x) => x;
(...skipping 28 matching lines...) Expand all
568 } 539 }
569 { 540 {
570 Bot f; 541 Bot f;
571 f = /*warning:DownCastComposite*/top; 542 f = /*warning:DownCastComposite*/top;
572 f = /*warning:DownCastComposite*/left; 543 f = /*warning:DownCastComposite*/left;
573 f = /*warning:DownCastComposite*/right; 544 f = /*warning:DownCastComposite*/right;
574 f = bot; 545 f = bot;
575 } 546 }
576 } 547 }
577 ''' 548 '''
578 });
579 }); 549 });
580 550
581 test('Function typing and subtyping: classes', () { 551 testChecker('Function typing and subtyping: classes', {
582 testChecker({ 552 '/main.dart': '''
583 '/main.dart': '''
584 553
585 class A {} 554 class A {}
586 class B extends A {} 555 class B extends A {}
587 556
588 typedef A Top(B x); // Top of the lattice 557 typedef A Top(B x); // Top of the lattice
589 typedef B Left(B x); // Left branch 558 typedef B Left(B x); // Left branch
590 typedef B Left2(B x); // Left branch 559 typedef B Left2(B x); // Left branch
591 typedef A Right(A x); // Right branch 560 typedef A Right(A x); // Right branch
592 typedef B Bot(A x); // Bottom of the lattice 561 typedef B Bot(A x); // Bottom of the lattice
593 562
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 594 }
626 { 595 {
627 Bot f; 596 Bot f;
628 f = /*warning:DownCastComposite*/top; 597 f = /*warning:DownCastComposite*/top;
629 f = /*warning:DownCastComposite*/left; 598 f = /*warning:DownCastComposite*/left;
630 f = /*warning:DownCastComposite*/right; 599 f = /*warning:DownCastComposite*/right;
631 f = bot; 600 f = bot;
632 } 601 }
633 } 602 }
634 ''' 603 '''
635 });
636 }); 604 });
637 605
638 test('Function typing and subtyping: dynamic', () { 606 testChecker('Function typing and subtyping: dynamic', {
639 testChecker({ 607 '/main.dart': '''
640 '/main.dart': '''
641 608
642 class A {} 609 class A {}
643 610
644 typedef dynamic Top(dynamic x); // Top of the lattice 611 typedef dynamic Top(dynamic x); // Top of the lattice
645 typedef dynamic Left(A x); // Left branch 612 typedef dynamic Left(A x); // Left branch
646 typedef A Right(dynamic x); // Right branch 613 typedef A Right(dynamic x); // Right branch
647 typedef A Bottom(A x); // Bottom of the lattice 614 typedef A Bottom(A x); // Bottom of the lattice
648 615
649 dynamic left(A x) => x; 616 dynamic left(A x) => x;
650 A bot(A x) => x; 617 A bot(A x) => x;
(...skipping 24 matching lines...) Expand all
675 } 642 }
676 { 643 {
677 Bottom f; 644 Bottom f;
678 f = /*warning:DownCastComposite*/top; 645 f = /*warning:DownCastComposite*/top;
679 f = /*warning:DownCastComposite*/left; 646 f = /*warning:DownCastComposite*/left;
680 f = /*warning:DownCastComposite*/right; 647 f = /*warning:DownCastComposite*/right;
681 f = bot; 648 f = bot;
682 } 649 }
683 } 650 }
684 ''' 651 '''
685 });
686 }); 652 });
687 653
688 test('Function typing and subtyping: function literal variance', () { 654 testChecker('Function typing and subtyping: function literal variance', {
689 testChecker({ 655 '/main.dart': '''
690 '/main.dart': '''
691 656
692 class A {} 657 class A {}
693 class B extends A {} 658 class B extends A {}
694 659
695 typedef T Function2<S, T>(S z); 660 typedef T Function2<S, T>(S z);
696 661
697 A top(B x) => x; 662 A top(B x) => x;
698 B left(B x) => x; 663 B left(B x) => x;
699 A right(A x) => x; 664 A right(A x) => x;
700 B bot(A x) => x as B; 665 B bot(A x) => x as B;
(...skipping 22 matching lines...) Expand all
723 } 688 }
724 { 689 {
725 Function2<A, B> f; 690 Function2<A, B> f;
726 f = /*warning:DownCastComposite*/top; 691 f = /*warning:DownCastComposite*/top;
727 f = /*warning:DownCastComposite*/left; 692 f = /*warning:DownCastComposite*/left;
728 f = /*warning:DownCastComposite*/right; 693 f = /*warning:DownCastComposite*/right;
729 f = bot; 694 f = bot;
730 } 695 }
731 } 696 }
732 ''' 697 '''
733 });
734 }); 698 });
735 699
736 test('Function typing and subtyping: function variable variance', () { 700 testChecker('Function typing and subtyping: function variable variance', {
737 testChecker({ 701 '/main.dart': '''
738 '/main.dart': '''
739 702
740 class A {} 703 class A {}
741 class B extends A {} 704 class B extends A {}
742 705
743 typedef T Function2<S, T>(S z); 706 typedef T Function2<S, T>(S z);
744 707
745 void main() { 708 void main() {
746 { 709 {
747 Function2<B, A> top; 710 Function2<B, A> top;
748 Function2<B, B> left; 711 Function2<B, B> left;
(...skipping 15 matching lines...) Expand all
764 right = right; 727 right = right;
765 right = bot; 728 right = bot;
766 729
767 bot = /*warning:DownCastComposite*/top; 730 bot = /*warning:DownCastComposite*/top;
768 bot = /*warning:DownCastComposite*/left; 731 bot = /*warning:DownCastComposite*/left;
769 bot = /*warning:DownCastComposite*/right; 732 bot = /*warning:DownCastComposite*/right;
770 bot = bot; 733 bot = bot;
771 } 734 }
772 } 735 }
773 ''' 736 '''
774 });
775 }); 737 });
776 738
777 test('Function typing and subtyping: higher order function literals', () { 739 testChecker('Function typing and subtyping: higher order function literals', {
778 testChecker({ 740 '/main.dart': '''
779 '/main.dart': '''
780 741
781 class A {} 742 class A {}
782 class B extends A {} 743 class B extends A {}
783 744
784 typedef T Function2<S, T>(S z); 745 typedef T Function2<S, T>(S z);
785 746
786 typedef A BToA(B x); // Top of the base lattice 747 typedef A BToA(B x); // Top of the base lattice
787 typedef B AToB(A x); // Bot of the base lattice 748 typedef B AToB(A x); // Bot of the base lattice
788 749
789 BToA top(AToB f) => f; 750 BToA top(AToB f) => f;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 } 790 }
830 { 791 {
831 Function2<BToA, AToB> f; // Bot 792 Function2<BToA, AToB> f; // Bot
832 f = bot; 793 f = bot;
833 f = /*warning:DownCastComposite*/left; 794 f = /*warning:DownCastComposite*/left;
834 f = /*warning:DownCastComposite*/top; 795 f = /*warning:DownCastComposite*/top;
835 f = /*warning:DownCastComposite*/left; 796 f = /*warning:DownCastComposite*/left;
836 } 797 }
837 } 798 }
838 ''' 799 '''
839 });
840 }); 800 });
841 801
842 test('Function typing and subtyping: higher order function variables', () { 802 testChecker(
843 testChecker({ 803 'Function typing and subtyping: higher order function variables', {
844 '/main.dart': ''' 804 '/main.dart': '''
845 805
846 class A {} 806 class A {}
847 class B extends A {} 807 class B extends A {}
848 808
849 typedef T Function2<S, T>(S z); 809 typedef T Function2<S, T>(S z);
850 810
851 void main() { 811 void main() {
852 { 812 {
853 Function2<Function2<A, B>, Function2<B, A>> top; 813 Function2<Function2<A, B>, Function2<B, A>> top;
854 Function2<Function2<B, A>, Function2<B, A>> right; 814 Function2<Function2<B, A>, Function2<B, A>> right;
(...skipping 17 matching lines...) Expand all
872 right = right; 832 right = right;
873 right = bot; 833 right = bot;
874 834
875 bot = /*warning:DownCastComposite*/top; 835 bot = /*warning:DownCastComposite*/top;
876 bot = /*warning:DownCastComposite*/left; 836 bot = /*warning:DownCastComposite*/left;
877 bot = /*warning:DownCastComposite*/right; 837 bot = /*warning:DownCastComposite*/right;
878 bot = bot; 838 bot = bot;
879 } 839 }
880 } 840 }
881 ''' 841 '''
882 });
883 }); 842 });
884 843
885 test('Function typing and subtyping: named and optional parameters', () { 844 testChecker('Function typing and subtyping: named and optional parameters', {
886 testChecker({ 845 '/main.dart': '''
887 '/main.dart': '''
888 846
889 class A {} 847 class A {}
890 848
891 typedef A FR(A x); 849 typedef A FR(A x);
892 typedef A FO([A x]); 850 typedef A FO([A x]);
893 typedef A FN({A x}); 851 typedef A FN({A x});
894 typedef A FRR(A x, A y); 852 typedef A FRR(A x, A y);
895 typedef A FRO(A x, [A y]); 853 typedef A FRO(A x, [A y]);
896 typedef A FRN(A x, {A n}); 854 typedef A FRN(A x, {A n});
897 typedef A FOO([A x, A y]); 855 typedef A FOO([A x, A y]);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 nnn = /*severe:StaticTypeError*/o; 951 nnn = /*severe:StaticTypeError*/o;
994 nnn = /*warning:DownCastComposite*/n; 952 nnn = /*warning:DownCastComposite*/n;
995 nnn = /*severe:StaticTypeError*/rr; 953 nnn = /*severe:StaticTypeError*/rr;
996 nnn = /*severe:StaticTypeError*/ro; 954 nnn = /*severe:StaticTypeError*/ro;
997 nnn = /*severe:StaticTypeError*/rn; 955 nnn = /*severe:StaticTypeError*/rn;
998 nnn = /*severe:StaticTypeError*/oo; 956 nnn = /*severe:StaticTypeError*/oo;
999 nnn = /*warning:DownCastComposite*/nn; 957 nnn = /*warning:DownCastComposite*/nn;
1000 nnn = nnn; 958 nnn = nnn;
1001 } 959 }
1002 ''' 960 '''
1003 });
1004 }); 961 });
1005 962
1006 test('Function subtyping: objects with call methods', () { 963 testChecker('Function subtyping: objects with call methods', {
1007 testChecker({ 964 '/main.dart': '''
1008 '/main.dart': '''
1009 965
1010 typedef int I2I(int x); 966 typedef int I2I(int x);
1011 typedef num N2N(num x); 967 typedef num N2N(num x);
1012 class A { 968 class A {
1013 int call(int x) => x; 969 int call(int x) => x;
1014 } 970 }
1015 class B { 971 class B {
1016 num call(num x) => x; 972 num call(num x) => x;
1017 } 973 }
1018 int i2i(int x) => x; 974 int i2i(int x) => x;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 Function f; 1014 Function f;
1059 f = new A(); 1015 f = new A();
1060 f = new B(); 1016 f = new B();
1061 f = i2i; 1017 f = i2i;
1062 f = n2n; 1018 f = n2n;
1063 f = /*warning:DownCastImplicit*/i2i as Object; 1019 f = /*warning:DownCastImplicit*/i2i as Object;
1064 f = (n2n as Function); 1020 f = (n2n as Function);
1065 } 1021 }
1066 } 1022 }
1067 ''' 1023 '''
1068 });
1069 }); 1024 });
1070 1025
1071 test('Function typing and subtyping: void', () { 1026 testChecker('Function typing and subtyping: void', {
1072 testChecker({ 1027 '/main.dart': '''
1073 '/main.dart': '''
1074 1028
1075 class A { 1029 class A {
1076 void bar() => null; 1030 void bar() => null;
1077 void foo() => bar; // allowed 1031 void foo() => bar; // allowed
1078 } 1032 }
1079 ''' 1033 '''
1080 });
1081 }); 1034 });
1082 1035
1083 test('Covariant generic subtyping: invariance', () { 1036 testChecker(
1084 testChecker({ 1037 'Covariant generic subtyping: invariance',
1085 '/main.dart': ''' 1038 {
1039 '/main.dart': '''
1086 1040
1087 class A {} 1041 class A {}
1088 class B extends A {} 1042 class B extends A {}
1089 class C implements A {} 1043 class C implements A {}
1090 1044
1091 class L<T> {} 1045 class L<T> {}
1092 class M<T> extends L<T> {} 1046 class M<T> extends L<T> {}
1093 class N extends M<A> {} 1047 class N extends M<A> {}
1094 1048
1095 void main() { 1049 void main() {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 // Concrete subclass subtyping 1138 // Concrete subclass subtyping
1185 ns = /*warning:DownCastImplicit*/lOfAs; 1139 ns = /*warning:DownCastImplicit*/lOfAs;
1186 ns = /*severe:StaticTypeError*/lOfBs; 1140 ns = /*severe:StaticTypeError*/lOfBs;
1187 ns = /*severe:StaticTypeError*/lOfCs; 1141 ns = /*severe:StaticTypeError*/lOfCs;
1188 ns = /*warning:DownCastImplicit*/mOfAs; 1142 ns = /*warning:DownCastImplicit*/mOfAs;
1189 ns = /*severe:StaticTypeError*/mOfBs; 1143 ns = /*severe:StaticTypeError*/mOfBs;
1190 ns = /*severe:StaticTypeError*/mOfCs; 1144 ns = /*severe:StaticTypeError*/mOfCs;
1191 ns = ns; 1145 ns = ns;
1192 } 1146 }
1193 ''' 1147 '''
1194 }, relaxedCasts: false); 1148 },
1195 }); 1149 relaxedCasts: false);
1196 1150
1197 test('Relaxed casts', () { 1151 testChecker(
1198 testChecker({ 1152 'Relaxed casts',
1199 '/main.dart': ''' 1153 {
1154 '/main.dart': '''
1200 1155
1201 class A {} 1156 class A {}
1202 1157
1203 class L<T> {} 1158 class L<T> {}
1204 class M<T> extends L<T> {} 1159 class M<T> extends L<T> {}
1205 // L<dynamic|Object> 1160 // L<dynamic|Object>
1206 // / \ 1161 // / \
1207 // M<dynamic|Object> L<A> 1162 // M<dynamic|Object> L<A>
1208 // \ / 1163 // \ /
1209 // M<A> 1164 // M<A>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 mOfAs = /*warning:DownCastComposite*/mOfDs; 1219 mOfAs = /*warning:DownCastComposite*/mOfDs;
1265 mOfAs = /*warning:DownCastComposite*/mOfOs; 1220 mOfAs = /*warning:DownCastComposite*/mOfOs;
1266 mOfAs = mOfAs; 1221 mOfAs = mOfAs;
1267 mOfAs = /*warning:DownCastComposite*/lOfDs; 1222 mOfAs = /*warning:DownCastComposite*/lOfDs;
1268 mOfAs = /*warning:DownCastComposite*/lOfOs; 1223 mOfAs = /*warning:DownCastComposite*/lOfOs;
1269 mOfAs = /*warning:DownCastComposite*/lOfAs; 1224 mOfAs = /*warning:DownCastComposite*/lOfAs;
1270 } 1225 }
1271 1226
1272 } 1227 }
1273 ''' 1228 '''
1274 }, relaxedCasts: true); 1229 },
1275 }); 1230 relaxedCasts: true);
1276 1231 testChecker(
1277 test('Subtyping literals', () { 1232 'Subtyping literals',
1278 testChecker({ 1233 {
1279 '/main.dart': ''' 1234 '/main.dart': '''
1280 test() { 1235 test() {
1281 Iterable i1 = [1, 2, 3]; 1236 Iterable i1 = [1, 2, 3];
1282 i1 = <int>[1, 2, 3]; 1237 i1 = <int>[1, 2, 3];
1283 1238
1284 List l1 = [1, 2, 3]; 1239 List l1 = [1, 2, 3];
1285 l1 = <int>[1, 2, 3]; 1240 l1 = <int>[1, 2, 3];
1286 1241
1287 Iterable<int> i2 = /*severe:StaticTypeError*/[1, 2, 3]; 1242 Iterable<int> i2 = /*severe:StaticTypeError*/[1, 2, 3];
1288 i2 = /*warning:DownCastComposite*/i1; 1243 i2 = /*warning:DownCastComposite*/i1;
1289 i2 = /*warning:DownCastComposite*/l1; 1244 i2 = /*warning:DownCastComposite*/l1;
1290 i2 = <int>[1, 2, 3]; 1245 i2 = <int>[1, 2, 3];
1291 1246
1292 List<int> l2 = /*severe:StaticTypeError*/[1, 2, 3]; 1247 List<int> l2 = /*severe:StaticTypeError*/[1, 2, 3];
1293 l2 = /*warning:DownCastComposite*/i1; 1248 l2 = /*warning:DownCastComposite*/i1;
1294 l2 = /*warning:DownCastComposite*/l1; 1249 l2 = /*warning:DownCastComposite*/l1;
1295 1250
1296 l2 = /*severe:StaticTypeError*/new List(); 1251 l2 = /*severe:StaticTypeError*/new List();
1297 l2 = /*severe:StaticTypeError*/new List(10); 1252 l2 = /*severe:StaticTypeError*/new List(10);
1298 l2 = /*severe:StaticTypeError*/new List.filled(10, 42); 1253 l2 = /*severe:StaticTypeError*/new List.filled(10, 42);
1299 } 1254 }
1300 ''' 1255 '''
1301 }, inferDownwards: false); 1256 },
1302 }); 1257 inferDownwards: false);
1303 1258
1304 test('Type checking literals', () { 1259 testChecker('Type checking literals', {
1305 testChecker({ 1260 '/main.dart': '''
1306 '/main.dart': '''
1307 test() { 1261 test() {
1308 num n = 3; 1262 num n = 3;
1309 int i = 3; 1263 int i = 3;
1310 String s = "hello"; 1264 String s = "hello";
1311 { 1265 {
1312 List<int> l = <int>[i]; 1266 List<int> l = <int>[i];
1313 l = <int>[/*severe:StaticTypeError*/s]; 1267 l = <int>[/*severe:StaticTypeError*/s];
1314 l = <int>[/*warning:DownCastImplicit*/n]; 1268 l = <int>[/*warning:DownCastImplicit*/n];
1315 l = <int>[i, /*warning:DownCastImplicit*/n, /*severe:StaticTypeEr ror*/s]; 1269 l = <int>[i, /*warning:DownCastImplicit*/n, /*severe:StaticTypeEr ror*/s];
1316 } 1270 }
(...skipping 19 matching lines...) Expand all
1336 m = {s: n}; 1290 m = {s: n};
1337 m = {s: i, 1291 m = {s: i,
1338 s: n, 1292 s: n,
1339 s: s}; 1293 s: s};
1340 m = {i: s, 1294 m = {i: s,
1341 n: s, 1295 n: s,
1342 s: s}; 1296 s: s};
1343 } 1297 }
1344 } 1298 }
1345 ''' 1299 '''
1346 });
1347 }); 1300 });
1348 1301
1349 test('casts in constant contexts', () { 1302 testChecker('casts in constant contexts', {
1350 String mk(String error1, String error2) => ''' 1303 '/main.dart': '''
1351 class A { 1304 class A {
1352 static const num n = 3.0; 1305 static const num n = 3.0;
1353 static const int i = /*$error2*/n; 1306 static const int i = /*info:AssignmentCast*/n;
1354 final int fi; 1307 final int fi;
1355 const A(num a) : this.fi = /*$error1*/a; 1308 const A(num a) : this.fi = /*warning:DownCastImplicit*/a;
1356 } 1309 }
1357 class B extends A { 1310 class B extends A {
1358 const B(Object a) : super(/*$error1*/a); 1311 const B(Object a) : super(/*warning:DownCastImplicit*/a);
1359 } 1312 }
1360 void foo(Object o) { 1313 void foo(Object o) {
1361 var a = const A(/*$error1*/o); 1314 var a = const A(/*warning:DownCastImplicit*/o);
1362 } 1315 }
1363 '''; 1316 '''
1364 testChecker(
1365 {'/main.dart': mk("warning:DownCastImplicit", "info:AssignmentCast")});
1366 }); 1317 });
1367 1318
1368 test('casts in conditionals', () { 1319 testChecker('casts in conditionals', {
1369 testChecker({ 1320 '/main.dart': '''
1370 '/main.dart': '''
1371 main() { 1321 main() {
1372 bool b = true; 1322 bool b = true;
1373 num x = b ? 1 : 2.3; 1323 num x = b ? 1 : 2.3;
1374 int y = /*info:AssignmentCast*/b ? 1 : 2.3; 1324 int y = /*info:AssignmentCast*/b ? 1 : 2.3;
1375 String z = !b ? "hello" : null; 1325 String z = !b ? "hello" : null;
1376 z = b ? null : "hello"; 1326 z = b ? null : "hello";
1377 } 1327 }
1378 ''' 1328 '''
1379 });
1380 }); 1329 });
1381 1330
1382 test('redirecting constructor', () { 1331 testChecker('redirecting constructor', {
1383 testChecker({ 1332 '/main.dart': '''
1384 '/main.dart': '''
1385 class A { 1333 class A {
1386 A(A x) {} 1334 A(A x) {}
1387 A.two() : this(/*severe:StaticTypeError*/3); 1335 A.two() : this(/*severe:StaticTypeError*/3);
1388 } 1336 }
1389 ''' 1337 '''
1390 });
1391 }); 1338 });
1392 1339
1393 test('super constructor', () { 1340 testChecker('super constructor', {
1394 testChecker({ 1341 '/main.dart': '''
1395 '/main.dart': '''
1396 class A { A(A x) {} } 1342 class A { A(A x) {} }
1397 class B extends A { 1343 class B extends A {
1398 B() : super(/*severe:StaticTypeError*/3); 1344 B() : super(/*severe:StaticTypeError*/3);
1399 } 1345 }
1400 ''' 1346 '''
1401 });
1402 }); 1347 });
1403 1348
1404 test('field/field override', () { 1349 testChecker(
1405 testChecker({ 1350 'field/field override',
1406 '/main.dart': ''' 1351 {
1352 '/main.dart': '''
1407 class A {} 1353 class A {}
1408 class B extends A {} 1354 class B extends A {}
1409 class C extends B {} 1355 class C extends B {}
1410 1356
1411 class Base { 1357 class Base {
1412 B f1; 1358 B f1;
1413 B f2; 1359 B f2;
1414 B f3; 1360 B f3;
1415 B f4; 1361 B f4;
1416 } 1362 }
1417 1363
1418 class Child extends Base { 1364 class Child extends Base {
1419 /*severe:InvalidMethodOverride*/A f1; // invalid for getter 1365 /*severe:InvalidMethodOverride*/A f1; // invalid for getter
1420 /*severe:InvalidMethodOverride*/C f2; // invalid for setter 1366 /*severe:InvalidMethodOverride*/C f2; // invalid for setter
1421 var f3; 1367 var f3;
1422 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic f4; 1368 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic f4;
1423 } 1369 }
1424 ''' 1370 '''
1425 }, inferFromOverrides: true); 1371 },
1372 inferFromOverrides: true);
1426 1373
1427 testChecker({ 1374 testChecker(
1428 '/main.dart': ''' 1375 'field/field override 2',
1376 {
1377 '/main.dart': '''
1429 class A {} 1378 class A {}
1430 class B extends A {} 1379 class B extends A {}
1431 class C extends B {} 1380 class C extends B {}
1432 1381
1433 class Base { 1382 class Base {
1434 B f1; 1383 B f1;
1435 B f2; 1384 B f2;
1436 B f3; 1385 B f3;
1437 B f4; 1386 B f4;
1438 } 1387 }
1439 1388
1440 class Child extends Base { 1389 class Child extends Base {
1441 /*severe:InvalidMethodOverride*/A f1; // invalid for getter 1390 /*severe:InvalidMethodOverride*/A f1; // invalid for getter
1442 /*severe:InvalidMethodOverride*/C f2; // invalid for setter 1391 /*severe:InvalidMethodOverride*/C f2; // invalid for setter
1443 /*severe:InferableOverride,severe:InvalidMethodOverride*/var f3; 1392 /*severe:InferableOverride,severe:InvalidMethodOverride*/var f3;
1444 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic f4; 1393 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/dynamic f4;
1445 } 1394 }
1446 ''' 1395 '''
1447 }, inferFromOverrides: false); 1396 },
1448 }); 1397 inferFromOverrides: false);
1449 1398
1450 test('getter/getter override', () { 1399 testChecker(
1451 testChecker({ 1400 'getter/getter override',
1452 '/main.dart': ''' 1401 {
1402 '/main.dart': '''
1453 class A {} 1403 class A {}
1454 class B extends A {} 1404 class B extends A {}
1455 class C extends B {} 1405 class C extends B {}
1456 1406
1457 abstract class Base { 1407 abstract class Base {
1458 B get f1; 1408 B get f1;
1459 B get f2; 1409 B get f2;
1460 B get f3; 1410 B get f3;
1461 B get f4; 1411 B get f4;
1462 } 1412 }
1463 1413
1464 class Child extends Base { 1414 class Child extends Base {
1465 /*severe:InvalidMethodOverride*/A get f1 => null; 1415 /*severe:InvalidMethodOverride*/A get f1 => null;
1466 C get f2 => null; 1416 C get f2 => null;
1467 get f3 => null; 1417 get f3 => null;
1468 /*severe:InvalidMethodOverride*/dynamic get f4 => null; 1418 /*severe:InvalidMethodOverride*/dynamic get f4 => null;
1469 } 1419 }
1470 ''' 1420 '''
1471 }, inferFromOverrides: true); 1421 },
1422 inferFromOverrides: true);
1472 1423
1473 testChecker({ 1424 testChecker(
1474 '/main.dart': ''' 1425 'getter/getter override 2',
1426 {
1427 '/main.dart': '''
1475 class A {} 1428 class A {}
1476 class B extends A {} 1429 class B extends A {}
1477 class C extends B {} 1430 class C extends B {}
1478 1431
1479 abstract class Base { 1432 abstract class Base {
1480 B get f1; 1433 B get f1;
1481 B get f2; 1434 B get f2;
1482 B get f3; 1435 B get f3;
1483 B get f4; 1436 B get f4;
1484 } 1437 }
1485 1438
1486 class Child extends Base { 1439 class Child extends Base {
1487 /*severe:InvalidMethodOverride*/A get f1 => null; 1440 /*severe:InvalidMethodOverride*/A get f1 => null;
1488 C get f2 => null; 1441 C get f2 => null;
1489 /*severe:InferableOverride*/get f3 => null; 1442 /*severe:InferableOverride*/get f3 => null;
1490 /*severe:InvalidMethodOverride*/dynamic get f4 => null; 1443 /*severe:InvalidMethodOverride*/dynamic get f4 => null;
1491 } 1444 }
1492 ''' 1445 '''
1493 }, inferFromOverrides: false); 1446 },
1494 }); 1447 inferFromOverrides: false);
1495 1448
1496 test('field/getter override', () { 1449 testChecker(
1497 testChecker({ 1450 'field/getter override',
1498 '/main.dart': ''' 1451 {
1452 '/main.dart': '''
1499 class A {} 1453 class A {}
1500 class B extends A {} 1454 class B extends A {}
1501 class C extends B {} 1455 class C extends B {}
1502 1456
1503 abstract class Base { 1457 abstract class Base {
1504 B f1; 1458 B f1;
1505 B f2; 1459 B f2;
1506 B f3; 1460 B f3;
1507 B f4; 1461 B f4;
1508 } 1462 }
1509 1463
1510 class Child extends Base { 1464 class Child extends Base {
1511 /*severe:InvalidMethodOverride*/A get f1 => null; 1465 /*severe:InvalidMethodOverride*/A get f1 => null;
1512 C get f2 => null; 1466 C get f2 => null;
1513 get f3 => null; 1467 get f3 => null;
1514 /*severe:InvalidMethodOverride*/dynamic get f4 => null; 1468 /*severe:InvalidMethodOverride*/dynamic get f4 => null;
1515 } 1469 }
1516 ''' 1470 '''
1517 }, inferFromOverrides: true); 1471 },
1518 }); 1472 inferFromOverrides: true);
1519 1473
1520 test('setter/setter override', () { 1474 testChecker('setter/setter override', {
1521 testChecker({ 1475 '/main.dart': '''
1522 '/main.dart': '''
1523 class A {} 1476 class A {}
1524 class B extends A {} 1477 class B extends A {}
1525 class C extends B {} 1478 class C extends B {}
1526 1479
1527 abstract class Base { 1480 abstract class Base {
1528 void set f1(B value); 1481 void set f1(B value);
1529 void set f2(B value); 1482 void set f2(B value);
1530 void set f3(B value); 1483 void set f3(B value);
1531 void set f4(B value); 1484 void set f4(B value);
1532 void set f5(B value); 1485 void set f5(B value);
1533 } 1486 }
1534 1487
1535 class Child extends Base { 1488 class Child extends Base {
1536 void set f1(A value) {} 1489 void set f1(A value) {}
1537 /*severe:InvalidMethodOverride*/void set f2(C value) {} 1490 /*severe:InvalidMethodOverride*/void set f2(C value) {}
1538 /*severe:InvalidMethodOverride*/void set f3(value) {} 1491 /*severe:InvalidMethodOverride*/void set f3(value) {}
1539 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {} 1492 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {}
1540 set f5(B value) {} 1493 set f5(B value) {}
1541 } 1494 }
1542 ''' 1495 '''
1543 });
1544 }); 1496 });
1545 1497
1546 test('field/setter override', () { 1498 testChecker('field/setter override', {
1547 testChecker({ 1499 '/main.dart': '''
1548 '/main.dart': '''
1549 class A {} 1500 class A {}
1550 class B extends A {} 1501 class B extends A {}
1551 class C extends B {} 1502 class C extends B {}
1552 1503
1553 class Base { 1504 class Base {
1554 B f1; 1505 B f1;
1555 B f2; 1506 B f2;
1556 B f3; 1507 B f3;
1557 B f4; 1508 B f4;
1558 B f5; 1509 B f5;
1559 } 1510 }
1560 1511
1561 class Child extends Base { 1512 class Child extends Base {
1562 B get f1 => null; 1513 B get f1 => null;
1563 B get f2 => null; 1514 B get f2 => null;
1564 B get f3 => null; 1515 B get f3 => null;
1565 B get f4 => null; 1516 B get f4 => null;
1566 B get f5 => null; 1517 B get f5 => null;
1567 1518
1568 void set f1(A value) {} 1519 void set f1(A value) {}
1569 /*severe:InvalidMethodOverride*/void set f2(C value) {} 1520 /*severe:InvalidMethodOverride*/void set f2(C value) {}
1570 /*severe:InvalidMethodOverride*/void set f3(value) {} 1521 /*severe:InvalidMethodOverride*/void set f3(value) {}
1571 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {} 1522 /*severe:InvalidMethodOverride*/void set f4(dynamic value) {}
1572 set f5(B value) {} 1523 set f5(B value) {}
1573 } 1524 }
1574 ''' 1525 '''
1575 });
1576 }); 1526 });
1577 1527
1578 test('method override', () { 1528 testChecker(
1579 testChecker({ 1529 'method override',
1580 '/main.dart': ''' 1530 {
1531 '/main.dart': '''
1581 class A {} 1532 class A {}
1582 class B extends A {} 1533 class B extends A {}
1583 class C extends B {} 1534 class C extends B {}
1584 1535
1585 class Base { 1536 class Base {
1586 B m1(B a); 1537 B m1(B a);
1587 B m2(B a); 1538 B m2(B a);
1588 B m3(B a); 1539 B m3(B a);
1589 B m4(B a); 1540 B m4(B a);
1590 B m5(B a); 1541 B m5(B a);
1591 B m6(B a); 1542 B m6(B a);
1592 } 1543 }
1593 1544
1594 class Child extends Base { 1545 class Child extends Base {
1595 /*severe:InvalidMethodOverride*/A m1(A value) {} 1546 /*severe:InvalidMethodOverride*/A m1(A value) {}
1596 /*severe:InvalidMethodOverride*/C m2(C value) {} 1547 /*severe:InvalidMethodOverride*/C m2(C value) {}
1597 /*severe:InvalidMethodOverride*/A m3(C value) {} 1548 /*severe:InvalidMethodOverride*/A m3(C value) {}
1598 C m4(A value) {} 1549 C m4(A value) {}
1599 /*severe:InvalidMethodOverride*/m5(value) {} 1550 /*severe:InvalidMethodOverride*/m5(value) {}
1600 /*severe:InvalidMethodOverride*/dynamic m6(dynamic value) {} 1551 /*severe:InvalidMethodOverride*/dynamic m6(dynamic value) {}
1601 } 1552 }
1602 ''' 1553 '''
1603 }, inferFromOverrides: true); 1554 },
1604 }); 1555 inferFromOverrides: true);
1605 1556
1606 test( 1557 testChecker('unary operators', {
1607 'unary operators', 1558 '/main.dart': '''
1608 () => testChecker({
1609 '/main.dart': '''
1610 class A { 1559 class A {
1611 A operator ~() {} 1560 A operator ~() {}
1612 A operator +(int x) {} 1561 A operator +(int x) {}
1613 A operator -(int x) {} 1562 A operator -(int x) {}
1614 A operator -() {} 1563 A operator -() {}
1615 } 1564 }
1616 1565
1617 foo() => new A(); 1566 foo() => new A();
1618 1567
1619 test() { 1568 test() {
(...skipping 12 matching lines...) Expand all
1632 ++a; 1581 ++a;
1633 --a; 1582 --a;
1634 (/*info:DynamicInvoke*/++d); 1583 (/*info:DynamicInvoke*/++d);
1635 (/*info:DynamicInvoke*/--d); 1584 (/*info:DynamicInvoke*/--d);
1636 1585
1637 a++; 1586 a++;
1638 a--; 1587 a--;
1639 (/*info:DynamicInvoke*/d++); 1588 (/*info:DynamicInvoke*/d++);
1640 (/*info:DynamicInvoke*/d--); 1589 (/*info:DynamicInvoke*/d--);
1641 }''' 1590 }'''
1642 })); 1591 });
1643 1592
1644 test('binary and index operators', () { 1593 testChecker('binary and index operators', {
1645 testChecker({ 1594 '/main.dart': '''
1646 '/main.dart': '''
1647 class A { 1595 class A {
1648 A operator *(B b) {} 1596 A operator *(B b) {}
1649 A operator /(B b) {} 1597 A operator /(B b) {}
1650 A operator ~/(B b) {} 1598 A operator ~/(B b) {}
1651 A operator %(B b) {} 1599 A operator %(B b) {}
1652 A operator +(B b) {} 1600 A operator +(B b) {}
1653 A operator -(B b) {} 1601 A operator -(B b) {}
1654 A operator <<(B b) {} 1602 A operator <<(B b) {}
1655 A operator >>(B b) {} 1603 A operator >>(B b) {}
1656 A operator &(B b) {} 1604 A operator &(B b) {}
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 p = (/*info:DynamicCast*/c) && /*info:DynamicCast*/c; 1646 p = (/*info:DynamicCast*/c) && /*info:DynamicCast*/c;
1699 p = (/*severe:StaticTypeError*/y) && p; 1647 p = (/*severe:StaticTypeError*/y) && p;
1700 p = c == y; 1648 p = c == y;
1701 1649
1702 a = a[b]; 1650 a = a[b];
1703 a = a[/*info:DynamicCast*/c]; 1651 a = a[/*info:DynamicCast*/c];
1704 c = (/*info:DynamicInvoke*/c[b]); 1652 c = (/*info:DynamicInvoke*/c[b]);
1705 a[/*severe:StaticTypeError*/y]; 1653 a[/*severe:StaticTypeError*/y];
1706 } 1654 }
1707 ''' 1655 '''
1708 });
1709 }); 1656 });
1710 1657
1711 test('compound assignments', () { 1658 testChecker('compound assignments', {
1712 testChecker({ 1659 '/main.dart': '''
1713 '/main.dart': '''
1714 class A { 1660 class A {
1715 A operator *(B b) {} 1661 A operator *(B b) {}
1716 A operator /(B b) {} 1662 A operator /(B b) {}
1717 A operator ~/(B b) {} 1663 A operator ~/(B b) {}
1718 A operator %(B b) {} 1664 A operator %(B b) {}
1719 A operator +(B b) {} 1665 A operator +(B b) {}
1720 A operator -(B b) {} 1666 A operator -(B b) {}
1721 A operator <<(B b) {} 1667 A operator <<(B b) {}
1722 A operator >>(B b) {} 1668 A operator >>(B b) {}
1723 A operator &(B b) {} 1669 A operator &(B b) {}
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 1728
1783 var d = new D(); 1729 var d = new D();
1784 a[b] += d; 1730 a[b] += d;
1785 a[/*info:DynamicCast*/c] += d; 1731 a[/*info:DynamicCast*/c] += d;
1786 a[/*severe:StaticTypeError*/z] += d; 1732 a[/*severe:StaticTypeError*/z] += d;
1787 a[b] += /*info:DynamicCast*/c; 1733 a[b] += /*info:DynamicCast*/c;
1788 a[b] += /*severe:StaticTypeError*/z; 1734 a[b] += /*severe:StaticTypeError*/z;
1789 (/*info:DynamicInvoke*/(/*info:DynamicInvoke*/c[b]) += d); 1735 (/*info:DynamicInvoke*/(/*info:DynamicInvoke*/c[b]) += d);
1790 } 1736 }
1791 ''' 1737 '''
1792 });
1793 }); 1738 });
1794 1739
1795 test('super call placement', () { 1740 testChecker('super call placement', {
1796 testChecker({ 1741 '/main.dart': '''
1797 '/main.dart': '''
1798 class Base { 1742 class Base {
1799 var x; 1743 var x;
1800 Base() : x = print('Base.1') { print('Base.2'); } 1744 Base() : x = print('Base.1') { print('Base.2'); }
1801 } 1745 }
1802 1746
1803 class Derived extends Base { 1747 class Derived extends Base {
1804 var y, z; 1748 var y, z;
1805 Derived() 1749 Derived()
1806 : y = print('Derived.1'), 1750 : y = print('Derived.1'),
1807 /*severe:InvalidSuperInvocation*/super(), 1751 /*severe:InvalidSuperInvocation*/super(),
(...skipping 11 matching lines...) Expand all
1819 print('Valid.3'); 1763 print('Valid.3');
1820 } 1764 }
1821 } 1765 }
1822 1766
1823 class AlsoValid extends Base { 1767 class AlsoValid extends Base {
1824 AlsoValid() : super(); 1768 AlsoValid() : super();
1825 } 1769 }
1826 1770
1827 main() => new Derived(); 1771 main() => new Derived();
1828 ''' 1772 '''
1829 });
1830 }); 1773 });
1831 1774
1832 test('for loop variable', () { 1775 testChecker('for loop variable', {
1833 testChecker({ 1776 '/main.dart': '''
1834 '/main.dart': '''
1835 foo() { 1777 foo() {
1836 for (int i = 0; i < 10; i++) { 1778 for (int i = 0; i < 10; i++) {
1837 i = /*severe:StaticTypeError*/"hi"; 1779 i = /*severe:StaticTypeError*/"hi";
1838 } 1780 }
1839 } 1781 }
1840 bar() { 1782 bar() {
1841 for (var i = 0; i < 10; i++) { 1783 for (var i = 0; i < 10; i++) {
1842 int j = i + 1; 1784 int j = i + 1;
1843 } 1785 }
1844 } 1786 }
1845 ''' 1787 '''
1846 });
1847 }); 1788 });
1848 1789
1849 group('invalid overrides', () { 1790 group('invalid overrides', () {
1850 test('child override', () { 1791 testChecker('child override', {
1851 testChecker({ 1792 '/main.dart': '''
1852 '/main.dart': '''
1853 class A {} 1793 class A {}
1854 class B {} 1794 class B {}
1855 1795
1856 class Base { 1796 class Base {
1857 A f; 1797 A f;
1858 } 1798 }
1859 1799
1860 class T1 extends Base { 1800 class T1 extends Base {
1861 /*severe:InvalidMethodOverride*/B get f => null; 1801 /*severe:InvalidMethodOverride*/B get f => null;
1862 } 1802 }
1863 1803
1864 class T2 extends Base { 1804 class T2 extends Base {
1865 /*severe:InvalidMethodOverride*/set f(B b) => null; 1805 /*severe:InvalidMethodOverride*/set f(B b) => null;
1866 } 1806 }
1867 1807
1868 class T3 extends Base { 1808 class T3 extends Base {
1869 /*severe:InvalidMethodOverride*/final B f; 1809 /*severe:InvalidMethodOverride*/final B f;
1870 } 1810 }
1871 class T4 extends Base { 1811 class T4 extends Base {
1872 // two: one for the getter one for the setter. 1812 // two: one for the getter one for the setter.
1873 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/B f; 1813 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/B f;
1874 } 1814 }
1875 ''' 1815 '''
1876 }); 1816 });
1877 1817
1878 testChecker({ 1818 testChecker('child override 2', {
1879 '/main.dart': ''' 1819 '/main.dart': '''
1880 class A {} 1820 class A {}
1881 class B {} 1821 class B {}
1882 1822
1883 class Base { 1823 class Base {
1884 m(A a) {} 1824 m(A a) {}
1885 } 1825 }
1886 1826
1887 class Test extends Base { 1827 class Test extends Base {
1888 /*severe:InvalidMethodOverride*/m(B a) {} 1828 /*severe:InvalidMethodOverride*/m(B a) {}
1889 } 1829 }
1890 ''' 1830 '''
1891 });
1892 }); 1831 });
1893 test('grandchild override', () { 1832 testChecker('grandchild override', {
1894 testChecker({ 1833 '/main.dart': '''
1895 '/main.dart': '''
1896 class A {} 1834 class A {}
1897 class B {} 1835 class B {}
1898 1836
1899 class Grandparent { 1837 class Grandparent {
1900 m(A a) {} 1838 m(A a) {}
1901 } 1839 }
1902 class Parent extends Grandparent { 1840 class Parent extends Grandparent {
1903 } 1841 }
1904 1842
1905 class Test extends Parent { 1843 class Test extends Parent {
1906 /*severe:InvalidMethodOverride*/m(B a) {} 1844 /*severe:InvalidMethodOverride*/m(B a) {}
1907 } 1845 }
1908 ''' 1846 '''
1909 });
1910 }); 1847 });
1911 1848
1912 test('double override', () { 1849 testChecker('double override', {
1913 testChecker({ 1850 '/main.dart': '''
1914 '/main.dart': '''
1915 class A {} 1851 class A {}
1916 class B {} 1852 class B {}
1917 1853
1918 class Grandparent { 1854 class Grandparent {
1919 m(A a) {} 1855 m(A a) {}
1920 } 1856 }
1921 class Parent extends Grandparent { 1857 class Parent extends Grandparent {
1922 m(A a) {} 1858 m(A a) {}
1923 } 1859 }
1924 1860
1925 class Test extends Parent { 1861 class Test extends Parent {
1926 // Reported only once 1862 // Reported only once
1927 /*severe:InvalidMethodOverride*/m(B a) {} 1863 /*severe:InvalidMethodOverride*/m(B a) {}
1928 } 1864 }
1929 ''' 1865 '''
1930 }); 1866 });
1931 1867
1932 testChecker({ 1868 testChecker('double override 2', {
1933 '/main.dart': ''' 1869 '/main.dart': '''
1934 class A {} 1870 class A {}
1935 class B {} 1871 class B {}
1936 1872
1937 class Grandparent { 1873 class Grandparent {
1938 m(A a) {} 1874 m(A a) {}
1939 } 1875 }
1940 class Parent extends Grandparent { 1876 class Parent extends Grandparent {
1941 /*severe:InvalidMethodOverride*/m(B a) {} 1877 /*severe:InvalidMethodOverride*/m(B a) {}
1942 } 1878 }
1943 1879
1944 class Test extends Parent { 1880 class Test extends Parent {
1945 m(B a) {} 1881 m(B a) {}
1946 } 1882 }
1947 ''' 1883 '''
1948 });
1949 }); 1884 });
1950 1885
1951 test('mixin override to base', () { 1886 testChecker('mixin override to base', {
1952 testChecker({ 1887 '/main.dart': '''
1953 '/main.dart': '''
1954 class A {} 1888 class A {}
1955 class B {} 1889 class B {}
1956 1890
1957 class Base { 1891 class Base {
1958 m(A a) {} 1892 m(A a) {}
1959 } 1893 }
1960 1894
1961 class M1 { 1895 class M1 {
1962 m(B a) {} 1896 m(B a) {}
1963 } 1897 }
1964 1898
1965 class M2 {} 1899 class M2 {}
1966 1900
1967 class T1 extends Base with /*severe:InvalidMethodOverride*/M1 {} 1901 class T1 extends Base with /*severe:InvalidMethodOverride*/M1 {}
1968 class T2 extends Base with /*severe:InvalidMethodOverride*/M1, M2 {} 1902 class T2 extends Base with /*severe:InvalidMethodOverride*/M1, M2 {}
1969 class T3 extends Base with M2, /*severe:InvalidMethodOverride*/M1 {} 1903 class T3 extends Base with M2, /*severe:InvalidMethodOverride*/M1 {}
1970 ''' 1904 '''
1971 });
1972 }); 1905 });
1973 1906
1974 test('mixin override to mixin', () { 1907 testChecker('mixin override to mixin', {
1975 testChecker({ 1908 '/main.dart': '''
1976 '/main.dart': '''
1977 class A {} 1909 class A {}
1978 class B {} 1910 class B {}
1979 1911
1980 class Base { 1912 class Base {
1981 } 1913 }
1982 1914
1983 class M1 { 1915 class M1 {
1984 m(B a) {} 1916 m(B a) {}
1985 } 1917 }
1986 1918
1987 class M2 { 1919 class M2 {
1988 m(A a) {} 1920 m(A a) {}
1989 } 1921 }
1990 1922
1991 class T1 extends Base with M1, /*severe:InvalidMethodOverride*/M2 {} 1923 class T1 extends Base with M1, /*severe:InvalidMethodOverride*/M2 {}
1992 ''' 1924 '''
1993 });
1994 }); 1925 });
1995 1926
1996 test('no duplicate mixin override', () { 1927 // This is a regression test for a bug in an earlier implementation were
1997 // This is a regression test for a bug in an earlier implementation were 1928 // names were hiding errors if the first mixin override looked correct,
1998 // names were hiding errors if the first mixin override looked correct, 1929 // but subsequent ones did not.
1999 // but subsequent ones did not. 1930 testChecker('no duplicate mixin override', {
2000 testChecker({ 1931 '/main.dart': '''
2001 '/main.dart': '''
2002 class A {} 1932 class A {}
2003 class B {} 1933 class B {}
2004 1934
2005 class Base { 1935 class Base {
2006 m(A a) {} 1936 m(A a) {}
2007 } 1937 }
2008 1938
2009 class M1 { 1939 class M1 {
2010 m(A a) {} 1940 m(A a) {}
2011 } 1941 }
2012 1942
2013 class M2 { 1943 class M2 {
2014 m(B a) {} 1944 m(B a) {}
2015 } 1945 }
2016 1946
2017 class M3 { 1947 class M3 {
2018 m(B a) {} 1948 m(B a) {}
2019 } 1949 }
2020 1950
2021 class T1 extends Base 1951 class T1 extends Base
2022 with M1, /*severe:InvalidMethodOverride*/M2, M3 {} 1952 with M1, /*severe:InvalidMethodOverride*/M2, M3 {}
2023 ''' 1953 '''
2024 });
2025 }); 1954 });
2026 1955
2027 test('class override of interface', () { 1956 testChecker('class override of interface', {
2028 testChecker({ 1957 '/main.dart': '''
2029 '/main.dart': '''
2030 class A {} 1958 class A {}
2031 class B {} 1959 class B {}
2032 1960
2033 abstract class I { 1961 abstract class I {
2034 m(A a); 1962 m(A a);
2035 } 1963 }
2036 1964
2037 class T1 implements I { 1965 class T1 implements I {
2038 /*severe:InvalidMethodOverride*/m(B a) {} 1966 /*severe:InvalidMethodOverride*/m(B a) {}
2039 } 1967 }
2040 ''' 1968 '''
2041 });
2042 }); 1969 });
2043 1970
2044 test('base class override to child interface', () { 1971 testChecker('base class override to child interface', {
2045 testChecker({ 1972 '/main.dart': '''
2046 '/main.dart': '''
2047 class A {} 1973 class A {}
2048 class B {} 1974 class B {}
2049 1975
2050 abstract class I { 1976 abstract class I {
2051 m(A a); 1977 m(A a);
2052 } 1978 }
2053 1979
2054 class Base { 1980 class Base {
2055 m(B a) {} 1981 m(B a) {}
2056 } 1982 }
2057 1983
2058 1984
2059 class T1 /*severe:InvalidMethodOverride*/extends Base implements I { 1985 class T1 /*severe:InvalidMethodOverride*/extends Base implements I {
2060 } 1986 }
2061 ''' 1987 '''
2062 });
2063 }); 1988 });
2064 1989
2065 test('mixin override of interface', () { 1990 testChecker('mixin override of interface', {
2066 testChecker({ 1991 '/main.dart': '''
2067 '/main.dart': '''
2068 class A {} 1992 class A {}
2069 class B {} 1993 class B {}
2070 1994
2071 abstract class I { 1995 abstract class I {
2072 m(A a); 1996 m(A a);
2073 } 1997 }
2074 1998
2075 class M { 1999 class M {
2076 m(B a) {} 2000 m(B a) {}
2077 } 2001 }
2078 2002
2079 class T1 extends Object with /*severe:InvalidMethodOverride*/M 2003 class T1 extends Object with /*severe:InvalidMethodOverride*/M
2080 implements I {} 2004 implements I {}
2081 ''' 2005 '''
2082 });
2083 }); 2006 });
2084 2007
2085 test('no errors if subclass correctly overrides base and interface', () { 2008 // This is a case were it is incorrect to say that the base class
2086 // This is a case were it is incorrect to say that the base class 2009 // incorrectly overrides the interface.
2087 // incorrectly overrides the interface. 2010 testChecker(
2088 testChecker({ 2011 'no errors if subclass correctly overrides base and interface', {
2089 '/main.dart': ''' 2012 '/main.dart': '''
2090 class A {} 2013 class A {}
2091 class B {} 2014 class B {}
2092 2015
2093 class Base { 2016 class Base {
2094 m(A a) {} 2017 m(A a) {}
2095 } 2018 }
2096 2019
2097 class I1 { 2020 class I1 {
2098 m(B a) {} 2021 m(B a) {}
2099 } 2022 }
2100 2023
2101 class T1 /*severe:InvalidMethodOverride*/extends Base 2024 class T1 /*severe:InvalidMethodOverride*/extends Base
2102 implements I1 {} 2025 implements I1 {}
2103 2026
2104 class T2 extends Base implements I1 { 2027 class T2 extends Base implements I1 {
2105 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a ) {} 2028 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a ) {}
2106 } 2029 }
2107 2030
2108 class T3 extends Object with /*severe:InvalidMethodOverride*/Base 2031 class T3 extends Object with /*severe:InvalidMethodOverride*/Base
2109 implements I1 {} 2032 implements I1 {}
2110 2033
2111 class T4 extends Object with Base implements I1 { 2034 class T4 extends Object with Base implements I1 {
2112 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a ) {} 2035 /*severe:InvalidMethodOverride,severe:InvalidMethodOverride*/m(a ) {}
2113 } 2036 }
2114 ''' 2037 '''
2115 });
2116 }); 2038 });
2039 });
2117 2040
2118 group('class override of grand interface', () { 2041 group('class override of grand interface', () {
2119 test('interface of interface of child', () { 2042 testChecker('interface of interface of child', {
2120 testChecker({ 2043 '/main.dart': '''
2121 '/main.dart': '''
2122 class A {} 2044 class A {}
2123 class B {} 2045 class B {}
2124 2046
2125 abstract class I1 { 2047 abstract class I1 {
2126 m(A a); 2048 m(A a);
2127 } 2049 }
2128 abstract class I2 implements I1 {} 2050 abstract class I2 implements I1 {}
2129 2051
2130 class T1 implements I2 { 2052 class T1 implements I2 {
2131 /*severe:InvalidMethodOverride*/m(B a) {} 2053 /*severe:InvalidMethodOverride*/m(B a) {}
2132 } 2054 }
2133 ''' 2055 '''
2134 }); 2056 });
2135 }); 2057 testChecker('superclass of interface of child', {
2136 test('superclass of interface of child', () { 2058 '/main.dart': '''
2137 testChecker({
2138 '/main.dart': '''
2139 class A {} 2059 class A {}
2140 class B {} 2060 class B {}
2141 2061
2142 abstract class I1 { 2062 abstract class I1 {
2143 m(A a); 2063 m(A a);
2144 } 2064 }
2145 abstract class I2 extends I1 {} 2065 abstract class I2 extends I1 {}
2146 2066
2147 class T1 implements I2 { 2067 class T1 implements I2 {
2148 /*severe:InvalidMethodOverride*/m(B a) {} 2068 /*severe:InvalidMethodOverride*/m(B a) {}
2149 } 2069 }
2150 ''' 2070 '''
2151 }); 2071 });
2152 }); 2072 testChecker('mixin of interface of child', {
2153 test('mixin of interface of child', () { 2073 '/main.dart': '''
2154 testChecker({
2155 '/main.dart': '''
2156 class A {} 2074 class A {}
2157 class B {} 2075 class B {}
2158 2076
2159 abstract class M1 { 2077 abstract class M1 {
2160 m(A a); 2078 m(A a);
2161 } 2079 }
2162 abstract class I2 extends Object with M1 {} 2080 abstract class I2 extends Object with M1 {}
2163 2081
2164 class T1 implements I2 { 2082 class T1 implements I2 {
2165 /*severe:InvalidMethodOverride*/m(B a) {} 2083 /*severe:InvalidMethodOverride*/m(B a) {}
2166 } 2084 }
2167 ''' 2085 '''
2168 }); 2086 });
2169 }); 2087 testChecker('interface of abstract superclass', {
2170 test('interface of abstract superclass', () { 2088 '/main.dart': '''
2171 testChecker({
2172 '/main.dart': '''
2173 class A {} 2089 class A {}
2174 class B {} 2090 class B {}
2175 2091
2176 abstract class I1 { 2092 abstract class I1 {
2177 m(A a); 2093 m(A a);
2178 } 2094 }
2179 abstract class Base implements I1 {} 2095 abstract class Base implements I1 {}
2180 2096
2181 class T1 extends Base { 2097 class T1 extends Base {
2182 /*severe:InvalidMethodOverride*/m(B a) {} 2098 /*severe:InvalidMethodOverride*/m(B a) {}
2183 } 2099 }
2184 ''' 2100 '''
2185 }); 2101 });
2186 }); 2102 testChecker('interface of concrete superclass', {
2187 test('interface of concrete superclass', () { 2103 '/main.dart': '''
2188 testChecker({
2189 '/main.dart': '''
2190 class A {} 2104 class A {}
2191 class B {} 2105 class B {}
2192 2106
2193 abstract class I1 { 2107 abstract class I1 {
2194 m(A a); 2108 m(A a);
2195 } 2109 }
2196 2110
2197 // See issue #25 2111 // See issue #25
2198 /*pass should be warning:AnalyzerError*/class Base implements I1 { 2112 /*pass should be warning:AnalyzerError*/class Base implements I1 {
2199 } 2113 }
2200 2114
2201 class T1 extends Base { 2115 class T1 extends Base {
2202 // not reported technically because if the class is concrete, 2116 // not reported technically because if the class is concrete,
2203 // it should implement all its interfaces and hence it is 2117 // it should implement all its interfaces and hence it is
2204 // sufficient to check overrides against it. 2118 // sufficient to check overrides against it.
2205 m(B a) {} 2119 m(B a) {}
2206 } 2120 }
2207 ''' 2121 '''
2208 });
2209 });
2210 }); 2122 });
2123 });
2211 2124
2212 group('mixin override of grand interface', () { 2125 group('mixin override of grand interface', () {
2213 test('interface of interface of child', () { 2126 testChecker('interface of interface of child', {
2214 testChecker({ 2127 '/main.dart': '''
2215 '/main.dart': '''
2216 class A {} 2128 class A {}
2217 class B {} 2129 class B {}
2218 2130
2219 abstract class I1 { 2131 abstract class I1 {
2220 m(A a); 2132 m(A a);
2221 } 2133 }
2222 abstract class I2 implements I1 {} 2134 abstract class I2 implements I1 {}
2223 2135
2224 class M { 2136 class M {
2225 m(B a) {} 2137 m(B a) {}
2226 } 2138 }
2227 2139
2228 class T1 extends Object with /*severe:InvalidMethodOverride*/M 2140 class T1 extends Object with /*severe:InvalidMethodOverride*/M
2229 implements I2 { 2141 implements I2 {
2230 } 2142 }
2231 ''' 2143 '''
2232 }); 2144 });
2233 }); 2145 testChecker('superclass of interface of child', {
2234 test('superclass of interface of child', () { 2146 '/main.dart': '''
2235 testChecker({
2236 '/main.dart': '''
2237 class A {} 2147 class A {}
2238 class B {} 2148 class B {}
2239 2149
2240 abstract class I1 { 2150 abstract class I1 {
2241 m(A a); 2151 m(A a);
2242 } 2152 }
2243 abstract class I2 extends I1 {} 2153 abstract class I2 extends I1 {}
2244 2154
2245 class M { 2155 class M {
2246 m(B a) {} 2156 m(B a) {}
2247 } 2157 }
2248 2158
2249 class T1 extends Object with /*severe:InvalidMethodOverride*/M 2159 class T1 extends Object with /*severe:InvalidMethodOverride*/M
2250 implements I2 { 2160 implements I2 {
2251 } 2161 }
2252 ''' 2162 '''
2253 }); 2163 });
2254 }); 2164 testChecker('mixin of interface of child', {
2255 test('mixin of interface of child', () { 2165 '/main.dart': '''
2256 testChecker({
2257 '/main.dart': '''
2258 class A {} 2166 class A {}
2259 class B {} 2167 class B {}
2260 2168
2261 abstract class M1 { 2169 abstract class M1 {
2262 m(A a); 2170 m(A a);
2263 } 2171 }
2264 abstract class I2 extends Object with M1 {} 2172 abstract class I2 extends Object with M1 {}
2265 2173
2266 class M { 2174 class M {
2267 m(B a) {} 2175 m(B a) {}
2268 } 2176 }
2269 2177
2270 class T1 extends Object with /*severe:InvalidMethodOverride*/M 2178 class T1 extends Object with /*severe:InvalidMethodOverride*/M
2271 implements I2 { 2179 implements I2 {
2272 } 2180 }
2273 ''' 2181 '''
2274 }); 2182 });
2275 }); 2183 testChecker('interface of abstract superclass', {
2276 test('interface of abstract superclass', () { 2184 '/main.dart': '''
2277 testChecker({
2278 '/main.dart': '''
2279 class A {} 2185 class A {}
2280 class B {} 2186 class B {}
2281 2187
2282 abstract class I1 { 2188 abstract class I1 {
2283 m(A a); 2189 m(A a);
2284 } 2190 }
2285 abstract class Base implements I1 {} 2191 abstract class Base implements I1 {}
2286 2192
2287 class M { 2193 class M {
2288 m(B a) {} 2194 m(B a) {}
2289 } 2195 }
2290 2196
2291 class T1 extends Base with /*severe:InvalidMethodOverride*/M { 2197 class T1 extends Base with /*severe:InvalidMethodOverride*/M {
2292 } 2198 }
2293 ''' 2199 '''
2294 }); 2200 });
2295 }); 2201 testChecker('interface of concrete superclass', {
2296 test('interface of concrete superclass', () { 2202 '/main.dart': '''
2297 testChecker({
2298 '/main.dart': '''
2299 class A {} 2203 class A {}
2300 class B {} 2204 class B {}
2301 2205
2302 abstract class I1 { 2206 abstract class I1 {
2303 m(A a); 2207 m(A a);
2304 } 2208 }
2305 2209
2306 // See issue #25 2210 // See issue #25
2307 /*pass should be warning:AnalyzerError*/class Base implements I1 { 2211 /*pass should be warning:AnalyzerError*/class Base implements I1 {
2308 } 2212 }
2309 2213
2310 class M { 2214 class M {
2311 m(B a) {} 2215 m(B a) {}
2312 } 2216 }
2313 2217
2314 class T1 extends Base with M { 2218 class T1 extends Base with M {
2315 } 2219 }
2316 ''' 2220 '''
2317 });
2318 });
2319 }); 2221 });
2222 });
2320 2223
2321 group('superclass override of grand interface', () { 2224 group('superclass override of grand interface', () {
2322 test('interface of interface of child', () { 2225 testChecker('interface of interface of child', {
2323 testChecker({ 2226 '/main.dart': '''
2324 '/main.dart': '''
2325 class A {} 2227 class A {}
2326 class B {} 2228 class B {}
2327 2229
2328 abstract class I1 { 2230 abstract class I1 {
2329 m(A a); 2231 m(A a);
2330 } 2232 }
2331 abstract class I2 implements I1 {} 2233 abstract class I2 implements I1 {}
2332 2234
2333 class Base { 2235 class Base {
2334 m(B a) {} 2236 m(B a) {}
2335 } 2237 }
2336 2238
2337 class T1 /*severe:InvalidMethodOverride*/extends Base 2239 class T1 /*severe:InvalidMethodOverride*/extends Base
2338 implements I2 { 2240 implements I2 {
2339 } 2241 }
2340 ''' 2242 '''
2341 }); 2243 });
2342 }); 2244 testChecker('superclass of interface of child', {
2343 test('superclass of interface of child', () { 2245 '/main.dart': '''
2344 testChecker({
2345 '/main.dart': '''
2346 class A {} 2246 class A {}
2347 class B {} 2247 class B {}
2348 2248
2349 abstract class I1 { 2249 abstract class I1 {
2350 m(A a); 2250 m(A a);
2351 } 2251 }
2352 abstract class I2 extends I1 {} 2252 abstract class I2 extends I1 {}
2353 2253
2354 class Base { 2254 class Base {
2355 m(B a) {} 2255 m(B a) {}
2356 } 2256 }
2357 2257
2358 class T1 /*severe:InvalidMethodOverride*/extends Base 2258 class T1 /*severe:InvalidMethodOverride*/extends Base
2359 implements I2 { 2259 implements I2 {
2360 } 2260 }
2361 ''' 2261 '''
2362 }); 2262 });
2363 }); 2263 testChecker('mixin of interface of child', {
2364 test('mixin of interface of child', () { 2264 '/main.dart': '''
2365 testChecker({
2366 '/main.dart': '''
2367 class A {} 2265 class A {}
2368 class B {} 2266 class B {}
2369 2267
2370 abstract class M1 { 2268 abstract class M1 {
2371 m(A a); 2269 m(A a);
2372 } 2270 }
2373 abstract class I2 extends Object with M1 {} 2271 abstract class I2 extends Object with M1 {}
2374 2272
2375 class Base { 2273 class Base {
2376 m(B a) {} 2274 m(B a) {}
2377 } 2275 }
2378 2276
2379 class T1 /*severe:InvalidMethodOverride*/extends Base 2277 class T1 /*severe:InvalidMethodOverride*/extends Base
2380 implements I2 { 2278 implements I2 {
2381 } 2279 }
2382 ''' 2280 '''
2383 }); 2281 });
2384 }); 2282 testChecker('interface of abstract superclass', {
2385 test('interface of abstract superclass', () { 2283 '/main.dart': '''
2386 testChecker({
2387 '/main.dart': '''
2388 class A {} 2284 class A {}
2389 class B {} 2285 class B {}
2390 2286
2391 abstract class I1 { 2287 abstract class I1 {
2392 m(A a); 2288 m(A a);
2393 } 2289 }
2394 2290
2395 abstract class Base implements I1 { 2291 abstract class Base implements I1 {
2396 /*severe:InvalidMethodOverride*/m(B a) {} 2292 /*severe:InvalidMethodOverride*/m(B a) {}
2397 } 2293 }
2398 2294
2399 class T1 extends Base { 2295 class T1 extends Base {
2400 // we consider the base class incomplete because it is 2296 // we consider the base class incomplete because it is
2401 // abstract, so we report the error here too. 2297 // abstract, so we report the error here too.
2402 // TODO(sigmund): consider tracking overrides in a fine-grain 2298 // TODO(sigmund): consider tracking overrides in a fine-grain
2403 // manner, then this and the double-overrides would not be 2299 // manner, then this and the double-overrides would not be
2404 // reported. 2300 // reported.
2405 /*severe:InvalidMethodOverride*/m(B a) {} 2301 /*severe:InvalidMethodOverride*/m(B a) {}
2406 } 2302 }
2407 ''' 2303 '''
2408 }); 2304 });
2409 }); 2305 testChecker('interface of concrete superclass', {
2410 test('interface of concrete superclass', () { 2306 '/main.dart': '''
2411 testChecker({
2412 '/main.dart': '''
2413 class A {} 2307 class A {}
2414 class B {} 2308 class B {}
2415 2309
2416 abstract class I1 { 2310 abstract class I1 {
2417 m(A a); 2311 m(A a);
2418 } 2312 }
2419 2313
2420 class Base implements I1 { 2314 class Base implements I1 {
2421 /*severe:InvalidMethodOverride*/m(B a) {} 2315 /*severe:InvalidMethodOverride*/m(B a) {}
2422 } 2316 }
2423 2317
2424 class T1 extends Base { 2318 class T1 extends Base {
2425 m(B a) {} 2319 m(B a) {}
2426 } 2320 }
2427 ''' 2321 '''
2428 });
2429 });
2430 }); 2322 });
2323 });
2431 2324
2432 group('no duplicate reports from overriding interfaces', () { 2325 group('no duplicate reports from overriding interfaces', () {
2433 test('type overrides same method in multiple interfaces', () { 2326 testChecker('type overrides same method in multiple interfaces', {
2434 testChecker({ 2327 '/main.dart': '''
2435 '/main.dart': '''
2436 class A {} 2328 class A {}
2437 class B {} 2329 class B {}
2438 2330
2439 abstract class I1 { 2331 abstract class I1 {
2440 m(A a); 2332 m(A a);
2441 } 2333 }
2442 abstract class I2 implements I1 { 2334 abstract class I2 implements I1 {
2443 m(A a); 2335 m(A a);
2444 } 2336 }
2445 2337
2446 class Base { 2338 class Base {
2447 } 2339 }
2448 2340
2449 class T1 implements I2 { 2341 class T1 implements I2 {
2450 /*severe:InvalidMethodOverride*/m(B a) {} 2342 /*severe:InvalidMethodOverride*/m(B a) {}
2451 } 2343 }
2452 ''' 2344 '''
2453 }); 2345 });
2454 });
2455 2346
2456 test('type and base type override same method in interface', () { 2347 testChecker('type and base type override same method in interface', {
2457 testChecker({ 2348 '/main.dart': '''
2458 '/main.dart': '''
2459 class A {} 2349 class A {}
2460 class B {} 2350 class B {}
2461 2351
2462 abstract class I1 { 2352 abstract class I1 {
2463 m(A a); 2353 m(A a);
2464 } 2354 }
2465 2355
2466 class Base { 2356 class Base {
2467 m(B a); 2357 m(B a);
2468 } 2358 }
2469 2359
2470 // Note: no error reported in `extends Base` to avoid duplicating 2360 // Note: no error reported in `extends Base` to avoid duplicating
2471 // the error in T1. 2361 // the error in T1.
2472 class T1 extends Base implements I1 { 2362 class T1 extends Base implements I1 {
2473 /*severe:InvalidMethodOverride*/m(B a) {} 2363 /*severe:InvalidMethodOverride*/m(B a) {}
2474 } 2364 }
2475 2365
2476 // If there is no error in the class, we do report the error at 2366 // If there is no error in the class, we do report the error at
2477 // the base class: 2367 // the base class:
2478 class T2 /*severe:InvalidMethodOverride*/extends Base 2368 class T2 /*severe:InvalidMethodOverride*/extends Base
2479 implements I1 { 2369 implements I1 {
2480 } 2370 }
2481 ''' 2371 '''
2482 }); 2372 });
2483 });
2484 2373
2485 test('type and mixin override same method in interface', () { 2374 testChecker('type and mixin override same method in interface', {
2486 testChecker({ 2375 '/main.dart': '''
2487 '/main.dart': '''
2488 class A {} 2376 class A {}
2489 class B {} 2377 class B {}
2490 2378
2491 abstract class I1 { 2379 abstract class I1 {
2492 m(A a); 2380 m(A a);
2493 } 2381 }
2494 2382
2495 class M { 2383 class M {
2496 m(B a); 2384 m(B a);
2497 } 2385 }
2498 2386
2499 class T1 extends Object with M implements I1 { 2387 class T1 extends Object with M implements I1 {
2500 /*severe:InvalidMethodOverride*/m(B a) {} 2388 /*severe:InvalidMethodOverride*/m(B a) {}
2501 } 2389 }
2502 2390
2503 class T2 extends Object with /*severe:InvalidMethodOverride*/M 2391 class T2 extends Object with /*severe:InvalidMethodOverride*/M
2504 implements I1 { 2392 implements I1 {
2505 } 2393 }
2506 ''' 2394 '''
2507 }); 2395 });
2508 });
2509 2396
2510 test('two grand types override same method in interface', () { 2397 testChecker('two grand types override same method in interface', {
2511 testChecker({ 2398 '/main.dart': '''
2512 '/main.dart': '''
2513 class A {} 2399 class A {}
2514 class B {} 2400 class B {}
2515 2401
2516 abstract class I1 { 2402 abstract class I1 {
2517 m(A a); 2403 m(A a);
2518 } 2404 }
2519 2405
2520 class Grandparent { 2406 class Grandparent {
2521 m(B a) {} 2407 m(B a) {}
2522 } 2408 }
2523 2409
2524 class Parent1 extends Grandparent { 2410 class Parent1 extends Grandparent {
2525 m(B a) {} 2411 m(B a) {}
2526 } 2412 }
2527 class Parent2 extends Grandparent { 2413 class Parent2 extends Grandparent {
2528 } 2414 }
2529 2415
2530 // Note: otherwise both errors would be reported on this line 2416 // Note: otherwise both errors would be reported on this line
2531 class T1 /*severe:InvalidMethodOverride*/extends Parent1 2417 class T1 /*severe:InvalidMethodOverride*/extends Parent1
2532 implements I1 { 2418 implements I1 {
2533 } 2419 }
2534 class T2 /*severe:InvalidMethodOverride*/extends Parent2 2420 class T2 /*severe:InvalidMethodOverride*/extends Parent2
2535 implements I1 { 2421 implements I1 {
2536 } 2422 }
2537 ''' 2423 '''
2538 }); 2424 });
2539 });
2540 2425
2541 test('two mixins override same method in interface', () { 2426 testChecker('two mixins override same method in interface', {
2542 testChecker({ 2427 '/main.dart': '''
2543 '/main.dart': '''
2544 class A {} 2428 class A {}
2545 class B {} 2429 class B {}
2546 2430
2547 abstract class I1 { 2431 abstract class I1 {
2548 m(A a); 2432 m(A a);
2549 } 2433 }
2550 2434
2551 class M1 { 2435 class M1 {
2552 m(B a) {} 2436 m(B a) {}
2553 } 2437 }
2554 2438
2555 class M2 { 2439 class M2 {
2556 m(B a) {} 2440 m(B a) {}
2557 } 2441 }
2558 2442
2559 // Here we want to report both, because the error location is 2443 // Here we want to report both, because the error location is
2560 // different. 2444 // different.
2561 // TODO(sigmund): should we merge these as well? 2445 // TODO(sigmund): should we merge these as well?
2562 class T1 extends Object 2446 class T1 extends Object
2563 with /*severe:InvalidMethodOverride*/M1 2447 with /*severe:InvalidMethodOverride*/M1
2564 with /*severe:InvalidMethodOverride*/M2 2448 with /*severe:InvalidMethodOverride*/M2
2565 implements I1 { 2449 implements I1 {
2566 } 2450 }
2567 ''' 2451 '''
2568 }); 2452 });
2569 });
2570 2453
2571 test('base type and mixin override same method in interface', () { 2454 testChecker('base type and mixin override same method in interface', {
2572 testChecker({ 2455 '/main.dart': '''
2573 '/main.dart': '''
2574 class A {} 2456 class A {}
2575 class B {} 2457 class B {}
2576 2458
2577 abstract class I1 { 2459 abstract class I1 {
2578 m(A a); 2460 m(A a);
2579 } 2461 }
2580 2462
2581 class Base { 2463 class Base {
2582 m(B a) {} 2464 m(B a) {}
2583 } 2465 }
2584 2466
2585 class M { 2467 class M {
2586 m(B a) {} 2468 m(B a) {}
2587 } 2469 }
2588 2470
2589 // Here we want to report both, because the error location is 2471 // Here we want to report both, because the error location is
2590 // different. 2472 // different.
2591 // TODO(sigmund): should we merge these as well? 2473 // TODO(sigmund): should we merge these as well?
2592 class T1 /*severe:InvalidMethodOverride*/extends Base 2474 class T1 /*severe:InvalidMethodOverride*/extends Base
2593 with /*severe:InvalidMethodOverride*/M 2475 with /*severe:InvalidMethodOverride*/M
2594 implements I1 { 2476 implements I1 {
2595 } 2477 }
2596 ''' 2478 '''
2597 });
2598 });
2599 }); 2479 });
2480 });
2600 2481
2601 test('no reporting of overrides with Object twice.', () { 2482 // This is a regression test: we used to report it twice because it was
2602 // This is a regression test: we used to report it twice because it was 2483 // the top super class and top super interface.
2603 // the top super class and top super interface. 2484 // TODO(sigmund): maybe we generalize this and don't report again errors
2604 // TODO(sigmund): maybe we generalize this and don't report again errors 2485 // when an interface is also a superclass.
2605 // when an interface is also a superclass. 2486 testChecker(
2606 testChecker({ 2487 'no reporting of overrides with Object twice.',
2488 {
2607 '/main.dart': ''' 2489 '/main.dart': '''
2608 class A {} 2490 class A {}
2609 class T1 implements A { 2491 class T1 implements A {
2610 /*severe:InferableOverride*/toString() {} 2492 /*severe:InferableOverride*/toString() {}
2611 } 2493 }
2612 ''' 2494 '''
2613 }, inferFromOverrides: false); 2495 },
2614 }); 2496 inferFromOverrides: false);
2615 });
2616 2497
2617 test('invalid runtime checks', () { 2498 testChecker('invalid runtime checks', {
2618 testChecker({ 2499 '/main.dart': '''
2619 '/main.dart': '''
2620 typedef int I2I(int x); 2500 typedef int I2I(int x);
2621 typedef int D2I(x); 2501 typedef int D2I(x);
2622 typedef int II2I(int x, int y); 2502 typedef int II2I(int x, int y);
2623 typedef int DI2I(x, int y); 2503 typedef int DI2I(x, int y);
2624 typedef int ID2I(int x, y); 2504 typedef int ID2I(int x, y);
2625 typedef int DD2I(x, y); 2505 typedef int DD2I(x, y);
2626 2506
2627 typedef I2D(int x); 2507 typedef I2D(int x);
2628 typedef D2D(x); 2508 typedef D2D(x);
2629 typedef II2D(int x, int y); 2509 typedef II2D(int x, int y);
(...skipping 30 matching lines...) Expand all
2660 f = bar as II2I; 2540 f = bar as II2I;
2661 f = bar as DI2I; 2541 f = bar as DI2I;
2662 f = bar as ID2I; 2542 f = bar as ID2I;
2663 f = bar as II2D; 2543 f = bar as II2D;
2664 f = bar as DD2I; 2544 f = bar as DD2I;
2665 f = bar as DI2D; 2545 f = bar as DI2D;
2666 f = bar as ID2D; 2546 f = bar as ID2D;
2667 f = bar as DD2D; 2547 f = bar as DD2D;
2668 } 2548 }
2669 ''' 2549 '''
2670 });
2671 }); 2550 });
2672 2551
2673 test( 2552 testChecker('custom URL mappings', {
2674 'custom URL mappings', 2553 '/main.dart': '''
2675 () => testChecker({
2676 '/main.dart': '''
2677 import 'dart:foobar' show Baz; 2554 import 'dart:foobar' show Baz;
2678 main() { 2555 main() {
2679 print(Baz.quux); 2556 print(Baz.quux);
2680 }''' 2557 }'''
2681 }, customUrlMappings: { 2558 }, customUrlMappings: {
2682 'dart:foobar': '$testDirectory/checker/dart_foobar.dart' 2559 'dart:foobar': '$testDirectory/checker/dart_foobar.dart'
2683 })); 2560 });
2684 2561
2685 group('function modifiers', () { 2562 group('function modifiers', () {
2686 test( 2563 testChecker('async', {
2687 'async', 2564 '/main.dart': '''
2688 () => testChecker({
2689 '/main.dart': '''
2690 import 'dart:async'; 2565 import 'dart:async';
2691 import 'dart:math' show Random; 2566 import 'dart:math' show Random;
2692 2567
2693 dynamic x; 2568 dynamic x;
2694 2569
2695 foo1() async => x; 2570 foo1() async => x;
2696 Future foo2() async => x; 2571 Future foo2() async => x;
2697 Future<int> foo3() async => (/*info:DynamicCast*/x); 2572 Future<int> foo3() async => (/*info:DynamicCast*/x);
2698 Future<int> foo4() async => (/*severe:StaticTypeError*/new Future<int>.v alue(/*info:DynamicCast*/x)); 2573 Future<int> foo4() async => (/*severe:StaticTypeError*/new Future<int>.v alue(/*info:DynamicCast*/x));
2699 2574
(...skipping 14 matching lines...) Expand all
2714 2589
2715 Future<bool> get issue_264 async { 2590 Future<bool> get issue_264 async {
2716 await 42; 2591 await 42;
2717 if (new Random().nextBool()) { 2592 if (new Random().nextBool()) {
2718 return true; 2593 return true;
2719 } else { 2594 } else {
2720 return /*severe:StaticTypeError*/new Future<bool>.value(false); 2595 return /*severe:StaticTypeError*/new Future<bool>.value(false);
2721 } 2596 }
2722 } 2597 }
2723 ''' 2598 '''
2724 })); 2599 });
2725 2600
2726 test( 2601 testChecker('async*', {
2727 'async*', 2602 '/main.dart': '''
2728 () => testChecker({
2729 '/main.dart': '''
2730 import 'dart:async'; 2603 import 'dart:async';
2731 2604
2732 dynamic x; 2605 dynamic x;
2733 2606
2734 bar1() async* { yield x; } 2607 bar1() async* { yield x; }
2735 Stream bar2() async* { yield x; } 2608 Stream bar2() async* { yield x; }
2736 Stream<int> bar3() async* { yield (/*info:DynamicCast*/x); } 2609 Stream<int> bar3() async* { yield (/*info:DynamicCast*/x); }
2737 Stream<int> bar4() async* { yield (/*severe:StaticTypeError*/new Stream< int>()); } 2610 Stream<int> bar4() async* { yield (/*severe:StaticTypeError*/new Stream< int>()); }
2738 2611
2739 baz1() async* { yield* (/*info:DynamicCast*/x); } 2612 baz1() async* { yield* (/*info:DynamicCast*/x); }
2740 Stream baz2() async* { yield* (/*info:DynamicCast*/x); } 2613 Stream baz2() async* { yield* (/*info:DynamicCast*/x); }
2741 Stream<int> baz3() async* { yield* (/*warning:DownCastComposite*/x); } 2614 Stream<int> baz3() async* { yield* (/*warning:DownCastComposite*/x); }
2742 Stream<int> baz4() async* { yield* new Stream<int>(); } 2615 Stream<int> baz4() async* { yield* new Stream<int>(); }
2743 Stream<int> baz5() async* { yield* (/*info:InferredTypeAllocation*/new S tream()); } 2616 Stream<int> baz5() async* { yield* (/*info:InferredTypeAllocation*/new S tream()); }
2744 ''' 2617 '''
2745 })); 2618 });
2746 2619
2747 test( 2620 testChecker('sync*', {
2748 'sync*', 2621 '/main.dart': '''
2749 () => testChecker({
2750 '/main.dart': '''
2751 import 'dart:async'; 2622 import 'dart:async';
2752 2623
2753 dynamic x; 2624 dynamic x;
2754 2625
2755 bar1() sync* { yield x; } 2626 bar1() sync* { yield x; }
2756 Iterable bar2() sync* { yield x; } 2627 Iterable bar2() sync* { yield x; }
2757 Iterable<int> bar3() sync* { yield (/*info:DynamicCast*/x); } 2628 Iterable<int> bar3() sync* { yield (/*info:DynamicCast*/x); }
2758 Iterable<int> bar4() sync* { yield (/*severe:StaticTypeError*/new Iterab le<int>()); } 2629 Iterable<int> bar4() sync* { yield (/*severe:StaticTypeError*/new Iterab le<int>()); }
2759 2630
2760 baz1() sync* { yield* (/*info:DynamicCast*/x); } 2631 baz1() sync* { yield* (/*info:DynamicCast*/x); }
2761 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); } 2632 Iterable baz2() sync* { yield* (/*info:DynamicCast*/x); }
2762 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); } 2633 Iterable<int> baz3() sync* { yield* (/*warning:DownCastComposite*/x); }
2763 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } 2634 Iterable<int> baz4() sync* { yield* new Iterable<int>(); }
2764 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new Iterable()); } 2635 Iterable<int> baz5() sync* { yield* (/*info:InferredTypeAllocation*/new Iterable()); }
2765 ''' 2636 '''
2766 })); 2637 });
2767 2638
2768 test( 2639 testChecker('dart:math min/max', {
2769 'dart:math min/max', 2640 '/main.dart': '''
2770 () => testChecker({
2771 '/main.dart': '''
2772 import 'dart:math'; 2641 import 'dart:math';
2773 2642
2774 void printInt(int x) => print(x); 2643 void printInt(int x) => print(x);
2775 void printDouble(double x) => print(x); 2644 void printDouble(double x) => print(x);
2776 2645
2777 num myMax(num x, num y) => max(x, y); 2646 num myMax(num x, num y) => max(x, y);
2778 2647
2779 main() { 2648 main() {
2780 // Okay if static types match. 2649 // Okay if static types match.
2781 printInt(max(1, 2)); 2650 printInt(max(1, 2));
(...skipping 11 matching lines...) Expand all
2793 printDouble(/*warning:DownCastImplicit*/max(1, 2.0)); 2662 printDouble(/*warning:DownCastImplicit*/max(1, 2.0));
2794 printDouble(/*warning:DownCastImplicit*/min(1, 2.0)); 2663 printDouble(/*warning:DownCastImplicit*/min(1, 2.0));
2795 2664
2796 // Types other than int and double are not accepted. 2665 // Types other than int and double are not accepted.
2797 printInt( 2666 printInt(
2798 /*warning:DownCastImplicit*/min( 2667 /*warning:DownCastImplicit*/min(
2799 /*severe:StaticTypeError*/"hi", 2668 /*severe:StaticTypeError*/"hi",
2800 /*severe:StaticTypeError*/"there")); 2669 /*severe:StaticTypeError*/"there"));
2801 } 2670 }
2802 ''' 2671 '''
2803 })); 2672 });
2804 }); 2673 });
2805 } 2674 }
OLDNEW
« no previous file with comments | « no previous file | test/checker/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698