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

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

Issue 1780783002: Don't report redundant type errors in strong mode. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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
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';
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 v = (isValidKey != null) 42 v = (isValidKey != null)
43 ? v : (/*info:INFERRED_TYPE_CLOSURE*/(_) => true); 43 ? v : (/*info:INFERRED_TYPE_CLOSURE*/(_) => true);
44 } 44 }
45 } 45 }
46 void main() { 46 void main() {
47 Object obj = 42; 47 Object obj = 42;
48 dynamic dyn = 42; 48 dynamic dyn = 42;
49 int i = 42; 49 int i = 42;
50 50
51 // Check the boolean conversion of the condition. 51 // Check the boolean conversion of the condition.
52 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true); 52 print(/*warning:NON_BOOL_CONDITION*/i ? false : true);
53 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true); 53 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true);
54 print((/*info:DYNAMIC_CAST*/dyn) ? false : true); 54 print((/*info:DYNAMIC_CAST*/dyn) ? false : true);
55 } 55 }
56 '''); 56 ''');
57 }); 57 });
58 58
59 test('if/for/do/while statements use boolean conversion', () { 59 test('if/for/do/while statements use boolean conversion', () {
60 checkFile(''' 60 checkFile('''
61 main() { 61 main() {
62 dynamic dyn = 42; 62 dynamic dyn = 42;
63 Object obj = 42; 63 Object obj = 42;
64 int i = 42; 64 int i = 42;
65 bool b = false; 65 bool b = false;
66 66
67 if (b) {} 67 if (b) {}
68 if (/*info:DYNAMIC_CAST*/dyn) {} 68 if (/*info:DYNAMIC_CAST*/dyn) {}
69 if (/*info:DOWN_CAST_IMPLICIT*/obj) {} 69 if (/*info:DOWN_CAST_IMPLICIT*/obj) {}
70 if (/*severe:STATIC_TYPE_ERROR*/i) {} 70 if (/*warning:NON_BOOL_CONDITION*/i) {}
71 71
72 while (b) {} 72 while (b) {}
73 while (/*info:DYNAMIC_CAST*/dyn) {} 73 while (/*info:DYNAMIC_CAST*/dyn) {}
74 while (/*info:DOWN_CAST_IMPLICIT*/obj) {} 74 while (/*info:DOWN_CAST_IMPLICIT*/obj) {}
75 while (/*severe:STATIC_TYPE_ERROR*/i) {} 75 while (/*warning:NON_BOOL_CONDITION*/i) {}
76 76
77 do {} while (b); 77 do {} while (b);
78 do {} while (/*info:DYNAMIC_CAST*/dyn); 78 do {} while (/*info:DYNAMIC_CAST*/dyn);
79 do {} while (/*info:DOWN_CAST_IMPLICIT*/obj); 79 do {} while (/*info:DOWN_CAST_IMPLICIT*/obj);
80 do {} while (/*severe:STATIC_TYPE_ERROR*/i); 80 do {} while (/*warning:NON_BOOL_CONDITION*/i);
81 81
82 for (;b;) {} 82 for (;b;) {}
83 for (;/*info:DYNAMIC_CAST*/dyn;) {} 83 for (;/*info:DYNAMIC_CAST*/dyn;) {}
84 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} 84 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {}
85 for (;/*severe:STATIC_TYPE_ERROR*/i;) {} 85 for (;/*warning:NON_BOOL_CONDITION*/i;) {}
86 } 86 }
87 '''); 87 ''');
88 }); 88 });
89 89
90 test('dynamic invocation', () { 90 test('dynamic invocation', () {
91 checkFile(''' 91 checkFile('''
92
93 class A { 92 class A {
94 dynamic call(dynamic x) => x; 93 dynamic call(dynamic x) => x;
95 } 94 }
96 class B extends A { 95 class B extends A {
97 int call(int x) => x; 96 int call(int x) => x;
98 double col(double x) => x; 97 double col(double x) => x;
99 } 98 }
100 void main() { 99 void main() {
101 { 100 {
102 B f = new B(); 101 B f = new B();
103 int x; 102 int x;
104 double y; 103 double y;
105 x = f(3); 104 x = f(3);
106 x = /*severe:STATIC_TYPE_ERROR*/f.col(3.0); 105 x = /*warning:INVALID_ASSIGNMENT*/f.col(3.0);
107 y = /*severe:STATIC_TYPE_ERROR*/f(3); 106 y = /*warning:INVALID_ASSIGNMENT*/f(3);
108 y = f.col(3.0); 107 y = f.col(3.0);
109 f(/*severe:STATIC_TYPE_ERROR*/3.0); 108 f(/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3.0);
110 f.col(/*severe:STATIC_TYPE_ERROR*/3); 109 f.col(/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
111 } 110 }
112 { 111 {
113 Function f = new B(); 112 Function f = new B();
114 int x; 113 int x;
115 double y; 114 double y;
116 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); 115 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
117 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0); 116 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE, info:INVALID_ASSIGNMENT* /f.col(3.0);
118 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); 117 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
119 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0); 118 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0);
120 (/*info:DYNAMIC_INVOKE*/f(3.0)); 119 /*info:DYNAMIC_INVOKE*/f(3.0);
121 (/*info:DYNAMIC_INVOKE*/f.col(3)); 120 /*info:DYNAMIC_INVOKE*/f.col(/*info:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
Leaf 2016/03/10 22:58:25 Interesting. I guess this is the propagated type
Bob Nystrom 2016/03/15 00:08:13 Yeah, I think so. That's why it's an info and not
122 } 121 }
123 { 122 {
124 A f = new B(); 123 A f = new B();
125 int x; 124 int x;
126 double y; 125 double y;
127 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); 126 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
128 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); 127 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3);
129 (/*info:DYNAMIC_INVOKE*/f(3.0)); 128 /*info:DYNAMIC_INVOKE*/f(3.0);
130 } 129 }
131 { 130 {
132 dynamic g = new B(); 131 dynamic g = new B();
133 (/*info:DYNAMIC_INVOKE*/g.call(32.0)); 132 /*info:DYNAMIC_INVOKE*/g.call(/*info:ARGUMENT_TYPE_NOT_ASSIGNABLE*/32. 0);
134 (/*info:DYNAMIC_INVOKE*/g.col(42.0)); 133 /*info:DYNAMIC_INVOKE*/g.col(42.0);
135 (/*info:DYNAMIC_INVOKE*/g.foo(42.0)); 134 /*info:DYNAMIC_INVOKE*/g.foo(42.0);
136 (/*info:DYNAMIC_INVOKE*/g./*info:UNDEFINED_GETTER*/x); 135 /*info:DYNAMIC_INVOKE*/g./*info:UNDEFINED_GETTER*/x;
137 A f = new B(); 136 A f = new B();
138 f.call(32.0); 137 f.call(/*info:ARGUMENT_TYPE_NOT_ASSIGNABLE*/32.0);
139 (/*info:DYNAMIC_INVOKE*/f.col(42.0)); 138 /*info:DYNAMIC_INVOKE*/f.col(42.0);
140 (/*info:DYNAMIC_INVOKE*/f.foo(42.0)); 139 /*info:DYNAMIC_INVOKE*/f.foo(42.0);
141 (/*info:DYNAMIC_INVOKE*/f./*warning:UNDEFINED_GETTER*/x); 140 /*info:DYNAMIC_INVOKE*/f./*warning:UNDEFINED_GETTER*/x;
142 } 141 }
143 } 142 }
144 '''); 143 ''');
145 }); 144 });
146 145
147 test('conversion and dynamic invoke', () { 146 test('conversion and dynamic invoke', () {
148 addFile( 147 addFile(
149 ''' 148 '''
150 dynamic toString = (int x) => x + 42; 149 dynamic toString = (int x) => x + 42;
151 dynamic hashCode = "hello"; 150 dynamic hashCode = "hello";
152 ''', 151 ''',
153 name: '/helper.dart'); 152 name: '/helper.dart');
154 checkFile(''' 153 checkFile('''
155 import 'helper.dart' as helper; 154 import 'helper.dart' as helper;
156 155
157 class A { 156 class A {
158 String x = "hello world"; 157 String x = "hello world";
159 158
160 void baz1(y) => x + /*info:DYNAMIC_CAST*/y; 159 void baz1(y) { x + /*info:DYNAMIC_CAST*/y; }
161 static baz2(y) => /*info:DYNAMIC_INVOKE*/y + y; 160 static baz2(y) => /*info:DYNAMIC_INVOKE*/y + y;
162 } 161 }
163 162
164 void foo(String str) { 163 void foo(String str) {
165 print(str); 164 print(str);
166 } 165 }
167 166
168 class B { 167 class B {
169 String toString([int arg]) => arg.toString(); 168 String toString([int arg]) => arg.toString();
170 } 169 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 227
229 test('Constructors', () { 228 test('Constructors', () {
230 checkFile(''' 229 checkFile('''
231 const num z = 25; 230 const num z = 25;
232 Object obj = "world"; 231 Object obj = "world";
233 232
234 class A { 233 class A {
235 int x; 234 int x;
236 String y; 235 String y;
237 236
238 A(this.x) : this.y = /*severe:STATIC_TYPE_ERROR*/42; 237 A(this.x) : this.y = /*warning:FIELD_INITIALIZER_NOT_ASSIGNABLE*/42;
239 238
240 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_ CAST*/p; 239 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_ CAST*/p;
241 240
242 A.c2(this.x, this.y); 241 A.c2(this.x, this.y);
243 242
244 A.c3(/*severe:INVALID_PARAMETER_DECLARATION*/num this.x, String this.y); 243 A.c3(/*severe:INVALID_PARAMETER_DECLARATION*/num this.x, String this.y);
245 } 244 }
246 245
247 class B extends A { 246 class B extends A {
248 B() : super(/*severe:STATIC_TYPE_ERROR*/"hello"); 247 B() : super(/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello");
249 248
250 B.c2(int x, String y) : super.c2(/*severe:STATIC_TYPE_ERROR*/y, 249 B.c2(int x, String y) : super.c2(/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE* /y,
251 /*severe:STATIC_TYPE_ERROR*/x); 250 /*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE* /x);
252 251
253 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/y); 252 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/y);
254 } 253 }
255 254
256 void main() { 255 void main() {
257 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR */z); 256 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*warning:ARGUMENT_TYPE_NO T_ASSIGNABLE*/z);
258 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_ IMPLICIT*/obj); 257 var b = new B.c2(/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/"hello", /*inf o:DOWN_CAST_IMPLICIT*/obj);
259 } 258 }
260 '''); 259 ''');
261 }); 260 });
262 261
263 test('Unbound variable', () { 262 test('Unbound variable', () {
264 checkFile(''' 263 checkFile('''
265 void main() { 264 void main() {
266 dynamic y = /*warning:UNDEFINED_IDENTIFIER should be error*/unboundVari able; 265 dynamic y = /*warning:UNDEFINED_IDENTIFIER should be error*/unboundVari able;
267 } 266 }
268 '''); 267 ''');
269 }); 268 });
270 269
271 test('Unbound type name', () { 270 test('Unbound type name', () {
272 checkFile(''' 271 checkFile('''
273 void main() { 272 void main() {
274 /*warning:UNDEFINED_CLASS should be error*/AToB y; 273 /*warning:UNDEFINED_CLASS should be error*/AToB y;
275 } 274 }
276 '''); 275 ''');
277 }); 276 });
278 277
279 // Regression test for https://github.com/dart-lang/sdk/issues/25069 278 // Regression test for https://github.com/dart-lang/sdk/issues/25069
280 test('Void subtyping', () { 279 test('Void subtyping', () {
281 checkFile(''' 280 checkFile('''
282 typedef int Foo(); 281 typedef int Foo();
283 void foo() {} 282 void foo() {}
284 void main () { 283 void main () {
285 Foo x = /*severe:STATIC_TYPE_ERROR*/foo(); 284 Foo x = /*warning:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo();
286 } 285 }
287 '''); 286 ''');
288 }); 287 });
289 288
290 group('Ground type subtyping:', () { 289 group('Ground type subtyping:', () {
291 test('dynamic is top', () { 290 test('dynamic is top', () {
292 checkFile(''' 291 checkFile('''
293 292
294 class A {} 293 class A {}
295 class B extends A {} 294 class B extends A {}
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 void main() { 344 void main() {
346 dynamic y; 345 dynamic y;
347 Object o; 346 Object o;
348 int i = 0; 347 int i = 0;
349 double d = 0.0; 348 double d = 0.0;
350 num n; 349 num n;
351 A a; 350 A a;
352 B b; 351 B b;
353 y = a; 352 y = a;
354 o = a; 353 o = a;
355 i = /*severe:STATIC_TYPE_ERROR*/a; 354 i = /*warning:INVALID_ASSIGNMENT*/a;
356 d = /*severe:STATIC_TYPE_ERROR*/a; 355 d = /*warning:INVALID_ASSIGNMENT*/a;
357 n = /*severe:STATIC_TYPE_ERROR*/a; 356 n = /*warning:INVALID_ASSIGNMENT*/a;
358 a = a; 357 a = a;
359 b = /*info:DOWN_CAST_IMPLICIT*/a; 358 b = /*info:DOWN_CAST_IMPLICIT*/a;
360 } 359 }
361 '''); 360 ''');
362 }); 361 });
363 362
364 test('assigning a subclass', () { 363 test('assigning a subclass', () {
365 checkFile(''' 364 checkFile('''
366 365
367 class A {} 366 class A {}
368 class B extends A {} 367 class B extends A {}
369 class C extends A {} 368 class C extends A {}
370 369
371 void main() { 370 void main() {
372 dynamic y; 371 dynamic y;
373 Object o; 372 Object o;
374 int i = 0; 373 int i = 0;
375 double d = 0.0; 374 double d = 0.0;
376 num n; 375 num n;
377 A a; 376 A a;
378 B b; 377 B b;
379 C c; 378 C c;
380 y = b; 379 y = b;
381 o = b; 380 o = b;
382 i = /*severe:STATIC_TYPE_ERROR*/b; 381 i = /*warning:INVALID_ASSIGNMENT*/b;
383 d = /*severe:STATIC_TYPE_ERROR*/b; 382 d = /*warning:INVALID_ASSIGNMENT*/b;
384 n = /*severe:STATIC_TYPE_ERROR*/b; 383 n = /*warning:INVALID_ASSIGNMENT*/b;
385 a = b; 384 a = b;
386 b = b; 385 b = b;
387 c = /*severe:STATIC_TYPE_ERROR*/b; 386 c = /*warning:INVALID_ASSIGNMENT*/b;
388 } 387 }
389 '''); 388 ''');
390 }); 389 });
391 390
392 test('interfaces', () { 391 test('interfaces', () {
393 checkFile(''' 392 checkFile('''
394 393
395 class A {} 394 class A {}
396 class B extends A {} 395 class B extends A {}
397 class C extends A {} 396 class C extends A {}
398 class D extends B implements C {} 397 class D extends B implements C {}
399 398
400 void main() { 399 void main() {
401 A top; 400 A top;
402 B left; 401 B left;
403 C right; 402 C right;
404 D bot; 403 D bot;
405 { 404 {
406 top = top; 405 top = top;
407 top = left; 406 top = left;
408 top = right; 407 top = right;
409 top = bot; 408 top = bot;
410 } 409 }
411 { 410 {
412 left = /*info:DOWN_CAST_IMPLICIT*/top; 411 left = /*info:DOWN_CAST_IMPLICIT*/top;
413 left = left; 412 left = left;
414 left = /*severe:STATIC_TYPE_ERROR*/right; 413 left = /*warning:INVALID_ASSIGNMENT*/right;
415 left = bot; 414 left = bot;
416 } 415 }
417 { 416 {
418 right = /*info:DOWN_CAST_IMPLICIT*/top; 417 right = /*info:DOWN_CAST_IMPLICIT*/top;
419 right = /*severe:STATIC_TYPE_ERROR*/left; 418 right = /*warning:INVALID_ASSIGNMENT*/left;
420 right = right; 419 right = right;
421 right = bot; 420 right = bot;
422 } 421 }
423 { 422 {
424 bot = /*info:DOWN_CAST_IMPLICIT*/top; 423 bot = /*info:DOWN_CAST_IMPLICIT*/top;
425 bot = /*info:DOWN_CAST_IMPLICIT*/left; 424 bot = /*info:DOWN_CAST_IMPLICIT*/left;
426 bot = /*info:DOWN_CAST_IMPLICIT*/right; 425 bot = /*info:DOWN_CAST_IMPLICIT*/right;
427 bot = bot; 426 bot = bot;
428 } 427 }
429 } 428 }
430 '''); 429 ''');
431 }); 430 });
432 }); 431 });
433 432
434 group('Function typing and subtyping:', () { 433 group('Function typing and subtyping:', () {
435 test('int and object', () { 434 test('int and object', () {
436 checkFile(''' 435 checkFile('''
437 436
438 typedef Object Top(int x); // Top of the lattice 437 typedef Object Top(int x); // Top of the lattice
439 typedef int Left(int x); // Left branch 438 typedef int Left(int x); // Left branch
440 typedef int Left2(int x); // Left branch 439 typedef int Left2(int x); // Left branch
441 typedef Object Right(Object x); // Right branch 440 typedef Object Right(Object x); // Right branch
442 typedef int Bot(Object x); // Bottom of the lattice 441 typedef int Bot(Object x); // Bottom of the lattice
443 442
444 Object globalTop(int x) => x; 443 Object globalTop(int x) => x;
445 int globalLeft(int x) => x; 444 int globalLeft(int x) => x;
446 Object globalRight(Object x) => x; 445 Object globalRight(Object x) => x;
447 int _bot(Object x) => /*info:DOWN_CAST_IMPLICIT*/x; 446 int bot_(Object x) => /*info:DOWN_CAST_IMPLICIT*/x;
448 int globalBot(Object x) => x as int; 447 int globalBot(Object x) => x as int;
449 448
450 void main() { 449 void main() {
451 // Note: use locals so we only know the type, not that it's a specific 450 // Note: use locals so we only know the type, not that it's a specific
452 // function declaration. (we can issue better errors in that case.) 451 // function declaration. (we can issue better errors in that case.)
453 var top = globalTop; 452 var top = globalTop;
454 var left = globalLeft; 453 var left = globalLeft;
455 var right = globalRight; 454 var right = globalRight;
456 var bot = globalBot; 455 var bot = globalBot;
457 456
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 class A {} 496 class A {}
498 class B extends A {} 497 class B extends A {}
499 498
500 typedef A Top(B x); // Top of the lattice 499 typedef A Top(B x); // Top of the lattice
501 typedef B Left(B x); // Left branch 500 typedef B Left(B x); // Left branch
502 typedef B Left2(B x); // Left branch 501 typedef B Left2(B x); // Left branch
503 typedef A Right(A x); // Right branch 502 typedef A Right(A x); // Right branch
504 typedef B Bot(A x); // Bottom of the lattice 503 typedef B Bot(A x); // Bottom of the lattice
505 504
506 B left(B x) => x; 505 B left(B x) => x;
507 B _bot(A x) => /*info:DOWN_CAST_IMPLICIT*/x; 506 B bot_(A x) => /*info:DOWN_CAST_IMPLICIT*/x;
508 B bot(A x) => x as B; 507 B bot(A x) => x as B;
509 A top(B x) => x; 508 A top(B x) => x;
510 A right(A x) => x; 509 A right(A x) => x;
511 510
512 void main() { 511 void main() {
513 { // Check typedef equality 512 { // Check typedef equality
514 Left f = left; 513 Left f = left;
515 Left2 g = f; 514 Left2 g = f;
516 } 515 }
517 { 516 {
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 class B extends A {} 858 class B extends A {}
860 859
861 typedef T Function2<S, T>(S z); 860 typedef T Function2<S, T>(S z);
862 861
863 typedef A BToA(B x); // Top of the base lattice 862 typedef A BToA(B x); // Top of the base lattice
864 typedef B AToB(A x); // Bot of the base lattice 863 typedef B AToB(A x); // Bot of the base lattice
865 864
866 BToA top(AToB f) => f; 865 BToA top(AToB f) => f;
867 AToB left(AToB f) => f; 866 AToB left(AToB f) => f;
868 BToA right(BToA f) => f; 867 BToA right(BToA f) => f;
869 AToB _bot(BToA f) => /*warning:DOWN_CAST_COMPOSITE*/f; 868 AToB bot_(BToA f) => /*warning:DOWN_CAST_COMPOSITE*/f;
870 AToB bot(BToA f) => f as AToB; 869 AToB bot(BToA f) => f as AToB;
871 870
872 void main() { 871 void main() {
873 { 872 {
874 Function2<AToB, BToA> f; // Top 873 Function2<AToB, BToA> f; // Top
875 f = top; 874 f = top;
876 f = left; 875 f = left;
877 f = right; 876 f = right;
878 f = bot; 877 f = bot;
879 } 878 }
(...skipping 29 matching lines...) Expand all
909 class B extends A {} 908 class B extends A {}
910 909
911 typedef T Function2<S, T>(S z); 910 typedef T Function2<S, T>(S z);
912 911
913 typedef A BToA(B x); // Top of the base lattice 912 typedef A BToA(B x); // Top of the base lattice
914 typedef B AToB(A x); // Bot of the base lattice 913 typedef B AToB(A x); // Bot of the base lattice
915 914
916 Function2<B, A> top(AToB f) => f; 915 Function2<B, A> top(AToB f) => f;
917 Function2<A, B> left(AToB f) => f; 916 Function2<A, B> left(AToB f) => f;
918 Function2<B, A> right(BToA f) => f; 917 Function2<B, A> right(BToA f) => f;
919 Function2<A, B> _bot(BToA f) => /*warning:DOWN_CAST_COMPOSITE*/f; 918 Function2<A, B> bot_(BToA f) => /*warning:DOWN_CAST_COMPOSITE*/f;
920 Function2<A, B> bot(BToA f) => f as Function2<A, B>; 919 Function2<A, B> bot(BToA f) => f as Function2<A, B>;
921 920
922 void main() { 921 void main() {
923 { 922 {
924 Function2<AToB, BToA> f; // Top 923 Function2<AToB, BToA> f; // Top
925 f = top; 924 f = top;
926 f = left; 925 f = left;
927 f = right; 926 f = right;
928 f = bot; 927 f = bot;
929 } 928 }
(...skipping 29 matching lines...) Expand all
959 class B extends A {} 958 class B extends A {}
960 959
961 typedef T Function2<S, T>(S z); 960 typedef T Function2<S, T>(S z);
962 961
963 typedef A BToA(B x); // Top of the base lattice 962 typedef A BToA(B x); // Top of the base lattice
964 typedef B AToB(A x); // Bot of the base lattice 963 typedef B AToB(A x); // Bot of the base lattice
965 964
966 BToA top(Function2<A, B> f) => f; 965 BToA top(Function2<A, B> f) => f;
967 AToB left(Function2<A, B> f) => f; 966 AToB left(Function2<A, B> f) => f;
968 BToA right(Function2<B, A> f) => f; 967 BToA right(Function2<B, A> f) => f;
969 AToB _bot(Function2<B, A> f) => /*warning:DOWN_CAST_COMPOSITE*/f; 968 AToB bot_(Function2<B, A> f) => /*warning:DOWN_CAST_COMPOSITE*/f;
970 AToB bot(Function2<B, A> f) => f as AToB; 969 AToB bot(Function2<B, A> f) => f as AToB;
971 970
972 void main() { 971 void main() {
973 { 972 {
974 Function2<AToB, BToA> f; // Top 973 Function2<AToB, BToA> f; // Top
975 f = top; 974 f = top;
976 f = left; 975 f = left;
977 f = right; 976 f = right;
978 f = bot; 977 f = bot;
979 } 978 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 FN n; 1063 FN n;
1065 FRR rr; 1064 FRR rr;
1066 FRO ro; 1065 FRO ro;
1067 FRN rn; 1066 FRN rn;
1068 FOO oo; 1067 FOO oo;
1069 FNN nn; 1068 FNN nn;
1070 FNNN nnn; 1069 FNNN nnn;
1071 1070
1072 r = r; 1071 r = r;
1073 r = o; 1072 r = o;
1074 r = /*severe:STATIC_TYPE_ERROR*/n; 1073 r = /*warning:INVALID_ASSIGNMENT*/n;
1075 r = /*severe:STATIC_TYPE_ERROR*/rr; 1074 r = /*warning:INVALID_ASSIGNMENT*/rr;
1076 r = ro; 1075 r = ro;
1077 r = rn; 1076 r = rn;
1078 r = oo; 1077 r = oo;
1079 r = /*severe:STATIC_TYPE_ERROR*/nn; 1078 r = /*warning:INVALID_ASSIGNMENT*/nn;
1080 r = /*severe:STATIC_TYPE_ERROR*/nnn; 1079 r = /*warning:INVALID_ASSIGNMENT*/nnn;
1081 1080
1082 o = /*warning:DOWN_CAST_COMPOSITE*/r; 1081 o = /*warning:DOWN_CAST_COMPOSITE*/r;
1083 o = o; 1082 o = o;
1084 o = /*severe:STATIC_TYPE_ERROR*/n; 1083 o = /*warning:INVALID_ASSIGNMENT*/n;
1085 o = /*severe:STATIC_TYPE_ERROR*/rr; 1084 o = /*warning:INVALID_ASSIGNMENT*/rr;
1086 o = /*severe:STATIC_TYPE_ERROR*/ro; 1085 o = /*warning:INVALID_ASSIGNMENT*/ro;
1087 o = /*severe:STATIC_TYPE_ERROR*/rn; 1086 o = /*warning:INVALID_ASSIGNMENT*/rn;
1088 o = oo; 1087 o = oo;
1089 o = /*severe:STATIC_TYPE_ERROR*/nn; 1088 o = /*warning:INVALID_ASSIGNMENT*/nn;
1090 o = /*severe:STATIC_TYPE_ERROR*/nnn; 1089 o = /*warning:INVALID_ASSIGNMENT*/nnn;
1091 1090
1092 n = /*severe:STATIC_TYPE_ERROR*/r; 1091 n = /*warning:INVALID_ASSIGNMENT*/r;
1093 n = /*severe:STATIC_TYPE_ERROR*/o; 1092 n = /*warning:INVALID_ASSIGNMENT*/o;
1094 n = n; 1093 n = n;
1095 n = /*severe:STATIC_TYPE_ERROR*/rr; 1094 n = /*warning:INVALID_ASSIGNMENT*/rr;
1096 n = /*severe:STATIC_TYPE_ERROR*/ro; 1095 n = /*warning:INVALID_ASSIGNMENT*/ro;
1097 n = /*severe:STATIC_TYPE_ERROR*/rn; 1096 n = /*warning:INVALID_ASSIGNMENT*/rn;
1098 n = /*severe:STATIC_TYPE_ERROR*/oo; 1097 n = /*warning:INVALID_ASSIGNMENT*/oo;
1099 n = nn; 1098 n = nn;
1100 n = nnn; 1099 n = nnn;
1101 1100
1102 rr = /*severe:STATIC_TYPE_ERROR*/r; 1101 rr = /*warning:INVALID_ASSIGNMENT*/r;
1103 rr = /*severe:STATIC_TYPE_ERROR*/o; 1102 rr = /*warning:INVALID_ASSIGNMENT*/o;
1104 rr = /*severe:STATIC_TYPE_ERROR*/n; 1103 rr = /*warning:INVALID_ASSIGNMENT*/n;
1105 rr = rr; 1104 rr = rr;
1106 rr = ro; 1105 rr = ro;
1107 rr = /*severe:STATIC_TYPE_ERROR*/rn; 1106 rr = /*warning:INVALID_ASSIGNMENT*/rn;
1108 rr = oo; 1107 rr = oo;
1109 rr = /*severe:STATIC_TYPE_ERROR*/nn; 1108 rr = /*warning:INVALID_ASSIGNMENT*/nn;
1110 rr = /*severe:STATIC_TYPE_ERROR*/nnn; 1109 rr = /*warning:INVALID_ASSIGNMENT*/nnn;
1111 1110
1112 ro = /*warning:DOWN_CAST_COMPOSITE*/r; 1111 ro = /*warning:DOWN_CAST_COMPOSITE*/r;
1113 ro = /*severe:STATIC_TYPE_ERROR*/o; 1112 ro = /*warning:INVALID_ASSIGNMENT*/o;
1114 ro = /*severe:STATIC_TYPE_ERROR*/n; 1113 ro = /*warning:INVALID_ASSIGNMENT*/n;
1115 ro = /*warning:DOWN_CAST_COMPOSITE*/rr; 1114 ro = /*warning:DOWN_CAST_COMPOSITE*/rr;
1116 ro = ro; 1115 ro = ro;
1117 ro = /*severe:STATIC_TYPE_ERROR*/rn; 1116 ro = /*warning:INVALID_ASSIGNMENT*/rn;
1118 ro = oo; 1117 ro = oo;
1119 ro = /*severe:STATIC_TYPE_ERROR*/nn; 1118 ro = /*warning:INVALID_ASSIGNMENT*/nn;
1120 ro = /*severe:STATIC_TYPE_ERROR*/nnn; 1119 ro = /*warning:INVALID_ASSIGNMENT*/nnn;
1121 1120
1122 rn = /*warning:DOWN_CAST_COMPOSITE*/r; 1121 rn = /*warning:DOWN_CAST_COMPOSITE*/r;
1123 rn = /*severe:STATIC_TYPE_ERROR*/o; 1122 rn = /*warning:INVALID_ASSIGNMENT*/o;
1124 rn = /*severe:STATIC_TYPE_ERROR*/n; 1123 rn = /*warning:INVALID_ASSIGNMENT*/n;
1125 rn = /*severe:STATIC_TYPE_ERROR*/rr; 1124 rn = /*warning:INVALID_ASSIGNMENT*/rr;
1126 rn = /*severe:STATIC_TYPE_ERROR*/ro; 1125 rn = /*warning:INVALID_ASSIGNMENT*/ro;
1127 rn = rn; 1126 rn = rn;
1128 rn = /*severe:STATIC_TYPE_ERROR*/oo; 1127 rn = /*warning:INVALID_ASSIGNMENT*/oo;
1129 rn = /*severe:STATIC_TYPE_ERROR*/nn; 1128 rn = /*warning:INVALID_ASSIGNMENT*/nn;
1130 rn = /*severe:STATIC_TYPE_ERROR*/nnn; 1129 rn = /*warning:INVALID_ASSIGNMENT*/nnn;
1131 1130
1132 oo = /*warning:DOWN_CAST_COMPOSITE*/r; 1131 oo = /*warning:DOWN_CAST_COMPOSITE*/r;
1133 oo = /*warning:DOWN_CAST_COMPOSITE*/o; 1132 oo = /*warning:DOWN_CAST_COMPOSITE*/o;
1134 oo = /*severe:STATIC_TYPE_ERROR*/n; 1133 oo = /*warning:INVALID_ASSIGNMENT*/n;
1135 oo = /*warning:DOWN_CAST_COMPOSITE*/rr; 1134 oo = /*warning:DOWN_CAST_COMPOSITE*/rr;
1136 oo = /*warning:DOWN_CAST_COMPOSITE*/ro; 1135 oo = /*warning:DOWN_CAST_COMPOSITE*/ro;
1137 oo = /*severe:STATIC_TYPE_ERROR*/rn; 1136 oo = /*warning:INVALID_ASSIGNMENT*/rn;
1138 oo = oo; 1137 oo = oo;
1139 oo = /*severe:STATIC_TYPE_ERROR*/nn; 1138 oo = /*warning:INVALID_ASSIGNMENT*/nn;
1140 oo = /*severe:STATIC_TYPE_ERROR*/nnn; 1139 oo = /*warning:INVALID_ASSIGNMENT*/nnn;
1141 1140
1142 nn = /*severe:STATIC_TYPE_ERROR*/r; 1141 nn = /*warning:INVALID_ASSIGNMENT*/r;
1143 nn = /*severe:STATIC_TYPE_ERROR*/o; 1142 nn = /*warning:INVALID_ASSIGNMENT*/o;
1144 nn = /*warning:DOWN_CAST_COMPOSITE*/n; 1143 nn = /*warning:DOWN_CAST_COMPOSITE*/n;
1145 nn = /*severe:STATIC_TYPE_ERROR*/rr; 1144 nn = /*warning:INVALID_ASSIGNMENT*/rr;
1146 nn = /*severe:STATIC_TYPE_ERROR*/ro; 1145 nn = /*warning:INVALID_ASSIGNMENT*/ro;
1147 nn = /*severe:STATIC_TYPE_ERROR*/rn; 1146 nn = /*warning:INVALID_ASSIGNMENT*/rn;
1148 nn = /*severe:STATIC_TYPE_ERROR*/oo; 1147 nn = /*warning:INVALID_ASSIGNMENT*/oo;
1149 nn = nn; 1148 nn = nn;
1150 nn = nnn; 1149 nn = nnn;
1151 1150
1152 nnn = /*severe:STATIC_TYPE_ERROR*/r; 1151 nnn = /*warning:INVALID_ASSIGNMENT*/r;
1153 nnn = /*severe:STATIC_TYPE_ERROR*/o; 1152 nnn = /*warning:INVALID_ASSIGNMENT*/o;
1154 nnn = /*warning:DOWN_CAST_COMPOSITE*/n; 1153 nnn = /*warning:DOWN_CAST_COMPOSITE*/n;
1155 nnn = /*severe:STATIC_TYPE_ERROR*/rr; 1154 nnn = /*warning:INVALID_ASSIGNMENT*/rr;
1156 nnn = /*severe:STATIC_TYPE_ERROR*/ro; 1155 nnn = /*warning:INVALID_ASSIGNMENT*/ro;
1157 nnn = /*severe:STATIC_TYPE_ERROR*/rn; 1156 nnn = /*warning:INVALID_ASSIGNMENT*/rn;
1158 nnn = /*severe:STATIC_TYPE_ERROR*/oo; 1157 nnn = /*warning:INVALID_ASSIGNMENT*/oo;
1159 nnn = /*warning:DOWN_CAST_COMPOSITE*/nn; 1158 nnn = /*warning:DOWN_CAST_COMPOSITE*/nn;
1160 nnn = nnn; 1159 nnn = nnn;
1161 } 1160 }
1162 '''); 1161 ''');
1163 }); 1162 });
1164 1163
1165 test('Function subtyping: objects with call methods', () { 1164 test('Function subtyping: objects with call methods', () {
1166 checkFile(''' 1165 checkFile('''
1167 1166
1168 typedef int I2I(int x); 1167 typedef int I2I(int x);
1169 typedef num N2N(num x); 1168 typedef num N2N(num x);
1170 class A { 1169 class A {
1171 int call(int x) => x; 1170 int call(int x) => x;
1172 } 1171 }
1173 class B { 1172 class B {
1174 num call(num x) => x; 1173 num call(num x) => x;
1175 } 1174 }
1176 int i2i(int x) => x; 1175 int i2i(int x) => x;
1177 num n2n(num x) => x; 1176 num n2n(num x) => x;
1178 void main() { 1177 void main() {
1179 { 1178 {
1180 I2I f; 1179 I2I f;
1181 f = new A(); 1180 f = new A();
1182 f = /*severe:STATIC_TYPE_ERROR*/new B(); 1181 f = /*warning:INVALID_ASSIGNMENT*/new B();
1183 f = i2i; 1182 f = i2i;
1184 f = /*severe:STATIC_TYPE_ERROR*/n2n; 1183 f = /*severe:STATIC_TYPE_ERROR*/n2n;
1185 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object; 1184 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object;
1186 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function; 1185 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function;
1187 } 1186 }
1188 { 1187 {
1189 N2N f; 1188 N2N f;
1190 f = /*severe:STATIC_TYPE_ERROR*/new A(); 1189 f = /*warning:INVALID_ASSIGNMENT*/new A();
1191 f = new B(); 1190 f = new B();
1192 f = /*severe:STATIC_TYPE_ERROR*/i2i; 1191 f = /*severe:STATIC_TYPE_ERROR*/i2i;
1193 f = n2n; 1192 f = n2n;
1194 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object; 1193 f = /*warning:DOWN_CAST_COMPOSITE*/i2i as Object;
1195 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function; 1194 f = /*warning:DOWN_CAST_COMPOSITE*/n2n as Function;
1196 } 1195 }
1197 { 1196 {
1198 A f; 1197 A f;
1199 f = new A(); 1198 f = new A();
1200 f = /*severe:STATIC_TYPE_ERROR*/new B(); 1199 f = /*warning:INVALID_ASSIGNMENT*/new B();
1201 f = /*severe:STATIC_TYPE_ERROR*/i2i; 1200 f = /*warning:INVALID_ASSIGNMENT*/i2i;
1202 f = /*severe:STATIC_TYPE_ERROR*/n2n; 1201 f = /*warning:INVALID_ASSIGNMENT*/n2n;
1203 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; 1202 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object;
1204 f = /*info:DOWN_CAST_IMPLICIT*/n2n as Function; 1203 f = /*info:DOWN_CAST_IMPLICIT*/n2n as Function;
1205 } 1204 }
1206 { 1205 {
1207 B f; 1206 B f;
1208 f = /*severe:STATIC_TYPE_ERROR*/new A(); 1207 f = /*warning:INVALID_ASSIGNMENT*/new A();
1209 f = new B(); 1208 f = new B();
1210 f = /*severe:STATIC_TYPE_ERROR*/i2i; 1209 f = /*warning:INVALID_ASSIGNMENT*/i2i;
1211 f = /*severe:STATIC_TYPE_ERROR*/n2n; 1210 f = /*warning:INVALID_ASSIGNMENT*/n2n;
1212 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; 1211 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object;
1213 f = /*info:DOWN_CAST_IMPLICIT*/n2n as Function; 1212 f = /*info:DOWN_CAST_IMPLICIT*/n2n as Function;
1214 } 1213 }
1215 { 1214 {
1216 Function f; 1215 Function f;
1217 f = new A(); 1216 f = new A();
1218 f = new B(); 1217 f = new B();
1219 f = i2i; 1218 f = i2i;
1220 f = n2n; 1219 f = n2n;
1221 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; 1220 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object;
1222 f = (n2n as Function); 1221 f = (n2n as Function);
1223 } 1222 }
1224 } 1223 }
1225 '''); 1224 ''');
1226 }); 1225 });
1227 1226
1228 test('void', () { 1227 test('void', () {
1229 checkFile(''' 1228 checkFile('''
1230 1229
1231 class A { 1230 class A {
1232 void bar() => null; 1231 void bar() => null;
1233 void foo() => bar; // allowed 1232 void foo() => bar(); // allowed
1234 } 1233 }
1235 '''); 1234 ''');
1236 }); 1235 });
1237 1236
1238 test('uninferred closure', () { 1237 test('uninferred closure', () {
1239 checkFile(''' 1238 checkFile('''
1240 typedef num Num2Num(num x); 1239 typedef num Num2Num(num x);
1241 void main() { 1240 void main() {
1242 Num2Num g = /*info:INFERRED_TYPE_CLOSURE,severe:STATIC_TYPE_ERROR*/(in t x) { return x; }; 1241 Num2Num g = /*info:INFERRED_TYPE_CLOSURE,severe:STATIC_TYPE_ERROR*/(in t x) { return x; };
1243 print(g(42)); 1242 print(g(42));
1244 } 1243 }
1245 '''); 1244 ''');
1246 }); 1245 });
1247 1246
1248 test('subtype of universal type', () { 1247 test('subtype of universal type', () {
1249 checkFile(''' 1248 checkFile('''
1250 void main() { 1249 void main() {
1251 nonGenericFn(x) => null; 1250 nonGenericFn(x) => null;
1252 { 1251 {
1253 /*=R*/ f/*<P, R>*/(/*=P*/ p) => null; 1252 /*=R*/ f/*<P, R>*/(/*=P*/ p) => null;
1254 /*=T*/ g/*<S, T>*/(/*=S*/ s) => null; 1253 /*=T*/ g/*<S, T>*/(/*=S*/ s) => null;
1255 1254
1256 var local = f; 1255 var local = f;
1257 local = g; // valid 1256 local = g; // valid
1258 1257
1259 // Non-generic function cannot subtype a generic one. 1258 // Non-generic function cannot subtype a generic one.
1260 local = /*severe:STATIC_TYPE_ERROR*/(x) => null; 1259 local = /*severe:STATIC_TYPE_ERROR, warning:INVALID_ASSIGNMENT*/(x) => null;
1261 local = /*severe:STATIC_TYPE_ERROR*/nonGenericFn; 1260 local = /*warning:INVALID_ASSIGNMENT*/nonGenericFn;
1262 } 1261 }
1263 { 1262 {
1264 Iterable/*<R>*/ f/*<P, R>*/(List/*<P>*/ p) => null; 1263 Iterable/*<R>*/ f/*<P, R>*/(List/*<P>*/ p) => null;
1265 List/*<T>*/ g/*<S, T>*/(Iterable/*<S>*/ s) => null; 1264 List/*<T>*/ g/*<S, T>*/(Iterable/*<S>*/ s) => null;
1266 1265
1267 var local = f; 1266 var local = f;
1268 local = g; // valid 1267 local = g; // valid
1269 1268
1270 var local2 = g; 1269 var local2 = g;
1271 local = local2; 1270 local = local2;
1272 local2 = /*severe:STATIC_TYPE_ERROR*/f; 1271 local2 = /*severe:STATIC_TYPE_ERROR*/f;
1273 local2 = /*warning:DOWN_CAST_COMPOSITE*/local; 1272 local2 = /*warning:DOWN_CAST_COMPOSITE*/local;
1274 1273
1275 // Non-generic function cannot subtype a generic one. 1274 // Non-generic function cannot subtype a generic one.
1276 local = /*severe:STATIC_TYPE_ERROR*/(x) => null; 1275 local = /*severe:STATIC_TYPE_ERROR, warning:INVALID_ASSIGNMENT*/(x) => null;
1277 local = /*severe:STATIC_TYPE_ERROR*/nonGenericFn; 1276 local = /*warning:INVALID_ASSIGNMENT*/nonGenericFn;
1278 } 1277 }
1279 } 1278 }
1280 '''); 1279 ''');
1281 }); 1280 });
1282 }); 1281 });
1283 1282
1284 test('Relaxed casts', () { 1283 test('Relaxed casts', () {
1285 checkFile(''' 1284 checkFile('''
1286 1285
1287 class A {} 1286 class A {}
(...skipping 29 matching lines...) Expand all
1317 { 1316 {
1318 lOfOs = mOfDs; 1317 lOfOs = mOfDs;
1319 lOfOs = mOfOs; 1318 lOfOs = mOfOs;
1320 lOfOs = mOfAs; 1319 lOfOs = mOfAs;
1321 lOfOs = lOfDs; 1320 lOfOs = lOfDs;
1322 lOfOs = lOfOs; 1321 lOfOs = lOfOs;
1323 lOfOs = lOfAs; 1322 lOfOs = lOfAs;
1324 } 1323 }
1325 { 1324 {
1326 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs; 1325 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs;
1327 lOfAs = /*severe:STATIC_TYPE_ERROR*/mOfOs; 1326 lOfAs = /*warning:INVALID_ASSIGNMENT*/mOfOs;
1328 lOfAs = mOfAs; 1327 lOfAs = mOfAs;
1329 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs; 1328 lOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs;
1330 lOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; 1329 lOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
1331 lOfAs = lOfAs; 1330 lOfAs = lOfAs;
1332 } 1331 }
1333 { 1332 {
1334 mOfDs = mOfDs; 1333 mOfDs = mOfDs;
1335 mOfDs = mOfOs; 1334 mOfDs = mOfOs;
1336 mOfDs = mOfAs; 1335 mOfDs = mOfAs;
1337 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfDs; 1336 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfDs;
1338 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; 1337 mOfDs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
1339 mOfDs = /*warning:DOWN_CAST_COMPOSITE*/lOfAs; 1338 mOfDs = /*warning:DOWN_CAST_COMPOSITE*/lOfAs;
1340 } 1339 }
1341 { 1340 {
1342 mOfOs = mOfDs; 1341 mOfOs = mOfDs;
1343 mOfOs = mOfOs; 1342 mOfOs = mOfOs;
1344 mOfOs = mOfAs; 1343 mOfOs = mOfAs;
1345 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfDs; 1344 mOfOs = /*info:DOWN_CAST_IMPLICIT, info:INVALID_ASSIGNMENT*/lOfDs;
Leaf 2016/03/10 22:58:25 Why did these show up? I think this is just an im
Bob Nystrom 2016/03/15 00:08:13 I believe it's a hint coming from type propagation
Leaf 2016/03/15 00:28:04 I see. Not a big deal, but it might be better to
Bob Nystrom 2016/03/15 19:14:34 Done.
1346 mOfOs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; 1345 mOfOs = /*info:DOWN_CAST_IMPLICIT, info:INVALID_ASSIGNMENT*/lOfOs;
1347 mOfOs = /*severe:STATIC_TYPE_ERROR*/lOfAs; 1346 mOfOs = /*warning:INVALID_ASSIGNMENT*/lOfAs;
1348 } 1347 }
1349 { 1348 {
1350 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs; 1349 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs;
1351 mOfAs = /*info:DOWN_CAST_IMPLICIT*/mOfOs; 1350 mOfAs = /*info:DOWN_CAST_IMPLICIT*/mOfOs;
1352 mOfAs = mOfAs; 1351 mOfAs = mOfAs;
1353 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs; 1352 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs;
1354 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; 1353 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs;
1355 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfAs; 1354 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfAs;
1356 } 1355 }
1357 1356
1358 } 1357 }
1359 '''); 1358 ''');
1360 }); 1359 });
1361 1360
1362 test('Type checking literals', () { 1361 test('Type checking literals', () {
1363 checkFile(''' 1362 checkFile('''
1364 test() { 1363 test() {
1365 num n = 3; 1364 num n = 3;
1366 int i = 3; 1365 int i = 3;
1367 String s = "hello"; 1366 String s = "hello";
1368 { 1367 {
1369 List<int> l = <int>[i]; 1368 List<int> l = <int>[i];
1370 l = <int>[/*severe:STATIC_TYPE_ERROR*/s]; 1369 l = <int>[/*warning:LIST_ELEMENT_TYPE_NOT_ASSIGNABLE*/s];
1371 l = <int>[/*info:DOWN_CAST_IMPLICIT*/n]; 1370 l = <int>[/*info:DOWN_CAST_IMPLICIT*/n];
1372 l = <int>[i, /*info:DOWN_CAST_IMPLICIT*/n, /*severe:STATIC_TYPE_E RROR*/s]; 1371 l = <int>[i, /*info:DOWN_CAST_IMPLICIT*/n, /*warning:LIST_ELEMENT _TYPE_NOT_ASSIGNABLE*/s];
1373 } 1372 }
1374 { 1373 {
1375 List l = [i]; 1374 List l = [i];
1376 l = [s]; 1375 l = [s];
1377 l = [n]; 1376 l = [n];
1378 l = [i, n, s]; 1377 l = [i, n, s];
1379 } 1378 }
1380 { 1379 {
1381 Map<String, int> m = <String, int>{s: i}; 1380 Map<String, int> m = <String, int>{s: i};
1382 m = <String, int>{s: /*severe:STATIC_TYPE_ERROR*/s}; 1381 m = <String, int>{s: /*warning:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/s};
1383 m = <String, int>{s: /*info:DOWN_CAST_IMPLICIT*/n}; 1382 m = <String, int>{s: /*info:DOWN_CAST_IMPLICIT*/n};
1384 m = <String, int>{s: i, 1383 m = <String, int>{s: i,
1385 s: /*info:DOWN_CAST_IMPLICIT*/n, 1384 s: /*info:DOWN_CAST_IMPLICIT*/n,
1386 s: /*severe:STATIC_TYPE_ERROR*/s}; 1385 s: /*warning:MAP_VALUE_TYPE_NOT_ASSIGNABLE*/s};
1387 } 1386 }
1388 // TODO(leafp): We can't currently test for key errors since the 1387 // TODO(leafp): We can't currently test for key errors since the
1389 // error marker binds to the entire entry. 1388 // error marker binds to the entire entry.
1390 { 1389 {
1391 Map m = {s: i}; 1390 Map m = {s: i};
1392 m = {s: s}; 1391 m = {s: s};
1393 m = {s: n}; 1392 m = {s: n};
1394 m = {s: i, 1393 m = {s: i,
1395 s: n, 1394 s: n,
1396 s: s}; 1395 s: s};
1397 m = {i: s, 1396 m = {i: s,
1398 n: s, 1397 n: s,
1399 s: s}; 1398 s: s};
1400 } 1399 }
1401 } 1400 }
1402 '''); 1401 ''');
1403 }); 1402 });
1404 1403
1405 test('casts in constant contexts', () { 1404 test('casts in constant contexts', () {
1406 checkFile(''' 1405 checkFile('''
1407 class A { 1406 class A {
1408 static const num n = 3.0; 1407 static const num n = 3.0;
1409 static const int i = /*info:ASSIGNMENT_CAST*/n; 1408 static const int /*severe:VARIABLE_TYPE_MISMATCH*/i = /*info:ASSIGNM ENT_CAST*/n;
Leaf 2016/03/10 22:58:25 What is this about? I don't think this is suppose
Bob Nystrom 2016/03/15 00:08:13 n and i are const, so analyzer knows the concrete
1410 final int fi; 1409 final int fi;
1411 const A(num a) : this.fi = /*info:DOWN_CAST_IMPLICIT*/a; 1410 const A(num a) : this.fi = /*info:DOWN_CAST_IMPLICIT*/a;
1412 } 1411 }
1413 class B extends A { 1412 class B extends A {
1414 const B(Object a) : super(/*info:DOWN_CAST_IMPLICIT*/a); 1413 const B(Object a) : super(/*info:DOWN_CAST_IMPLICIT*/a);
1415 } 1414 }
1416 void foo(Object o) { 1415 void foo(Object o) {
1417 var a = const A(/*info:DOWN_CAST_IMPLICIT*/o); 1416 var a = const A(/*info:DOWN_CAST_IMPLICIT, severe:CONST_WITH_NON_CON STANT_ARGUMENT, severe:INVALID_CONSTANT*/o);
1418 } 1417 }
1419 '''); 1418 ''');
1420 }); 1419 });
1421 1420
1422 test('casts in conditionals', () { 1421 test('casts in conditionals', () {
1423 checkFile(''' 1422 checkFile('''
1424 main() { 1423 main() {
1425 bool b = true; 1424 bool b = true;
1426 num x = b ? 1 : 2.3; 1425 num x = b ? 1 : 2.3;
1427 int y = /*info:ASSIGNMENT_CAST*/b ? 1 : 2.3; 1426 int y = /*info:ASSIGNMENT_CAST*/b ? 1 : 2.3;
1428 String z = !b ? "hello" : null; 1427 String z = !b ? "hello" : null;
1429 z = b ? null : "hello"; 1428 z = b ? null : "hello";
1430 } 1429 }
1431 '''); 1430 ''');
1432 }); 1431 });
1433 1432
1434 // This is a regression test for https://github.com/dart-lang/sdk/issues/25071 1433 // This is a regression test for https://github.com/dart-lang/sdk/issues/25071
1435 test('unbound redirecting constructor', () { 1434 test('unbound redirecting constructor', () {
1436 checkFile(''' 1435 checkFile('''
1437 class Foo { 1436 class Foo {
1438 Foo() : this.init(); 1437 Foo() : /*severe:REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR*/this.init() ;
1439 } 1438 }
1440 '''); 1439 ''');
1441 }); 1440 });
1442 1441
1443 test('redirecting constructor', () { 1442 test('redirecting constructor', () {
1444 checkFile(''' 1443 checkFile('''
1445 class A { 1444 class A {
1446 A(A x) {} 1445 A(A x) {}
1447 A.two() : this(/*severe:STATIC_TYPE_ERROR*/3); 1446 A.two() : this(/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
1448 } 1447 }
1449 '''); 1448 ''');
1450 }); 1449 });
1451 1450
1452 test('super constructor', () { 1451 test('super constructor', () {
1453 checkFile(''' 1452 checkFile('''
1454 class A { A(A x) {} } 1453 class A { A(A x) {} }
1455 class B extends A { 1454 class B extends A {
1456 B() : super(/*severe:STATIC_TYPE_ERROR*/3); 1455 B() : super(/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3);
1457 } 1456 }
1458 '''); 1457 ''');
1459 }); 1458 });
1460 1459
1461 test('factory constructor downcast', () { 1460 test('factory constructor downcast', () {
1462 checkFile(r''' 1461 checkFile(r'''
1463 class Animal { 1462 class Animal {
1464 Animal(); 1463 Animal();
1465 factory Animal.cat() => new Cat(); 1464 factory Animal.cat() => new Cat();
1466 } 1465 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 addFile( 1505 addFile(
1507 ''' 1506 '''
1508 import 'main.dart' as main; 1507 import 'main.dart' as main;
1509 1508
1510 class Base { 1509 class Base {
1511 var f1; 1510 var f1;
1512 var _f2; 1511 var _f2;
1513 var _f3; 1512 var _f3;
1514 get _f4 => null; 1513 get _f4 => null;
1515 1514
1516 int _m1(); 1515 int _m1() => null;
1517 } 1516 }
1518 1517
1519 class GrandChild extends main.Child { 1518 class GrandChild extends main.Child {
1520 /*severe:INVALID_FIELD_OVERRIDE*/var _f2; 1519 /*severe:INVALID_FIELD_OVERRIDE*/var _f2;
1521 /*severe:INVALID_FIELD_OVERRIDE*/var _f3; 1520 /*severe:INVALID_FIELD_OVERRIDE*/var _f3;
1522 var _f4; 1521 var _f4;
1523 1522
1524 /*severe:INVALID_METHOD_OVERRIDE*/String _m1(); 1523 /*severe:INVALID_METHOD_OVERRIDE*/String
1524 /*warning:INVALID_METHOD_OVERRIDE_RETURN_TYPE*/_m1() => null;
1525 } 1525 }
1526 ''', 1526 ''',
1527 name: '/helper.dart'); 1527 name: '/helper.dart');
1528 checkFile(''' 1528 checkFile('''
1529 import 'helper.dart' as helper; 1529 import 'helper.dart' as helper;
1530 1530
1531 class Child extends helper.Base { 1531 class Child extends helper.Base {
1532 /*severe:INVALID_FIELD_OVERRIDE*/var f1; 1532 /*severe:INVALID_FIELD_OVERRIDE*/var f1;
1533 var _f2; 1533 var _f2;
1534 var _f4; 1534 var _f4;
1535 1535
1536 String _m1(); 1536 String _m1() => null;
1537 } 1537 }
1538 '''); 1538 ''');
1539 }); 1539 });
1540 1540
1541 test('getter/getter override', () { 1541 test('getter/getter override', () {
1542 checkFile(''' 1542 checkFile('''
1543 class A {} 1543 class A {}
1544 class B extends A {} 1544 class B extends A {}
1545 class C extends B {} 1545 class C extends B {}
1546 1546
(...skipping 26 matching lines...) Expand all
1573 B f4; 1573 B f4;
1574 } 1574 }
1575 1575
1576 class Child extends Base { 1576 class Child extends Base {
1577 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A ge t f1 => null; 1577 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A ge t f1 => null;
1578 /*severe:INVALID_FIELD_OVERRIDE*/C get f2 => null; 1578 /*severe:INVALID_FIELD_OVERRIDE*/C get f2 => null;
1579 /*severe:INVALID_FIELD_OVERRIDE*/get f3 => null; 1579 /*severe:INVALID_FIELD_OVERRIDE*/get f3 => null;
1580 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyna mic get f4 => null; 1580 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyna mic get f4 => null;
1581 } 1581 }
1582 1582
1583 class Child2 implements Base { 1583 class /*warning:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_FOUR*/Chil d2 implements Base {
1584 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; 1584 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null;
1585 C get f2 => null; 1585 C get f2 => null;
1586 get f3 => null; 1586 get f3 => null;
1587 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; 1587 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null;
1588 } 1588 }
1589 '''); 1589 ''');
1590 }); 1590 });
1591 1591
1592 test('setter/setter override', () { 1592 test('setter/setter override', () {
1593 checkFile(''' 1593 checkFile('''
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 '''); 1657 ''');
1658 }); 1658 });
1659 1659
1660 test('method override', () { 1660 test('method override', () {
1661 checkFile(''' 1661 checkFile('''
1662 class A {} 1662 class A {}
1663 class B extends A {} 1663 class B extends A {}
1664 class C extends B {} 1664 class C extends B {}
1665 1665
1666 class Base { 1666 class Base {
1667 B m1(B a); 1667 B m1(B a) => null;
1668 B m2(B a); 1668 B m2(B a) => null;
1669 B m3(B a); 1669 B m3(B a) => null;
1670 B m4(B a); 1670 B m4(B a) => null;
1671 B m5(B a); 1671 B m5(B a) => null;
1672 B m6(B a); 1672 B m6(B a) => null;
1673 } 1673 }
1674 1674
1675 class Child extends Base { 1675 class Child extends Base {
1676 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {} 1676 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) => null;
1677 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {} 1677 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) => null;
1678 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) {} 1678 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) => null;
1679 C m4(A value) {} 1679 C m4(A value) => null;
1680 m5(value) {} 1680 m5(value) => null;
1681 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {} 1681 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) => null;
1682 } 1682 }
1683 '''); 1683 ''');
1684 }); 1684 });
1685 1685
1686 test('generic class method override', () { 1686 test('generic class method override', () {
1687 checkFile(''' 1687 checkFile('''
1688 class A {} 1688 class A {}
1689 class B extends A {} 1689 class B extends A {}
1690 1690
1691 class Base<T extends B> { 1691 class Base<T extends B> {
1692 T foo() => null; 1692 T foo() => null;
1693 } 1693 }
1694 1694
1695 class Derived<S extends A> extends Base<B> { 1695 class Derived<S extends A> extends Base<B> {
1696 /*severe:INVALID_METHOD_OVERRIDE*/S foo() => null; 1696 /*severe:INVALID_METHOD_OVERRIDE*/S
1697 /*warning:INVALID_METHOD_OVERRIDE_RETURN_TYPE*/foo() => null;
1697 } 1698 }
1698 1699
1699 class Derived2<S extends B> extends Base<B> { 1700 class Derived2<S extends B> extends Base<B> {
1700 S foo() => null; 1701 S foo() => null;
1701 } 1702 }
1702 '''); 1703 ''');
1703 }); 1704 });
1704 1705
1705 test('generic method override', () { 1706 test('generic method override', () {
1706 checkFile(''' 1707 checkFile('''
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 } 1752 }
1752 '''); 1753 ''');
1753 }); 1754 });
1754 1755
1755 test('type promotion from dynamic', () { 1756 test('type promotion from dynamic', () {
1756 checkFile(r''' 1757 checkFile(r'''
1757 f() { 1758 f() {
1758 dynamic x; 1759 dynamic x;
1759 if (x is int) { 1760 if (x is int) {
1760 int y = x; 1761 int y = x;
1761 String z = /*severe:STATIC_TYPE_ERROR*/x; 1762 String z = /*warning:INVALID_ASSIGNMENT*/x;
1762 } 1763 }
1763 } 1764 }
1764 g() { 1765 g() {
1765 Object x; 1766 Object x;
1766 if (x is int) { 1767 if (x is int) {
1767 int y = x; 1768 int y = x;
1768 String z = /*severe:STATIC_TYPE_ERROR*/x; 1769 String z = /*warning:INVALID_ASSIGNMENT*/x;
1769 } 1770 }
1770 } 1771 }
1771 '''); 1772 ''');
1772 }); 1773 });
1773 1774
1774 test('unary operators', () { 1775 test('unary operators', () {
1775 checkFile(''' 1776 checkFile('''
1776 class A { 1777 class A {
1777 A operator ~() {} 1778 A operator ~() => null;
1778 A operator +(int x) {} 1779 A operator +(int x) => null;
1779 A operator -(int x) {} 1780 A operator -(int x) => null;
1780 A operator -() {} 1781 A operator -() => null;
1781 } 1782 }
1782 1783
1783 foo() => new A(); 1784 foo() => new A();
1784 1785
1785 test() { 1786 test() {
1786 A a = new A(); 1787 A a = new A();
1787 var c = foo(); 1788 var c = foo();
1788 dynamic d; 1789 dynamic d;
1789 1790
1790 ~a; 1791 ~a;
1791 (/*info:DYNAMIC_INVOKE*/~d); 1792 (/*info:DYNAMIC_INVOKE*/~d);
1792 1793
1793 !/*severe:STATIC_TYPE_ERROR*/a; 1794 !/*warning:NON_BOOL_NEGATION_EXPRESSION*/a;
1794 !/*info:DYNAMIC_CAST*/d; 1795 !/*info:DYNAMIC_CAST*/d;
1795 1796
1796 -a; 1797 -a;
1797 (/*info:DYNAMIC_INVOKE*/-d); 1798 (/*info:DYNAMIC_INVOKE*/-d);
1798 1799
1799 ++a; 1800 ++a;
1800 --a; 1801 --a;
1801 (/*info:DYNAMIC_INVOKE*/++d); 1802 (/*info:DYNAMIC_INVOKE*/++d);
1802 (/*info:DYNAMIC_INVOKE*/--d); 1803 (/*info:DYNAMIC_INVOKE*/--d);
1803 1804
1804 a++; 1805 a++;
1805 a--; 1806 a--;
1806 (/*info:DYNAMIC_INVOKE*/d++); 1807 (/*info:DYNAMIC_INVOKE*/d++);
1807 (/*info:DYNAMIC_INVOKE*/d--); 1808 (/*info:DYNAMIC_INVOKE*/d--);
1808 }'''); 1809 }''');
1809 }); 1810 });
1810 1811
1811 test('binary and index operators', () { 1812 test('binary and index operators', () {
1812 checkFile(''' 1813 checkFile('''
1813 class A { 1814 class A {
1814 A operator *(B b) {} 1815 A operator *(B b) => null;
1815 A operator /(B b) {} 1816 A operator /(B b) => null;
1816 A operator ~/(B b) {} 1817 A operator ~/(B b) => null;
1817 A operator %(B b) {} 1818 A operator %(B b) => null;
1818 A operator +(B b) {} 1819 A operator +(B b) => null;
1819 A operator -(B b) {} 1820 A operator -(B b) => null;
1820 A operator <<(B b) {} 1821 A operator <<(B b) => null;
1821 A operator >>(B b) {} 1822 A operator >>(B b) => null;
1822 A operator &(B b) {} 1823 A operator &(B b) => null;
1823 A operator ^(B b) {} 1824 A operator ^(B b) => null;
1824 A operator |(B b) {} 1825 A operator |(B b) => null;
1825 A operator[](B b) {} 1826 A operator[](B b) => null;
1826 } 1827 }
1827 1828
1828 class B { 1829 class B {
1829 A operator -(B b) {} 1830 A operator -(B b) => null;
1830 } 1831 }
1831 1832
1832 foo() => new A(); 1833 foo() => new A();
1833 1834
1834 test() { 1835 test() {
1835 A a = new A(); 1836 A a = new A();
1836 B b = new B(); 1837 B b = new B();
1837 var c = foo(); 1838 var c = foo();
1838 a = a * b; 1839 a = a * b;
1839 a = a * /*info:DYNAMIC_CAST*/c; 1840 a = a * /*info:DYNAMIC_CAST*/c;
1840 a = a / b; 1841 a = a / b;
1841 a = a ~/ b; 1842 a = a ~/ b;
1842 a = a % b; 1843 a = a % b;
1843 a = a + b; 1844 a = a + b;
1844 a = a + /*severe:STATIC_TYPE_ERROR*/a; 1845 a = a + /*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/a;
1845 a = a - b; 1846 a = a - b;
1846 b = /*severe:STATIC_TYPE_ERROR*/b - b; 1847 b = /*warning:INVALID_ASSIGNMENT*/b - b;
1847 a = a << b; 1848 a = a << b;
1848 a = a >> b; 1849 a = a >> b;
1849 a = a & b; 1850 a = a & b;
1850 a = a ^ b; 1851 a = a ^ b;
1851 a = a | b; 1852 a = a | b;
1852 c = (/*info:DYNAMIC_INVOKE*/c + b); 1853 c = (/*info:DYNAMIC_INVOKE*/c + b);
1853 1854
1854 String x = 'hello'; 1855 String x = 'hello';
1855 int y = 42; 1856 int y = 42;
1856 x = x + x; 1857 x = x + x;
1857 x = x + /*info:DYNAMIC_CAST*/c; 1858 x = x + /*info:DYNAMIC_CAST*/c;
1858 x = x + /*severe:STATIC_TYPE_ERROR*/y; 1859 x = x + /*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/y;
1859 1860
1860 bool p = true; 1861 bool p = true;
1861 p = p && p; 1862 p = p && p;
1862 p = p && /*info:DYNAMIC_CAST*/c; 1863 p = p && /*info:DYNAMIC_CAST*/c;
1863 p = (/*info:DYNAMIC_CAST*/c) && p; 1864 p = (/*info:DYNAMIC_CAST*/c) && p;
1864 p = (/*info:DYNAMIC_CAST*/c) && /*info:DYNAMIC_CAST*/c; 1865 p = (/*info:DYNAMIC_CAST*/c) && /*info:DYNAMIC_CAST*/c;
1865 p = (/*severe:STATIC_TYPE_ERROR*/y) && p; 1866 p = /*warning:NON_BOOL_OPERAND*/y && p;
1866 p = c == y; 1867 p = c == y;
1867 1868
1868 a = a[b]; 1869 a = a[b];
1869 a = a[/*info:DYNAMIC_CAST*/c]; 1870 a = a[/*info:DYNAMIC_CAST*/c];
1870 c = (/*info:DYNAMIC_INVOKE*/c[b]); 1871 c = (/*info:DYNAMIC_INVOKE*/c[b]);
1871 a[/*severe:STATIC_TYPE_ERROR*/y]; 1872 a[/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/y];
1872 } 1873 }
1873 '''); 1874 ''');
1874 }); 1875 });
1875 1876
1876 test('null coalescing operator', () { 1877 test('null coalescing operator', () {
1877 checkFile(''' 1878 checkFile('''
1878 class A {} 1879 class A {}
1879 class C<T> {} 1880 class C<T> {}
1880 main() { 1881 main() {
1881 A a, b; 1882 A a, b;
1882 a ??= new A(); 1883 a ??= new A();
1883 b = b ?? new A(); 1884 b = b ?? new A();
1884 1885
1885 // downwards inference 1886 // downwards inference
1886 C<int> c, d; 1887 C<int> c, d;
1887 c ??= /*info:INFERRED_TYPE_ALLOCATION*/new C(); 1888 c ??= /*info:INFERRED_TYPE_ALLOCATION*/new C();
1888 d = d ?? /*info:INFERRED_TYPE_ALLOCATION*/new C(); 1889 d = d ?? /*info:INFERRED_TYPE_ALLOCATION*/new C();
1889 } 1890 }
1890 '''); 1891 ''');
1891 }); 1892 });
1892 1893
1893 test('compound assignments', () { 1894 test('compound assignments', () {
1894 checkFile(''' 1895 checkFile('''
1895 class A { 1896 class A {
1896 A operator *(B b) {} 1897 A operator *(B b) => null;
1897 A operator /(B b) {} 1898 A operator /(B b) => null;
1898 A operator ~/(B b) {} 1899 A operator ~/(B b) => null;
1899 A operator %(B b) {} 1900 A operator %(B b) => null;
1900 A operator +(B b) {} 1901 A operator +(B b) => null;
1901 A operator -(B b) {} 1902 A operator -(B b) => null;
1902 A operator <<(B b) {} 1903 A operator <<(B b) => null;
1903 A operator >>(B b) {} 1904 A operator >>(B b) => null;
1904 A operator &(B b) {} 1905 A operator &(B b) => null;
1905 A operator ^(B b) {} 1906 A operator ^(B b) => null;
1906 A operator |(B b) {} 1907 A operator |(B b) => null;
1907 D operator [](B index) {} 1908 D operator [](B index) => null;
1908 void operator []=(B index, D value) {} 1909 void operator []=(B index, D value) => null;
1909 } 1910 }
1910 1911
1911 class B { 1912 class B {
1912 A operator -(B b) {} 1913 A operator -(B b) => null;
1913 } 1914 }
1914 1915
1915 class D { 1916 class D {
1916 D operator +(D d) {} 1917 D operator +(D d) => null;
1917 } 1918 }
1918 1919
1919 foo() => new A(); 1920 foo() => new A();
1920 1921
1921 test() { 1922 test() {
1922 int x = 0; 1923 int x = 0;
1923 x += 5; 1924 x += 5;
1924 (/*severe:STATIC_TYPE_ERROR*/x += 3.14); 1925 /*severe:STATIC_TYPE_ERROR*/x += 3.14;
1925 1926
1926 double y = 0.0; 1927 double y = 0.0;
1927 y += 5; 1928 y += 5;
1928 y += 3.14; 1929 y += 3.14;
1929 1930
1930 num z = 0; 1931 num z = 0;
1931 z += 5; 1932 z += 5;
1932 z += 3.14; 1933 z += 3.14;
1933 1934
1934 x = /*info:DOWN_CAST_IMPLICIT*/x + z; 1935 x = /*info:DOWN_CAST_IMPLICIT*/x + z;
1935 x += /*info:DOWN_CAST_IMPLICIT*/z; 1936 x += /*info:DOWN_CAST_IMPLICIT*/z;
1936 y = /*info:DOWN_CAST_IMPLICIT*/y + z; 1937 y = /*info:DOWN_CAST_IMPLICIT*/y + z;
1937 y += /*info:DOWN_CAST_IMPLICIT*/z; 1938 y += /*info:DOWN_CAST_IMPLICIT*/z;
1938 1939
1939 dynamic w = 42; 1940 dynamic w = 42;
1940 x += /*info:DYNAMIC_CAST*/w; 1941 x += /*info:DYNAMIC_CAST*/w;
1941 y += /*info:DYNAMIC_CAST*/w; 1942 y += /*info:DYNAMIC_CAST*/w;
1942 z += /*info:DYNAMIC_CAST*/w; 1943 z += /*info:DYNAMIC_CAST*/w;
1943 1944
1944 A a = new A(); 1945 A a = new A();
1945 B b = new B(); 1946 B b = new B();
1946 var c = foo(); 1947 var c = foo();
1947 a = a * b; 1948 a = a * b;
1948 a *= b; 1949 a *= b;
1949 a *= /*info:DYNAMIC_CAST*/c; 1950 a *= /*info:DYNAMIC_CAST*/c;
1950 a /= b; 1951 a /= b;
1951 a ~/= b; 1952 a ~/= b;
1952 a %= b; 1953 a %= b;
1953 a += b; 1954 a += b;
1954 a += /*severe:STATIC_TYPE_ERROR*/a; 1955 a += /*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/a;
1955 a -= b; 1956 a -= b;
1956 (/*severe:STATIC_TYPE_ERROR*/b -= b); 1957 /*severe:STATIC_TYPE_ERROR*/b -= /*warning:INVALID_ASSIGNMENT*/b;
1957 a <<= b; 1958 a <<= b;
1958 a >>= b; 1959 a >>= b;
1959 a &= b; 1960 a &= b;
1960 a ^= b; 1961 a ^= b;
1961 a |= b; 1962 a |= b;
1962 (/*info:DYNAMIC_INVOKE*/c += b); 1963 /*info:DYNAMIC_INVOKE*/c += b;
1963 1964
1964 var d = new D(); 1965 var d = new D();
1965 a[b] += d; 1966 a[b] += d;
1966 a[/*info:DYNAMIC_CAST*/c] += d; 1967 a[/*info:DYNAMIC_CAST*/c] += d;
1967 a[/*severe:STATIC_TYPE_ERROR*/z] += d; 1968 a[/*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z] += d;
1968 a[b] += /*info:DYNAMIC_CAST*/c; 1969 a[b] += /*info:DYNAMIC_CAST*/c;
1969 a[b] += /*severe:STATIC_TYPE_ERROR*/z; 1970 a[b] += /*warning:ARGUMENT_TYPE_NOT_ASSIGNABLE*/z;
1970 /*info:DYNAMIC_INVOKE,info:DYNAMIC_INVOKE*/c[b] += d; 1971 /*info:DYNAMIC_INVOKE,info:DYNAMIC_INVOKE*/c[b] += d;
1971 } 1972 }
1972 '''); 1973 ''');
1973 }); 1974 });
1974 1975
1975 test('super call placement', () { 1976 test('super call placement', () {
1976 checkFile(''' 1977 checkFile('''
1977 class Base { 1978 class Base {
1978 var x; 1979 var x;
1979 Base() : x = print('Base.1') { print('Base.2'); } 1980 Base() : x = print('Base.1') { print('Base.2'); }
(...skipping 24 matching lines...) Expand all
2004 } 2005 }
2005 2006
2006 main() => new Derived(); 2007 main() => new Derived();
2007 '''); 2008 ''');
2008 }); 2009 });
2009 2010
2010 test('for loop variable', () { 2011 test('for loop variable', () {
2011 checkFile(''' 2012 checkFile('''
2012 foo() { 2013 foo() {
2013 for (int i = 0; i < 10; i++) { 2014 for (int i = 0; i < 10; i++) {
2014 i = /*severe:STATIC_TYPE_ERROR*/"hi"; 2015 i = /*warning:INVALID_ASSIGNMENT*/"hi";
2015 } 2016 }
2016 } 2017 }
2017 bar() { 2018 bar() {
2018 for (var i = 0; i < 10; i++) { 2019 for (var i = 0; i < 10; i++) {
2019 int j = i + 1; 2020 int j = i + 1;
2020 } 2021 }
2021 } 2022 }
2022 '''); 2023 ''');
2023 }); 2024 });
2024 2025
(...skipping 11 matching lines...) Expand all
2036 test('child override', () { 2037 test('child override', () {
2037 checkFile(''' 2038 checkFile('''
2038 class A {} 2039 class A {}
2039 class B {} 2040 class B {}
2040 2041
2041 class Base { 2042 class Base {
2042 A f; 2043 A f;
2043 } 2044 }
2044 2045
2045 class T1 extends Base { 2046 class T1 extends Base {
2046 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_FIELD_OVERRIDE*/B get f => null; 2047 /*warning:MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, sever e:INVALID_FIELD_OVERRIDE, severe:INVALID_METHOD_OVERRIDE*/B get
2048 /*warning:INVALID_GETTER_OVERRIDE_RETURN_TYPE*/f => null;
2047 } 2049 }
2048 2050
2049 class T2 extends Base { 2051 class T2 extends Base {
2050 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_FIELD_OVERRIDE*/se t f(B b) => null; 2052 /*warning:MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, sever e:INVALID_FIELD_OVERRIDE, severe:INVALID_METHOD_OVERRIDE*/set f(
2053 /*warning:INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE*/B b) => n ull;
2051 } 2054 }
2052 2055
2053 class T3 extends Base { 2056 class T3 extends Base {
2054 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/fi nal B f; 2057 /*severe:INVALID_FIELD_OVERRIDE, severe:INVALID_METHOD_OVERRIDE*/f inal B
2058 /*warning:FINAL_NOT_INITIALIZED, warning:INVALID_GETTER_OVERRI DE_RETURN_TYPE*/f;
2055 } 2059 }
2056 class T4 extends Base { 2060 class T4 extends Base {
2057 // two: one for the getter one for the setter. 2061 // two: one for the getter one for the setter.
2058 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sev ere:INVALID_METHOD_OVERRIDE*/B f; 2062 /*severe:INVALID_FIELD_OVERRIDE, severe:INVALID_METHOD_OVERRIDE, s evere:INVALID_METHOD_OVERRIDE*/B
2063 /*warning:INVALID_GETTER_OVERRIDE_RETURN_TYPE, warning:INVALID _SETTER_OVERRIDE_NORMAL_PARAM_TYPE*/f;
2059 } 2064 }
2060 2065
2061 class T5 implements Base { 2066 class /*warning:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE*/T5 implements Base {
2062 /*severe:INVALID_METHOD_OVERRIDE*/B get f => null; 2067 /*warning:MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, sever e:INVALID_METHOD_OVERRIDE*/B get
2068 /*warning:INVALID_GETTER_OVERRIDE_RETURN_TYPE*/f => null;
2063 } 2069 }
2064 2070
2065 class T6 implements Base { 2071 class /*warning:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE*/T6 implements Base {
2066 /*severe:INVALID_METHOD_OVERRIDE*/set f(B b) => null; 2072 /*warning:MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, sever e:INVALID_METHOD_OVERRIDE*/set f(
2073 /*warning:INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE*/B b) => n ull;
2067 } 2074 }
2068 2075
2069 class T7 implements Base { 2076 class /*warning:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE*/T7 implements Base {
2070 /*severe:INVALID_METHOD_OVERRIDE*/final B f; 2077 /*severe:INVALID_METHOD_OVERRIDE*/final B
2078 /*warning:INVALID_GETTER_OVERRIDE_RETURN_TYPE*/f = null;
2071 } 2079 }
2072 class T8 implements Base { 2080 class T8 implements Base {
2073 // two: one for the getter one for the setter. 2081 // two: one for the getter one for the setter.
2074 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B f; 2082 /*severe:INVALID_METHOD_OVERRIDE, severe:INVALID_METHOD_OVERRIDE*/ B
2083 /*warning:INVALID_GETTER_OVERRIDE_RETURN_TYPE, warning:INVALID _SETTER_OVERRIDE_NORMAL_PARAM_TYPE*/f;
2075 } 2084 }
2076 '''); 2085 ''');
2077 }); 2086 });
2078 2087
2079 test('child override 2', () { 2088 test('child override 2', () {
2080 checkFile(''' 2089 checkFile('''
2081 class A {} 2090 class A {}
2082 class B {} 2091 class B {}
2083 2092
2084 class Base { 2093 class Base {
2085 m(A a) {} 2094 m(A a) {}
2086 } 2095 }
2087 2096
2088 class Test extends Base { 2097 class Test extends Base {
2089 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2098 /*severe:INVALID_METHOD_OVERRIDE*/m(
2099 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2090 } 2100 }
2091 '''); 2101 ''');
2092 }); 2102 });
2093 test('grandchild override', () { 2103 test('grandchild override', () {
2094 checkFile(''' 2104 checkFile('''
2095 class A {} 2105 class A {}
2096 class B {} 2106 class B {}
2097 2107
2098 class Grandparent { 2108 class Grandparent {
2099 m(A a) {} 2109 m(A a) {}
2100 int x; 2110 int x;
2101 } 2111 }
2102 class Parent extends Grandparent { 2112 class Parent extends Grandparent {
2103 } 2113 }
2104 2114
2105 class Test extends Parent { 2115 class Test extends Parent {
2106 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2116 /*severe:INVALID_METHOD_OVERRIDE*/m(
2117 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2107 /*severe:INVALID_FIELD_OVERRIDE*/int x; 2118 /*severe:INVALID_FIELD_OVERRIDE*/int x;
2108 } 2119 }
2109 '''); 2120 ''');
2110 }); 2121 });
2111 2122
2112 test('double override', () { 2123 test('double override', () {
2113 checkFile(''' 2124 checkFile('''
2114 class A {} 2125 class A {}
2115 class B {} 2126 class B {}
2116 2127
2117 class Grandparent { 2128 class Grandparent {
2118 m(A a) {} 2129 m(A a) {}
2119 } 2130 }
2120 class Parent extends Grandparent { 2131 class Parent extends Grandparent {
2121 m(A a) {} 2132 m(A a) {}
2122 } 2133 }
2123 2134
2124 class Test extends Parent { 2135 class Test extends Parent {
2125 // Reported only once 2136 // Reported only once
2126 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2137 /*severe:INVALID_METHOD_OVERRIDE*/m(
2138 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2127 } 2139 }
2128 '''); 2140 ''');
2129 }); 2141 });
2130 2142
2131 test('double override 2', () { 2143 test('double override 2', () {
2132 checkFile(''' 2144 checkFile('''
2133 class A {} 2145 class A {}
2134 class B {} 2146 class B {}
2135 2147
2136 class Grandparent { 2148 class Grandparent {
2137 m(A a) {} 2149 m(A a) {}
2138 } 2150 }
2139 class Parent extends Grandparent { 2151 class Parent extends Grandparent {
2140 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2152 /*severe:INVALID_METHOD_OVERRIDE*/m(
2153 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2141 } 2154 }
2142 2155
2143 class Test extends Parent { 2156 class Test extends Parent {
2144 m(B a) {} 2157 m(B a) {}
2145 } 2158 }
2146 '''); 2159 ''');
2147 }); 2160 });
2148 2161
2149 test('mixin override to base', () { 2162 test('mixin override to base', () {
2150 checkFile(''' 2163 checkFile('''
2151 class A {} 2164 class A {}
2152 class B {} 2165 class B {}
2153 2166
2154 class Base { 2167 class Base {
2155 m(A a) {} 2168 m(A a) {}
2156 int x; 2169 int x;
2157 } 2170 }
2158 2171
2159 class M1 { 2172 class M1 {
2160 m(B a) {} 2173 m(B a) {}
2161 } 2174 }
2162 2175
2163 class M2 { 2176 class M2 {
2164 int x; 2177 int x;
2165 } 2178 }
2166 2179
2167 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1 {} 2180 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1 extends Base
2168 class T2 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1, /*s evere:INVALID_FIELD_OVERRIDE*/M2 {} 2181 with /*severe:INVALID_METHOD_OVERRIDE*/M1 {}
2169 class T3 extends Base with /*severe:INVALID_FIELD_OVERRIDE*/M2, /*se vere:INVALID_METHOD_OVERRIDE*/M1 {} 2182 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T2 extends Base
2183 with /*severe:INVALID_METHOD_OVERRIDE*/M1, /*severe:INVALID_FIEL D_OVERRIDE*/M2 {}
2184 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T3 extends Base
2185 with /*severe:INVALID_FIELD_OVERRIDE*/M2, /*severe:INVALID_METHO D_OVERRIDE*/M1 {}
2170 '''); 2186 ''');
2171 }); 2187 });
2172 2188
2173 test('mixin override to mixin', () { 2189 test('mixin override to mixin', () {
2174 checkFile(''' 2190 checkFile('''
2175 class A {} 2191 class A {}
2176 class B {} 2192 class B {}
2177 2193
2178 class Base { 2194 class Base {
2179 } 2195 }
2180 2196
2181 class M1 { 2197 class M1 {
2182 m(B a) {} 2198 m(B a) {}
2183 int x; 2199 int x;
2184 } 2200 }
2185 2201
2186 class M2 { 2202 class M2 {
2187 m(A a) {} 2203 m(A a) {}
2188 int x; 2204 int x;
2189 } 2205 }
2190 2206
2191 class T1 extends Base with M1, /*severe:INVALID_METHOD_OVERRIDE,seve re:INVALID_FIELD_OVERRIDE*/M2 {} 2207 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1 extends Base
2208 with M1,
2209 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_FIELD_OVERRIDE*/ M2 {}
2192 '''); 2210 ''');
2193 }); 2211 });
2194 2212
2195 // This is a regression test for a bug in an earlier implementation were 2213 // This is a regression test for a bug in an earlier implementation were
2196 // names were hiding errors if the first mixin override looked correct, 2214 // names were hiding errors if the first mixin override looked correct,
2197 // but subsequent ones did not. 2215 // but subsequent ones did not.
2198 test('no duplicate mixin override', () { 2216 test('no duplicate mixin override', () {
2199 checkFile(''' 2217 checkFile('''
2200 class A {} 2218 class A {}
2201 class B {} 2219 class B {}
2202 2220
2203 class Base { 2221 class Base {
2204 m(A a) {} 2222 m(A a) {}
2205 } 2223 }
2206 2224
2207 class M1 { 2225 class M1 {
2208 m(A a) {} 2226 m(A a) {}
2209 } 2227 }
2210 2228
2211 class M2 { 2229 class M2 {
2212 m(B a) {} 2230 m(B a) {}
2213 } 2231 }
2214 2232
2215 class M3 { 2233 class M3 {
2216 m(B a) {} 2234 m(B a) {}
2217 } 2235 }
2218 2236
2219 class T1 extends Base 2237 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1 extends Base
2220 with M1, /*severe:INVALID_METHOD_OVERRIDE*/M2, M3 {} 2238 with M1, /*severe:INVALID_METHOD_OVERRIDE*/M2, M3 {}
2221 '''); 2239 ''');
2222 }); 2240 });
2223 2241
2224 test('class override of interface', () { 2242 test('class override of interface', () {
2225 checkFile(''' 2243 checkFile('''
2226 class A {} 2244 class A {}
2227 class B {} 2245 class B {}
2228 2246
2229 abstract class I { 2247 abstract class I {
2230 m(A a); 2248 m(A a);
2231 } 2249 }
2232 2250
2233 class T1 implements I { 2251 class T1 implements I {
2234 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2252 /*severe:INVALID_METHOD_OVERRIDE*/m(
2253 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2235 } 2254 }
2236 '''); 2255 ''');
2237 }); 2256 });
2238 2257
2239 test('base class override to child interface', () { 2258 test('base class override to child interface', () {
2240 checkFile(''' 2259 checkFile('''
2241 class A {} 2260 class A {}
2242 class B {} 2261 class B {}
2243 2262
2244 abstract class I { 2263 abstract class I {
2245 m(A a); 2264 m(A a);
2246 } 2265 }
2247 2266
2248 class Base { 2267 class Base {
2249 m(B a) {} 2268 m(B a) {}
2250 } 2269 }
2251 2270
2252 2271 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2253 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I { 2272 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I {}
2254 }
2255 '''); 2273 ''');
2256 }); 2274 });
2257 2275
2258 test('mixin override of interface', () { 2276 test('mixin override of interface', () {
2259 checkFile(''' 2277 checkFile('''
2260 class A {} 2278 class A {}
2261 class B {} 2279 class B {}
2262 2280
2263 abstract class I { 2281 abstract class I {
2264 m(A a); 2282 m(A a);
2265 } 2283 }
2266 2284
2267 class M { 2285 class M {
2268 m(B a) {} 2286 m(B a) {}
2269 } 2287 }
2270 2288
2271 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2289 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2272 implements I {} 2290 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2291 implements I {}
2273 '''); 2292 ''');
2274 }); 2293 });
2275 2294
2276 // This is a case were it is incorrect to say that the base class 2295 // This is a case were it is incorrect to say that the base class
2277 // incorrectly overrides the interface. 2296 // incorrectly overrides the interface.
2278 test('no errors if subclass correctly overrides base and interface', () { 2297 test('no errors if subclass correctly overrides base and interface', () {
2279 checkFile(''' 2298 checkFile('''
2280 class A {} 2299 class A {}
2281 class B {} 2300 class B {}
2282 2301
2283 class Base { 2302 class Base {
2284 m(A a) {} 2303 m(A a) {}
2285 } 2304 }
2286 2305
2287 class I1 { 2306 class I1 {
2288 m(B a) {} 2307 m(B a) {}
2289 } 2308 }
2290 2309
2291 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2310 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2311 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2292 implements I1 {} 2312 implements I1 {}
2293 2313
2294 class T2 extends Base implements I1 { 2314 class T2 extends Base implements I1 {
2295 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} 2315 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {}
2296 } 2316 }
2297 2317
2298 class T3 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base 2318 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T3
2319 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base
2299 implements I1 {} 2320 implements I1 {}
2300 2321
2301 class T4 extends Object with Base implements I1 { 2322 class T4 extends Object with Base implements I1 {
2302 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} 2323 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {}
2303 } 2324 }
2304 '''); 2325 ''');
2305 }); 2326 });
2306 }); 2327 });
2307 2328
2308 group('class override of grand interface', () { 2329 group('class override of grand interface', () {
2309 test('interface of interface of child', () { 2330 test('interface of interface of child', () {
2310 checkFile(''' 2331 checkFile('''
2311 class A {} 2332 class A {}
2312 class B {} 2333 class B {}
2313 2334
2314 abstract class I1 { 2335 abstract class I1 {
2315 m(A a); 2336 m(A a);
2316 } 2337 }
2317 abstract class I2 implements I1 {} 2338 abstract class I2 implements I1 {}
2318 2339
2319 class T1 implements I2 { 2340 class T1 implements I2 {
2320 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2341 /*severe:INVALID_METHOD_OVERRIDE*/m(
2342 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2321 } 2343 }
2322 '''); 2344 ''');
2323 }); 2345 });
2324 test('superclass of interface of child', () { 2346 test('superclass of interface of child', () {
2325 checkFile(''' 2347 checkFile('''
2326 class A {} 2348 class A {}
2327 class B {} 2349 class B {}
2328 2350
2329 abstract class I1 { 2351 abstract class I1 {
2330 m(A a); 2352 m(A a);
2331 } 2353 }
2332 abstract class I2 extends I1 {} 2354 abstract class I2 extends I1 {}
2333 2355
2334 class T1 implements I2 { 2356 class T1 implements I2 {
2335 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2357 /*severe:INVALID_METHOD_OVERRIDE*/m(
2358 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2336 } 2359 }
2337 '''); 2360 ''');
2338 }); 2361 });
2339 test('mixin of interface of child', () { 2362 test('mixin of interface of child', () {
2340 checkFile(''' 2363 checkFile('''
2341 class A {} 2364 class A {}
2342 class B {} 2365 class B {}
2343 2366
2344 abstract class M1 { 2367 abstract class M1 {
2345 m(A a); 2368 m(A a);
2346 } 2369 }
2347 abstract class I2 extends Object with M1 {} 2370 abstract class I2 extends Object with M1 {}
2348 2371
2349 class T1 implements I2 { 2372 class T1 implements I2 {
2350 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2373 /*severe:INVALID_METHOD_OVERRIDE*/m(
2374 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2351 } 2375 }
2352 '''); 2376 ''');
2353 }); 2377 });
2354 test('interface of abstract superclass', () { 2378 test('interface of abstract superclass', () {
2355 checkFile(''' 2379 checkFile('''
2356 class A {} 2380 class A {}
2357 class B {} 2381 class B {}
2358 2382
2359 abstract class I1 { 2383 abstract class I1 {
2360 m(A a); 2384 m(A a);
2361 } 2385 }
2362 abstract class Base implements I1 {} 2386 abstract class Base implements I1 {}
2363 2387
2364 class T1 extends Base { 2388 class T1 extends Base {
2365 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2389 /*severe:INVALID_METHOD_OVERRIDE*/m(
2390 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2366 } 2391 }
2367 '''); 2392 ''');
2368 }); 2393 });
2369 test('interface of concrete superclass', () { 2394 test('interface of concrete superclass', () {
2370 checkFile(''' 2395 checkFile('''
2371 class A {} 2396 class A {}
2372 class B {} 2397 class B {}
2373 2398
2374 abstract class I1 { 2399 abstract class I1 {
2375 m(A a); 2400 m(A a);
2376 } 2401 }
2377 2402
2378 // See issue #25 2403 class /*warning:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE*/B ase
2379 /*pass should be warning:AnalyzerError*/class Base implements I1 { 2404 implements I1 {}
2380 }
2381 2405
2382 class T1 extends Base { 2406 class T1 extends Base {
2383 // not reported technically because if the class is concrete, 2407 // not reported technically because if the class is concrete,
2384 // it should implement all its interfaces and hence it is 2408 // it should implement all its interfaces and hence it is
2385 // sufficient to check overrides against it. 2409 // sufficient to check overrides against it.
2386 m(B a) {} 2410 m(/*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2387 } 2411 }
2388 '''); 2412 ''');
2389 }); 2413 });
2390 }); 2414 });
2391 2415
2392 group('mixin override of grand interface', () { 2416 group('mixin override of grand interface', () {
2393 test('interface of interface of child', () { 2417 test('interface of interface of child', () {
2394 checkFile(''' 2418 checkFile('''
2395 class A {} 2419 class A {}
2396 class B {} 2420 class B {}
2397 2421
2398 abstract class I1 { 2422 abstract class I1 {
2399 m(A a); 2423 m(A a);
2400 } 2424 }
2401 abstract class I2 implements I1 {} 2425 abstract class I2 implements I1 {}
2402 2426
2403 class M { 2427 class M {
2404 m(B a) {} 2428 m(B a) {}
2405 } 2429 }
2406 2430
2407 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2431 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2408 implements I2 { 2432 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2409 } 2433 implements I2 {}
2410 '''); 2434 ''');
2411 }); 2435 });
2412 test('superclass of interface of child', () { 2436 test('superclass of interface of child', () {
2413 checkFile(''' 2437 checkFile('''
2414 class A {} 2438 class A {}
2415 class B {} 2439 class B {}
2416 2440
2417 abstract class I1 { 2441 abstract class I1 {
2418 m(A a); 2442 m(A a);
2419 } 2443 }
2420 abstract class I2 extends I1 {} 2444 abstract class I2 extends I1 {}
2421 2445
2422 class M { 2446 class M {
2423 m(B a) {} 2447 m(B a) {}
2424 } 2448 }
2425 2449
2426 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2450 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2427 implements I2 { 2451 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2428 } 2452 implements I2 {}
2429 '''); 2453 ''');
2430 }); 2454 });
2431 test('mixin of interface of child', () { 2455 test('mixin of interface of child', () {
2432 checkFile(''' 2456 checkFile('''
2433 class A {} 2457 class A {}
2434 class B {} 2458 class B {}
2435 2459
2436 abstract class M1 { 2460 abstract class M1 {
2437 m(A a); 2461 m(A a);
2438 } 2462 }
2439 abstract class I2 extends Object with M1 {} 2463 abstract class I2 extends Object with M1 {}
2440 2464
2441 class M { 2465 class M {
2442 m(B a) {} 2466 m(B a) {}
2443 } 2467 }
2444 2468
2445 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2469 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2446 implements I2 { 2470 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2447 } 2471 implements I2 {}
2448 '''); 2472 ''');
2449 }); 2473 });
2450 test('interface of abstract superclass', () { 2474 test('interface of abstract superclass', () {
2451 checkFile(''' 2475 checkFile('''
2452 class A {} 2476 class A {}
2453 class B {} 2477 class B {}
2454 2478
2455 abstract class I1 { 2479 abstract class I1 {
2456 m(A a); 2480 m(A a);
2457 } 2481 }
2458 abstract class Base implements I1 {} 2482 abstract class Base implements I1 {}
2459 2483
2460 class M { 2484 class M {
2461 m(B a) {} 2485 m(B a) {}
2462 } 2486 }
2463 2487
2464 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M { 2488 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1 extends Base
2465 } 2489 with /*severe:INVALID_METHOD_OVERRIDE*/M {}
2466 '''); 2490 ''');
2467 }); 2491 });
2468 test('interface of concrete superclass', () { 2492 test('interface of concrete superclass', () {
2469 checkFile(''' 2493 checkFile('''
2470 class A {} 2494 class A {}
2471 class B {} 2495 class B {}
2472 2496
2473 abstract class I1 { 2497 abstract class I1 {
2474 m(A a); 2498 m(A a);
2475 } 2499 }
2476 2500
2477 // See issue #25 2501 class /*warning:NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER_ONE*/B ase
2478 /*pass should be warning:AnalyzerError*/class Base implements I1 { 2502 implements I1 {}
2479 }
2480 2503
2481 class M { 2504 class M {
2482 m(B a) {} 2505 m(B a) {}
2483 } 2506 }
2484 2507
2485 class T1 extends Base with M { 2508 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1 extends Base
2486 } 2509 with M {}
2487 '''); 2510 ''');
2488 }); 2511 });
2489 }); 2512 });
2490 2513
2491 group('superclass override of grand interface', () { 2514 group('superclass override of grand interface', () {
2492 test('interface of interface of child', () { 2515 test('interface of interface of child', () {
2493 checkFile(''' 2516 checkFile('''
2494 class A {} 2517 class A {}
2495 class B {} 2518 class B {}
2496 2519
2497 abstract class I1 { 2520 abstract class I1 {
2498 m(A a); 2521 m(A a);
2499 } 2522 }
2500 abstract class I2 implements I1 {} 2523 abstract class I2 implements I1 {}
2501 2524
2502 class Base { 2525 class Base {
2503 m(B a) {} 2526 m(B a) {}
2504 } 2527 }
2505 2528
2506 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2529 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2507 implements I2 { 2530 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I2 { }
2508 }
2509 '''); 2531 ''');
2510 }); 2532 });
2511 test('superclass of interface of child', () { 2533 test('superclass of interface of child', () {
2512 checkFile(''' 2534 checkFile('''
2513 class A {} 2535 class A {}
2514 class B {} 2536 class B {}
2515 2537
2516 abstract class I1 { 2538 abstract class I1 {
2517 m(A a); 2539 m(A a);
2518 } 2540 }
2519 abstract class I2 extends I1 {} 2541 abstract class I2 extends I1 {}
2520 2542
2521 class Base { 2543 class Base {
2522 m(B a) {} 2544 m(B a) {}
2523 } 2545 }
2524 2546
2525 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2547 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2526 implements I2 { 2548 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2527 } 2549 implements I2 {}
2528 '''); 2550 ''');
2529 }); 2551 });
2530 test('mixin of interface of child', () { 2552 test('mixin of interface of child', () {
2531 checkFile(''' 2553 checkFile('''
2532 class A {} 2554 class A {}
2533 class B {} 2555 class B {}
2534 2556
2535 abstract class M1 { 2557 abstract class M1 {
2536 m(A a); 2558 m(A a);
2537 } 2559 }
2538 abstract class I2 extends Object with M1 {} 2560 abstract class I2 extends Object with M1 {}
2539 2561
2540 class Base { 2562 class Base {
2541 m(B a) {} 2563 m(B a) {}
2542 } 2564 }
2543 2565
2544 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2566 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2545 implements I2 { 2567 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2546 } 2568 implements I2 {}
2547 '''); 2569 ''');
2548 }); 2570 });
2549 test('interface of abstract superclass', () { 2571 test('interface of abstract superclass', () {
2550 checkFile(''' 2572 checkFile('''
2551 class A {} 2573 class A {}
2552 class B {} 2574 class B {}
2553 2575
2554 abstract class I1 { 2576 abstract class I1 {
2555 m(A a); 2577 m(A a);
2556 } 2578 }
2557 2579
2558 abstract class Base implements I1 { 2580 abstract class Base implements I1 {
2559 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2581 /*severe:INVALID_METHOD_OVERRIDE*/m(
2582 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2560 } 2583 }
2561 2584
2562 class T1 extends Base { 2585 class T1 extends Base {
2563 // we consider the base class incomplete because it is 2586 // we consider the base class incomplete because it is
2564 // abstract, so we report the error here too. 2587 // abstract, so we report the error here too.
2565 // TODO(sigmund): consider tracking overrides in a fine-grain 2588 // TODO(sigmund): consider tracking overrides in a fine-grain
2566 // manner, then this and the double-overrides would not be 2589 // manner, then this and the double-overrides would not be
2567 // reported. 2590 // reported.
2568 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2591 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {}
2569 } 2592 }
2570 '''); 2593 ''');
2571 }); 2594 });
2572 test('interface of concrete superclass', () { 2595 test('interface of concrete superclass', () {
2573 checkFile(''' 2596 checkFile('''
2574 class A {} 2597 class A {}
2575 class B {} 2598 class B {}
2576 2599
2577 abstract class I1 { 2600 abstract class I1 {
2578 m(A a); 2601 m(A a);
2579 } 2602 }
2580 2603
2581 class Base implements I1 { 2604 class Base implements I1 {
2582 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2605 /*severe:INVALID_METHOD_OVERRIDE*/m(
2606 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2583 } 2607 }
2584 2608
2585 class T1 extends Base { 2609 class T1 extends Base {
2586 m(B a) {} 2610 m(B a) {}
2587 } 2611 }
2588 '''); 2612 ''');
2589 }); 2613 });
2590 }); 2614 });
2591 2615
2592 group('no duplicate reports from overriding interfaces', () { 2616 group('no duplicate reports from overriding interfaces', () {
2593 test('type overrides same method in multiple interfaces', () { 2617 test('type overrides same method in multiple interfaces', () {
2594 checkFile(''' 2618 checkFile('''
2595 class A {} 2619 class A {}
2596 class B {} 2620 class B {}
2597 2621
2598 abstract class I1 { 2622 abstract class I1 {
2599 m(A a); 2623 m(A a);
2600 } 2624 }
2601 abstract class I2 implements I1 { 2625 abstract class I2 implements I1 {
2602 m(A a); 2626 m(A a);
2603 } 2627 }
2604 2628
2605 class Base { 2629 class Base {}
2606 }
2607 2630
2608 class T1 implements I2 { 2631 class T1 implements I2 {
2609 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2632 /*severe:INVALID_METHOD_OVERRIDE*/m(
2633 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2610 } 2634 }
2611 '''); 2635 ''');
2612 }); 2636 });
2613 2637
2614 test('type and base type override same method in interface', () { 2638 test('type and base type override same method in interface', () {
2615 checkFile(''' 2639 checkFile('''
2616 class A {} 2640 class A {}
2617 class B {} 2641 class B {}
2618 2642
2619 abstract class I1 { 2643 abstract class I1 {
2620 m(A a); 2644 m(A a);
2621 } 2645 }
2622 2646
2623 class Base { 2647 class Base {
2624 m(B a); 2648 m(B a) {}
2625 } 2649 }
2626 2650
2627 // Note: no error reported in `extends Base` to avoid duplicating 2651 // Note: no error reported in `extends Base` to avoid duplicating
2628 // the error in T1. 2652 // the error in T1.
2629 class T1 extends Base implements I1 { 2653 class T1 extends Base implements I1 {
2630 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2654 /*severe:INVALID_METHOD_OVERRIDE*/m(
2655 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2631 } 2656 }
2632 2657
2633 // If there is no error in the class, we do report the error at 2658 // If there is no error in the class, we do report the error at
2634 // the base class: 2659 // the base class:
2635 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2660 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T2
2636 implements I1 { 2661 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2637 } 2662 implements I1 {}
2638 '''); 2663 ''');
2639 }); 2664 });
2640 2665
2641 test('type and mixin override same method in interface', () { 2666 test('type and mixin override same method in interface', () {
2642 checkFile(''' 2667 checkFile('''
2643 class A {} 2668 class A {}
2644 class B {} 2669 class B {}
2645 2670
2646 abstract class I1 { 2671 abstract class I1 {
2647 m(A a); 2672 m(A a);
2648 } 2673 }
2649 2674
2650 class M { 2675 class M {
2651 m(B a); 2676 m(B a) {}
2652 } 2677 }
2653 2678
2654 class T1 extends Object with M implements I1 { 2679 class T1 extends Object with M implements I1 {
2655 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} 2680 /*severe:INVALID_METHOD_OVERRIDE*/m(
2681 /*warning:INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE*/B a) {}
2656 } 2682 }
2657 2683
2658 class T2 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M 2684 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T2
2659 implements I1 { 2685 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M
2660 } 2686 implements I1 {}
2661 '''); 2687 ''');
2662 }); 2688 });
2663 2689
2664 test('two grand types override same method in interface', () { 2690 test('two grand types override same method in interface', () {
2665 checkFile(''' 2691 checkFile('''
2666 class A {} 2692 class A {}
2667 class B {} 2693 class B {}
2668 2694
2669 abstract class I1 { 2695 abstract class I1 {
2670 m(A a); 2696 m(A a);
2671 } 2697 }
2672 2698
2673 class Grandparent { 2699 class Grandparent {
2674 m(B a) {} 2700 m(B a) {}
2675 } 2701 }
2676 2702
2677 class Parent1 extends Grandparent { 2703 class Parent1 extends Grandparent {
2678 m(B a) {} 2704 m(B a) {}
2679 } 2705 }
2680 class Parent2 extends Grandparent { 2706 class Parent2 extends Grandparent {}
2681 }
2682 2707
2683 // Note: otherwise both errors would be reported on this line 2708 // Note: otherwise both errors would be reported on this line
2684 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent1 2709 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2685 implements I1 { 2710 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent1
2686 } 2711 implements I1 {}
2687 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent2 2712 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T2
2688 implements I1 { 2713 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent2
2689 } 2714 implements I1 {}
2690 '''); 2715 ''');
2691 }); 2716 });
2692 2717
2693 test('two mixins override same method in interface', () { 2718 test('two mixins override same method in interface', () {
2694 checkFile(''' 2719 checkFile('''
2695 class A {} 2720 class A {}
2696 class B {} 2721 class B {}
2697 2722
2698 abstract class I1 { 2723 abstract class I1 {
2699 m(A a); 2724 m(A a);
2700 } 2725 }
2701 2726
2702 class M1 { 2727 class M1 {
2703 m(B a) {} 2728 m(B a) {}
2704 } 2729 }
2705 2730
2706 class M2 { 2731 class M2 {
2707 m(B a) {} 2732 m(B a) {}
2708 } 2733 }
2709 2734
2710 // Here we want to report both, because the error location is 2735 // Here we want to report both, because the error location is
2711 // different. 2736 // different.
2712 // TODO(sigmund): should we merge these as well? 2737 // TODO(sigmund): should we merge these as well?
2713 class T1 extends Object 2738 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1 extends Object
2714 with /*severe:INVALID_METHOD_OVERRIDE*/M1, 2739 with /*severe:INVALID_METHOD_OVERRIDE*/M1,
2715 /*severe:INVALID_METHOD_OVERRIDE*/M2 2740 /*severe:INVALID_METHOD_OVERRIDE*/M2
2716 implements I1 { 2741 implements I1 {}
2717 }
2718 '''); 2742 ''');
2719 }); 2743 });
2720 2744
2721 test('base type and mixin override same method in interface', () { 2745 test('base type and mixin override same method in interface', () {
2722 checkFile(''' 2746 checkFile('''
2723 class A {} 2747 class A {}
2724 class B {} 2748 class B {}
2725 2749
2726 abstract class I1 { 2750 abstract class I1 {
2727 m(A a); 2751 m(A a);
2728 } 2752 }
2729 2753
2730 class Base { 2754 class Base {
2731 m(B a) {} 2755 m(B a) {}
2732 } 2756 }
2733 2757
2734 class M { 2758 class M {
2735 m(B a) {} 2759 m(B a) {}
2736 } 2760 }
2737 2761
2738 // Here we want to report both, because the error location is 2762 // Here we want to report both, because the error location is
2739 // different. 2763 // different.
2740 // TODO(sigmund): should we merge these as well? 2764 // TODO(sigmund): should we merge these as well?
2741 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base 2765 class /*warning:INCONSISTENT_METHOD_INHERITANCE*/T1
2766 /*severe:INVALID_METHOD_OVERRIDE*/extends Base
2742 with /*severe:INVALID_METHOD_OVERRIDE*/M 2767 with /*severe:INVALID_METHOD_OVERRIDE*/M
2743 implements I1 { 2768 implements I1 {}
2744 }
2745 '''); 2769 ''');
2746 }); 2770 });
2747 }); 2771 });
2748 2772
2749 test('invalid runtime checks', () { 2773 test('invalid runtime checks', () {
2750 checkFile(''' 2774 checkFile('''
2751 typedef int I2I(int x); 2775 typedef int I2I(int x);
2752 typedef int D2I(x); 2776 typedef int D2I(x);
2753 typedef int II2I(int x, int y); 2777 typedef int II2I(int x, int y);
2754 typedef int DI2I(x, int y); 2778 typedef int DI2I(x, int y);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2803 group('function modifiers', () { 2827 group('function modifiers', () {
2804 test('async', () { 2828 test('async', () {
2805 checkFile(''' 2829 checkFile('''
2806 import 'dart:async'; 2830 import 'dart:async';
2807 import 'dart:math' show Random; 2831 import 'dart:math' show Random;
2808 2832
2809 dynamic x; 2833 dynamic x;
2810 2834
2811 foo1() async => x; 2835 foo1() async => x;
2812 Future foo2() async => x; 2836 Future foo2() async => x;
2813 Future<int> foo3() async => (/*info:DYNAMIC_CAST*/x); 2837 Future<int> foo3() async => /*info:DYNAMIC_CAST*/x;
2814 Future<int> foo4() async => (new Future<int>.value(/*info:DYNAMIC_CAST*/ x)); 2838 Future<int> foo4() async => new Future<int>.value(/*info:DYNAMIC_CAST*/x );
2815 Future<int> foo5() async => (/*severe:STATIC_TYPE_ERROR*/new Future<Stri ng>.value(/*info:DYNAMIC_CAST*/x)); 2839 Future<int> foo5() async =>
2840 /*warning:RETURN_OF_INVALID_TYPE*/new Future<String>.value(/*info:DY NAMIC_CAST*/x);
2816 2841
2817 bar1() async { return x; } 2842 bar1() async { return x; }
2818 Future bar2() async { return x; } 2843 Future bar2() async { return x; }
2819 Future<int> bar3() async { return (/*info:DYNAMIC_CAST*/x); } 2844 Future<int> bar3() async { return /*info:DYNAMIC_CAST*/x; }
2820 Future<int> bar4() async { return (new Future<int>.value(/*info:DYNAMIC_ CAST*/x)); } 2845 Future<int> bar4() async { return new Future<int>.value(/*info:DYNAMIC_C AST*/x); }
2821 Future<int> bar5() async { return (/*severe:STATIC_TYPE_ERROR*/new Futur e<String>.value(/*info:DYNAMIC_CAST*/x)); } 2846 Future<int> bar5() async {
2847 return /*warning:RETURN_OF_INVALID_TYPE*/new Future<String>.value(/*in fo:DYNAMIC_CAST*/x);
2848 }
2822 2849
2823 int y; 2850 int y;
2824 Future<int> z; 2851 Future<int> z;
2825 2852
2826 void baz() async { 2853 baz() async {
2827 int a = /*info:DYNAMIC_CAST*/await x; 2854 int a = /*info:DYNAMIC_CAST*/await x;
2828 int b = await y; 2855 int b = await y;
2829 int c = await z; 2856 int c = await z;
2830 String d = /*severe:STATIC_TYPE_ERROR*/await z; 2857 String d = /*warning:INVALID_ASSIGNMENT*/await z;
2831 } 2858 }
2832 2859
2833 Future<bool> get issue_264 async { 2860 Future<bool> get issue_264 async {
2834 await 42; 2861 await 42;
2835 if (new Random().nextBool()) { 2862 if (new Random().nextBool()) {
2836 return true; 2863 return true;
2837 } else { 2864 } else {
2838 return new Future<bool>.value(false); 2865 return new Future<bool>.value(false);
2839 } 2866 }
2840 } 2867 }
2841 '''); 2868 ''');
2842 }); 2869 });
2843 2870
2844 test('async*', () { 2871 test('async*', () {
2845 checkFile(''' 2872 checkFile('''
2846 import 'dart:async'; 2873 import 'dart:async';
2847 2874
2848 dynamic x; 2875 dynamic x;
2849 2876
2850 bar1() async* { yield x; } 2877 bar1() async* { yield x; }
2851 Stream bar2() async* { yield x; } 2878 Stream bar2() async* { yield x; }
2852 Stream<int> bar3() async* { yield (/*info:DYNAMIC_CAST*/x); } 2879 Stream<int> bar3() async* { yield /*info:DYNAMIC_CAST*/x; }
2853 Stream<int> bar4() async* { yield (/*severe:STATIC_TYPE_ERROR*/new Strea m<int>()); } 2880 Stream<int> bar4() async* { yield /*warning:YIELD_OF_INVALID_TYPE*/new S tream<int>(); }
2854 2881
2855 baz1() async* { yield* (/*info:DYNAMIC_CAST*/x); } 2882 baz1() async* { yield* /*info:DYNAMIC_CAST*/x; }
2856 Stream baz2() async* { yield* (/*info:DYNAMIC_CAST*/x); } 2883 Stream baz2() async* { yield* /*info:DYNAMIC_CAST*/x; }
2857 Stream<int> baz3() async* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } 2884 Stream<int> baz3() async* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; }
2858 Stream<int> baz4() async* { yield* new Stream<int>(); } 2885 Stream<int> baz4() async* { yield* new Stream<int>(); }
2859 Stream<int> baz5() async* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/new Stream()); } 2886 Stream<int> baz5() async* { yield* /*info:INFERRED_TYPE_ALLOCATION*/new Stream(); }
2860 '''); 2887 ''');
2861 }); 2888 });
2862 2889
2863 test('sync*', () { 2890 test('sync*', () {
2864 checkFile(''' 2891 checkFile('''
2865 import 'dart:async';
2866
2867 dynamic x; 2892 dynamic x;
2868 2893
2869 bar1() sync* { yield x; } 2894 bar1() sync* { yield x; }
2870 Iterable bar2() sync* { yield x; } 2895 Iterable bar2() sync* { yield x; }
2871 Iterable<int> bar3() sync* { yield (/*info:DYNAMIC_CAST*/x); } 2896 Iterable<int> bar3() sync* { yield /*info:DYNAMIC_CAST*/x; }
2872 Iterable<int> bar4() sync* { yield (/*severe:STATIC_TYPE_ERROR*/new Iter able<int>()); } 2897 Iterable<int> bar4() sync* {
2898 yield /*warning:YIELD_OF_INVALID_TYPE*/new /*warning:NEW_WITH_ABSTRACT _CLASS*/Iterable<int>();
Leaf 2016/03/10 22:58:25 I think the extra error here is just noise, the te
Bob Nystrom 2016/03/15 00:08:13 Ah, great idea. I didn't want to change it to List
2899 }
2873 2900
2874 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2901 baz1() sync* { yield* /*info:DYNAMIC_CAST*/x; }
2875 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } 2902 Iterable baz2() sync* { yield* /*info:DYNAMIC_CAST*/x; }
2876 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } 2903 Iterable<int> baz3() sync* { yield* /*warning:DOWN_CAST_COMPOSITE*/x; }
2877 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } 2904 Iterable<int> baz4() sync* {
2878 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); } 2905 yield* new /*warning:NEW_WITH_ABSTRACT_CLASS*/Iterable<int>();
Leaf 2016/03/10 22:58:25 ditto.
Bob Nystrom 2016/03/15 00:08:13 Done.
2906 }
2907 Iterable<int> baz5() sync* {
2908 yield* /*info:INFERRED_TYPE_ALLOCATION*/new /*warning:NEW_WITH_ABSTRAC T_CLASS*/Iterable();
Leaf 2016/03/10 22:58:25 and again.
Bob Nystrom 2016/03/15 00:08:13 Changed this to new List() since we want to test i
2909 }
2879 '''); 2910 ''');
2880 }); 2911 });
2881 }); 2912 });
2882 } 2913 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698