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