Chromium Code Reviews| 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'; |
| 11 | 11 |
| 12 import 'strong_test_helper.dart'; | 12 import 'strong_test_helper.dart'; |
| 13 | 13 |
| 14 void main() { | 14 void main() { |
| 15 testChecker('ternary operator', { | 15 testChecker( |
|
Paul Berry
2016/02/05 15:23:16
Nit: consider modifying testChecker so that it doe
| |
| 16 '/main.dart': ''' | 16 'ternary operator', |
| 17 () => { | |
| 18 '/main.dart': ''' | |
| 17 abstract class Comparable<T> { | 19 abstract class Comparable<T> { |
| 18 int compareTo(T other); | 20 int compareTo(T other); |
| 19 static int compare(Comparable a, Comparable b) => a.compareTo(b); | 21 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 20 } | 22 } |
| 21 typedef int Comparator<T>(T a, T b); | 23 typedef int Comparator<T>(T a, T b); |
| 22 | 24 |
| 23 typedef bool _Predicate<T>(T value); | 25 typedef bool _Predicate<T>(T value); |
| 24 | 26 |
| 25 class SplayTreeMap<K, V> { | 27 class SplayTreeMap<K, V> { |
| 26 Comparator<K> _comparator; | 28 Comparator<K> _comparator; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 47 Object obj = 42; | 49 Object obj = 42; |
| 48 dynamic dyn = 42; | 50 dynamic dyn = 42; |
| 49 int i = 42; | 51 int i = 42; |
| 50 | 52 |
| 51 // Check the boolean conversion of the condition. | 53 // Check the boolean conversion of the condition. |
| 52 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true); | 54 print((/*severe:STATIC_TYPE_ERROR*/i) ? false : true); |
| 53 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true); | 55 print((/*info:DOWN_CAST_IMPLICIT*/obj) ? false : true); |
| 54 print((/*info:DYNAMIC_CAST*/dyn) ? false : true); | 56 print((/*info:DYNAMIC_CAST*/dyn) ? false : true); |
| 55 } | 57 } |
| 56 ''' | 58 ''' |
| 57 }); | 59 }); |
| 58 | 60 |
| 59 testChecker('if/for/do/while statements use boolean conversion', { | 61 testChecker( |
| 60 '/main.dart': ''' | 62 'if/for/do/while statements use boolean conversion', |
| 63 () => { | |
| 64 '/main.dart': ''' | |
| 61 main() { | 65 main() { |
| 62 dynamic d = 42; | 66 dynamic d = 42; |
| 63 Object obj = 42; | 67 Object obj = 42; |
| 64 int i = 42; | 68 int i = 42; |
| 65 bool b = false; | 69 bool b = false; |
| 66 | 70 |
| 67 if (b) {} | 71 if (b) {} |
| 68 if (/*info:DYNAMIC_CAST*/dyn) {} | 72 if (/*info:DYNAMIC_CAST*/dyn) {} |
| 69 if (/*info:DOWN_CAST_IMPLICIT*/obj) {} | 73 if (/*info:DOWN_CAST_IMPLICIT*/obj) {} |
| 70 if (/*severe:STATIC_TYPE_ERROR*/i) {} | 74 if (/*severe:STATIC_TYPE_ERROR*/i) {} |
| 71 | 75 |
| 72 while (b) {} | 76 while (b) {} |
| 73 while (/*info:DYNAMIC_CAST*/dyn) {} | 77 while (/*info:DYNAMIC_CAST*/dyn) {} |
| 74 while (/*info:DOWN_CAST_IMPLICIT*/obj) {} | 78 while (/*info:DOWN_CAST_IMPLICIT*/obj) {} |
| 75 while (/*severe:STATIC_TYPE_ERROR*/i) {} | 79 while (/*severe:STATIC_TYPE_ERROR*/i) {} |
| 76 | 80 |
| 77 do {} while (b); | 81 do {} while (b); |
| 78 do {} while (/*info:DYNAMIC_CAST*/dyn); | 82 do {} while (/*info:DYNAMIC_CAST*/dyn); |
| 79 do {} while (/*info:DOWN_CAST_IMPLICIT*/obj); | 83 do {} while (/*info:DOWN_CAST_IMPLICIT*/obj); |
| 80 do {} while (/*severe:STATIC_TYPE_ERROR*/i); | 84 do {} while (/*severe:STATIC_TYPE_ERROR*/i); |
| 81 | 85 |
| 82 for (;b;) {} | 86 for (;b;) {} |
| 83 for (;/*info:DYNAMIC_CAST*/dyn;) {} | 87 for (;/*info:DYNAMIC_CAST*/dyn;) {} |
| 84 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} | 88 for (;/*info:DOWN_CAST_IMPLICIT*/obj;) {} |
| 85 for (;/*severe:STATIC_TYPE_ERROR*/i;) {} | 89 for (;/*severe:STATIC_TYPE_ERROR*/i;) {} |
| 86 } | 90 } |
| 87 ''' | 91 ''' |
| 88 }); | 92 }); |
| 89 | 93 |
| 90 testChecker('dynamic invocation', { | 94 testChecker( |
| 91 '/main.dart': ''' | 95 'dynamic invocation', |
| 96 () => { | |
| 97 '/main.dart': ''' | |
| 92 | 98 |
| 93 class A { | 99 class A { |
| 94 dynamic call(dynamic x) => x; | 100 dynamic call(dynamic x) => x; |
| 95 } | 101 } |
| 96 class B extends A { | 102 class B extends A { |
| 97 int call(int x) => x; | 103 int call(int x) => x; |
| 98 double col(double x) => x; | 104 double col(double x) => x; |
| 99 } | 105 } |
| 100 void main() { | 106 void main() { |
| 101 { | 107 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 (/*info:DYNAMIC_INVOKE*/g.foo(42.0)); | 141 (/*info:DYNAMIC_INVOKE*/g.foo(42.0)); |
| 136 (/*info:DYNAMIC_INVOKE*/g.x); | 142 (/*info:DYNAMIC_INVOKE*/g.x); |
| 137 A f = new B(); | 143 A f = new B(); |
| 138 f.call(32.0); | 144 f.call(32.0); |
| 139 (/*info:DYNAMIC_INVOKE*/f.col(42.0)); | 145 (/*info:DYNAMIC_INVOKE*/f.col(42.0)); |
| 140 (/*info:DYNAMIC_INVOKE*/f.foo(42.0)); | 146 (/*info:DYNAMIC_INVOKE*/f.foo(42.0)); |
| 141 (/*info:DYNAMIC_INVOKE*/f.x); | 147 (/*info:DYNAMIC_INVOKE*/f.x); |
| 142 } | 148 } |
| 143 } | 149 } |
| 144 ''' | 150 ''' |
| 145 }); | 151 }); |
| 146 | 152 |
| 147 testChecker('conversion and dynamic invoke', { | 153 testChecker( |
| 148 '/helper.dart': ''' | 154 'conversion and dynamic invoke', |
| 155 () => { | |
| 156 '/helper.dart': ''' | |
| 149 dynamic toString = (int x) => x + 42; | 157 dynamic toString = (int x) => x + 42; |
| 150 dynamic hashCode = "hello"; | 158 dynamic hashCode = "hello"; |
| 151 ''', | 159 ''', |
| 152 '/main.dart': ''' | 160 '/main.dart': ''' |
| 153 import 'helper.dart' as helper; | 161 import 'helper.dart' as helper; |
| 154 | 162 |
| 155 class A { | 163 class A { |
| 156 String x = "hello world"; | 164 String x = "hello world"; |
| 157 | 165 |
| 158 void baz1(y) => x + /*info:DYNAMIC_CAST*/y; | 166 void baz1(y) => x + /*info:DYNAMIC_CAST*/y; |
| 159 static baz2(y) => /*info:DYNAMIC_INVOKE*/y + y; | 167 static baz2(y) => /*info:DYNAMIC_INVOKE*/y + y; |
| 160 } | 168 } |
| 161 | 169 |
| 162 void foo(String str) { | 170 void foo(String str) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 223 |
| 216 (/*info:DYNAMIC_INVOKE*/helper.toString()); | 224 (/*info:DYNAMIC_INVOKE*/helper.toString()); |
| 217 var toStringClosure2 = helper.toString; | 225 var toStringClosure2 = helper.toString; |
| 218 (/*info:DYNAMIC_INVOKE*/toStringClosure2()); | 226 (/*info:DYNAMIC_INVOKE*/toStringClosure2()); |
| 219 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode; | 227 int hashCode = /*info:DYNAMIC_CAST*/helper.hashCode; |
| 220 | 228 |
| 221 baz().toString(); | 229 baz().toString(); |
| 222 baz().hashCode; | 230 baz().hashCode; |
| 223 } | 231 } |
| 224 ''' | 232 ''' |
| 225 }); | 233 }); |
| 226 | 234 |
| 227 testChecker('Constructors', { | 235 testChecker( |
| 228 '/main.dart': ''' | 236 'Constructors', |
| 237 () => { | |
| 238 '/main.dart': ''' | |
| 229 const num z = 25; | 239 const num z = 25; |
| 230 Object obj = "world"; | 240 Object obj = "world"; |
| 231 | 241 |
| 232 class A { | 242 class A { |
| 233 int x; | 243 int x; |
| 234 String y; | 244 String y; |
| 235 | 245 |
| 236 A(this.x) : this.y = /*severe:STATIC_TYPE_ERROR*/42; | 246 A(this.x) : this.y = /*severe:STATIC_TYPE_ERROR*/42; |
| 237 | 247 |
| 238 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_ CAST*/p; | 248 A.c1(p): this.x = /*info:DOWN_CAST_IMPLICIT*/z, this.y = /*info:DYNAMIC_ CAST*/p; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 249 /*severe:STATIC_TYPE_ERROR*/x); | 259 /*severe:STATIC_TYPE_ERROR*/x); |
| 250 | 260 |
| 251 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/y); | 261 B.c3(num x, Object y) : super.c3(x, /*info:DOWN_CAST_IMPLICIT*/y); |
| 252 } | 262 } |
| 253 | 263 |
| 254 void main() { | 264 void main() { |
| 255 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR */z); | 265 A a = new A.c2(/*info:DOWN_CAST_IMPLICIT*/z, /*severe:STATIC_TYPE_ERROR */z); |
| 256 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_ IMPLICIT*/obj); | 266 var b = new B.c2(/*severe:STATIC_TYPE_ERROR*/"hello", /*info:DOWN_CAST_ IMPLICIT*/obj); |
| 257 } | 267 } |
| 258 ''' | 268 ''' |
| 259 }); | 269 }); |
| 260 | 270 |
| 261 testChecker('Unbound variable', { | 271 testChecker( |
| 262 '/main.dart': ''' | 272 'Unbound variable', |
| 273 () => { | |
| 274 '/main.dart': ''' | |
| 263 void main() { | 275 void main() { |
| 264 dynamic y = /*pass should be severe:STATIC_TYPE_ERROR*/unboundVariable; | 276 dynamic y = /*pass should be severe:STATIC_TYPE_ERROR*/unboundVariable; |
| 265 } | 277 } |
| 266 ''' | 278 ''' |
| 267 }); | 279 }); |
| 268 | 280 |
| 269 testChecker('Unbound type name', { | 281 testChecker( |
| 270 '/main.dart': ''' | 282 'Unbound type name', |
| 283 () => { | |
| 284 '/main.dart': ''' | |
| 271 void main() { | 285 void main() { |
| 272 /*pass should be severe:STATIC_TYPE_ERROR*/AToB y; | 286 /*pass should be severe:STATIC_TYPE_ERROR*/AToB y; |
| 273 } | 287 } |
| 274 ''' | 288 ''' |
| 275 }); | 289 }); |
| 276 | 290 |
| 277 // Regression test for https://github.com/dart-lang/sdk/issues/25069 | 291 // Regression test for https://github.com/dart-lang/sdk/issues/25069 |
| 278 testChecker('Void subtyping', { | 292 testChecker( |
| 279 '/main.dart': ''' | 293 'Void subtyping', |
| 294 () => { | |
| 295 '/main.dart': ''' | |
| 280 typedef int Foo(); | 296 typedef int Foo(); |
| 281 void foo() {} | 297 void foo() {} |
| 282 void main () { | 298 void main () { |
| 283 Foo x = /*severe:STATIC_TYPE_ERROR*/foo(); | 299 Foo x = /*severe:STATIC_TYPE_ERROR*/foo(); |
| 284 } | 300 } |
| 285 ''' | 301 ''' |
| 286 }); | 302 }); |
| 287 | 303 |
| 288 testChecker('Ground type subtyping: dynamic is top', { | 304 testChecker( |
| 289 '/main.dart': ''' | 305 'Ground type subtyping: dynamic is top', |
| 306 () => { | |
| 307 '/main.dart': ''' | |
| 290 | 308 |
| 291 class A {} | 309 class A {} |
| 292 class B extends A {} | 310 class B extends A {} |
| 293 | 311 |
| 294 void main() { | 312 void main() { |
| 295 dynamic y; | 313 dynamic y; |
| 296 Object o; | 314 Object o; |
| 297 int i = 0; | 315 int i = 0; |
| 298 double d = 0.0; | 316 double d = 0.0; |
| 299 num n; | 317 num n; |
| 300 A a; | 318 A a; |
| 301 B b; | 319 B b; |
| 302 y = o; | 320 y = o; |
| 303 y = i; | 321 y = i; |
| 304 y = d; | 322 y = d; |
| 305 y = n; | 323 y = n; |
| 306 y = a; | 324 y = a; |
| 307 y = b; | 325 y = b; |
| 308 } | 326 } |
| 309 ''' | 327 ''' |
| 310 }); | 328 }); |
| 311 | 329 |
| 312 testChecker('Ground type subtyping: dynamic downcasts', { | 330 testChecker( |
| 313 '/main.dart': ''' | 331 'Ground type subtyping: dynamic downcasts', |
| 332 () => { | |
| 333 '/main.dart': ''' | |
| 314 | 334 |
| 315 class A {} | 335 class A {} |
| 316 class B extends A {} | 336 class B extends A {} |
| 317 | 337 |
| 318 void main() { | 338 void main() { |
| 319 dynamic y; | 339 dynamic y; |
| 320 Object o; | 340 Object o; |
| 321 int i = 0; | 341 int i = 0; |
| 322 double d = 0.0; | 342 double d = 0.0; |
| 323 num n; | 343 num n; |
| 324 A a; | 344 A a; |
| 325 B b; | 345 B b; |
| 326 o = y; | 346 o = y; |
| 327 i = /*info:DYNAMIC_CAST*/y; | 347 i = /*info:DYNAMIC_CAST*/y; |
| 328 d = /*info:DYNAMIC_CAST*/y; | 348 d = /*info:DYNAMIC_CAST*/y; |
| 329 n = /*info:DYNAMIC_CAST*/y; | 349 n = /*info:DYNAMIC_CAST*/y; |
| 330 a = /*info:DYNAMIC_CAST*/y; | 350 a = /*info:DYNAMIC_CAST*/y; |
| 331 b = /*info:DYNAMIC_CAST*/y; | 351 b = /*info:DYNAMIC_CAST*/y; |
| 332 } | 352 } |
| 333 ''' | 353 ''' |
| 334 }); | 354 }); |
| 335 | 355 |
| 336 testChecker('Ground type subtyping: assigning a class', { | 356 testChecker( |
| 337 '/main.dart': ''' | 357 'Ground type subtyping: assigning a class', |
| 358 () => { | |
| 359 '/main.dart': ''' | |
| 338 | 360 |
| 339 class A {} | 361 class A {} |
| 340 class B extends A {} | 362 class B extends A {} |
| 341 | 363 |
| 342 void main() { | 364 void main() { |
| 343 dynamic y; | 365 dynamic y; |
| 344 Object o; | 366 Object o; |
| 345 int i = 0; | 367 int i = 0; |
| 346 double d = 0.0; | 368 double d = 0.0; |
| 347 num n; | 369 num n; |
| 348 A a; | 370 A a; |
| 349 B b; | 371 B b; |
| 350 y = a; | 372 y = a; |
| 351 o = a; | 373 o = a; |
| 352 i = /*severe:STATIC_TYPE_ERROR*/a; | 374 i = /*severe:STATIC_TYPE_ERROR*/a; |
| 353 d = /*severe:STATIC_TYPE_ERROR*/a; | 375 d = /*severe:STATIC_TYPE_ERROR*/a; |
| 354 n = /*severe:STATIC_TYPE_ERROR*/a; | 376 n = /*severe:STATIC_TYPE_ERROR*/a; |
| 355 a = a; | 377 a = a; |
| 356 b = /*info:DOWN_CAST_IMPLICIT*/a; | 378 b = /*info:DOWN_CAST_IMPLICIT*/a; |
| 357 } | 379 } |
| 358 ''' | 380 ''' |
| 359 }); | 381 }); |
| 360 | 382 |
| 361 testChecker('Ground type subtyping: assigning a subclass', { | 383 testChecker( |
| 362 '/main.dart': ''' | 384 'Ground type subtyping: assigning a subclass', |
| 385 () => { | |
| 386 '/main.dart': ''' | |
| 363 | 387 |
| 364 class A {} | 388 class A {} |
| 365 class B extends A {} | 389 class B extends A {} |
| 366 class C extends A {} | 390 class C extends A {} |
| 367 | 391 |
| 368 void main() { | 392 void main() { |
| 369 dynamic y; | 393 dynamic y; |
| 370 Object o; | 394 Object o; |
| 371 int i = 0; | 395 int i = 0; |
| 372 double d = 0.0; | 396 double d = 0.0; |
| 373 num n; | 397 num n; |
| 374 A a; | 398 A a; |
| 375 B b; | 399 B b; |
| 376 C c; | 400 C c; |
| 377 y = b; | 401 y = b; |
| 378 o = b; | 402 o = b; |
| 379 i = /*severe:STATIC_TYPE_ERROR*/b; | 403 i = /*severe:STATIC_TYPE_ERROR*/b; |
| 380 d = /*severe:STATIC_TYPE_ERROR*/b; | 404 d = /*severe:STATIC_TYPE_ERROR*/b; |
| 381 n = /*severe:STATIC_TYPE_ERROR*/b; | 405 n = /*severe:STATIC_TYPE_ERROR*/b; |
| 382 a = b; | 406 a = b; |
| 383 b = b; | 407 b = b; |
| 384 c = /*severe:STATIC_TYPE_ERROR*/b; | 408 c = /*severe:STATIC_TYPE_ERROR*/b; |
| 385 } | 409 } |
| 386 ''' | 410 ''' |
| 387 }); | 411 }); |
| 388 | 412 |
| 389 testChecker('Ground type subtyping: interfaces', { | 413 testChecker( |
| 390 '/main.dart': ''' | 414 'Ground type subtyping: interfaces', |
| 415 () => { | |
| 416 '/main.dart': ''' | |
| 391 | 417 |
| 392 class A {} | 418 class A {} |
| 393 class B extends A {} | 419 class B extends A {} |
| 394 class C extends A {} | 420 class C extends A {} |
| 395 class D extends B implements C {} | 421 class D extends B implements C {} |
| 396 | 422 |
| 397 void main() { | 423 void main() { |
| 398 A top; | 424 A top; |
| 399 B left; | 425 B left; |
| 400 C right; | 426 C right; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 418 right = bot; | 444 right = bot; |
| 419 } | 445 } |
| 420 { | 446 { |
| 421 bot = /*info:DOWN_CAST_IMPLICIT*/top; | 447 bot = /*info:DOWN_CAST_IMPLICIT*/top; |
| 422 bot = /*info:DOWN_CAST_IMPLICIT*/left; | 448 bot = /*info:DOWN_CAST_IMPLICIT*/left; |
| 423 bot = /*info:DOWN_CAST_IMPLICIT*/right; | 449 bot = /*info:DOWN_CAST_IMPLICIT*/right; |
| 424 bot = bot; | 450 bot = bot; |
| 425 } | 451 } |
| 426 } | 452 } |
| 427 ''' | 453 ''' |
| 428 }); | 454 }); |
| 429 | 455 |
| 430 testChecker('Function typing and subtyping: int and object', { | 456 testChecker( |
| 431 '/main.dart': ''' | 457 'Function typing and subtyping: int and object', |
| 458 () => { | |
| 459 '/main.dart': ''' | |
| 432 | 460 |
| 433 typedef Object Top(int x); // Top of the lattice | 461 typedef Object Top(int x); // Top of the lattice |
| 434 typedef int Left(int x); // Left branch | 462 typedef int Left(int x); // Left branch |
| 435 typedef int Left2(int x); // Left branch | 463 typedef int Left2(int x); // Left branch |
| 436 typedef Object Right(Object x); // Right branch | 464 typedef Object Right(Object x); // Right branch |
| 437 typedef int Bot(Object x); // Bottom of the lattice | 465 typedef int Bot(Object x); // Bottom of the lattice |
| 438 | 466 |
| 439 Object top(int x) => x; | 467 Object top(int x) => x; |
| 440 int left(int x) => x; | 468 int left(int x) => x; |
| 441 Object right(Object x) => x; | 469 Object right(Object x) => x; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 470 } | 498 } |
| 471 { | 499 { |
| 472 Bot f; | 500 Bot f; |
| 473 f = /*warning:DOWN_CAST_COMPOSITE*/top; | 501 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 474 f = /*warning:DOWN_CAST_COMPOSITE*/left; | 502 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 475 f = /*warning:DOWN_CAST_COMPOSITE*/right; | 503 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 476 f = bot; | 504 f = bot; |
| 477 } | 505 } |
| 478 } | 506 } |
| 479 ''' | 507 ''' |
| 480 }); | 508 }); |
| 481 | 509 |
| 482 testChecker('Function typing and subtyping: classes', { | 510 testChecker( |
| 483 '/main.dart': ''' | 511 'Function typing and subtyping: classes', |
| 512 () => { | |
| 513 '/main.dart': ''' | |
| 484 | 514 |
| 485 class A {} | 515 class A {} |
| 486 class B extends A {} | 516 class B extends A {} |
| 487 | 517 |
| 488 typedef A Top(B x); // Top of the lattice | 518 typedef A Top(B x); // Top of the lattice |
| 489 typedef B Left(B x); // Left branch | 519 typedef B Left(B x); // Left branch |
| 490 typedef B Left2(B x); // Left branch | 520 typedef B Left2(B x); // Left branch |
| 491 typedef A Right(A x); // Right branch | 521 typedef A Right(A x); // Right branch |
| 492 typedef B Bot(A x); // Bottom of the lattice | 522 typedef B Bot(A x); // Bottom of the lattice |
| 493 | 523 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 } | 555 } |
| 526 { | 556 { |
| 527 Bot f; | 557 Bot f; |
| 528 f = /*warning:DOWN_CAST_COMPOSITE*/top; | 558 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 529 f = /*warning:DOWN_CAST_COMPOSITE*/left; | 559 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 530 f = /*warning:DOWN_CAST_COMPOSITE*/right; | 560 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 531 f = bot; | 561 f = bot; |
| 532 } | 562 } |
| 533 } | 563 } |
| 534 ''' | 564 ''' |
| 535 }); | 565 }); |
| 536 | 566 |
| 537 testChecker('Function typing and subtyping: dynamic', { | 567 testChecker( |
| 538 '/main.dart': ''' | 568 'Function typing and subtyping: dynamic', |
| 569 () => { | |
| 570 '/main.dart': ''' | |
| 539 | 571 |
| 540 class A {} | 572 class A {} |
| 541 | 573 |
| 542 typedef dynamic Top(dynamic x); // Top of the lattice | 574 typedef dynamic Top(dynamic x); // Top of the lattice |
| 543 typedef dynamic Left(A x); // Left branch | 575 typedef dynamic Left(A x); // Left branch |
| 544 typedef A Right(dynamic x); // Right branch | 576 typedef A Right(dynamic x); // Right branch |
| 545 typedef A Bottom(A x); // Bottom of the lattice | 577 typedef A Bottom(A x); // Bottom of the lattice |
| 546 | 578 |
| 547 dynamic left(A x) => x; | 579 dynamic left(A x) => x; |
| 548 A bot(A x) => x; | 580 A bot(A x) => x; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 573 } | 605 } |
| 574 { | 606 { |
| 575 Bottom f; | 607 Bottom f; |
| 576 f = /*warning:DOWN_CAST_COMPOSITE*/top; | 608 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 577 f = /*warning:DOWN_CAST_COMPOSITE*/left; | 609 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 578 f = /*warning:DOWN_CAST_COMPOSITE*/right; | 610 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 579 f = bot; | 611 f = bot; |
| 580 } | 612 } |
| 581 } | 613 } |
| 582 ''' | 614 ''' |
| 583 }); | 615 }); |
| 584 | 616 |
| 585 testChecker('Function typing and subtyping: function literal variance', { | 617 testChecker( |
| 586 '/main.dart': ''' | 618 'Function typing and subtyping: function literal variance', |
| 619 () => { | |
| 620 '/main.dart': ''' | |
| 587 | 621 |
| 588 class A {} | 622 class A {} |
| 589 class B extends A {} | 623 class B extends A {} |
| 590 | 624 |
| 591 typedef T Function2<S, T>(S z); | 625 typedef T Function2<S, T>(S z); |
| 592 | 626 |
| 593 A top(B x) => x; | 627 A top(B x) => x; |
| 594 B left(B x) => x; | 628 B left(B x) => x; |
| 595 A right(A x) => x; | 629 A right(A x) => x; |
| 596 B bot(A x) => x as B; | 630 B bot(A x) => x as B; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 619 } | 653 } |
| 620 { | 654 { |
| 621 Function2<A, B> f; | 655 Function2<A, B> f; |
| 622 f = /*warning:DOWN_CAST_COMPOSITE*/top; | 656 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 623 f = /*warning:DOWN_CAST_COMPOSITE*/left; | 657 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 624 f = /*warning:DOWN_CAST_COMPOSITE*/right; | 658 f = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 625 f = bot; | 659 f = bot; |
| 626 } | 660 } |
| 627 } | 661 } |
| 628 ''' | 662 ''' |
| 629 }); | 663 }); |
| 630 | 664 |
| 631 testChecker('Function typing and subtyping: function variable variance', { | 665 testChecker( |
| 632 '/main.dart': ''' | 666 'Function typing and subtyping: function variable variance', |
| 667 () => { | |
| 668 '/main.dart': ''' | |
| 633 | 669 |
| 634 class A {} | 670 class A {} |
| 635 class B extends A {} | 671 class B extends A {} |
| 636 | 672 |
| 637 typedef T Function2<S, T>(S z); | 673 typedef T Function2<S, T>(S z); |
| 638 | 674 |
| 639 void main() { | 675 void main() { |
| 640 { | 676 { |
| 641 Function2<B, A> top; | 677 Function2<B, A> top; |
| 642 Function2<B, B> left; | 678 Function2<B, B> left; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 658 right = right; | 694 right = right; |
| 659 right = bot; | 695 right = bot; |
| 660 | 696 |
| 661 bot = /*warning:DOWN_CAST_COMPOSITE*/top; | 697 bot = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 662 bot = /*warning:DOWN_CAST_COMPOSITE*/left; | 698 bot = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 663 bot = /*warning:DOWN_CAST_COMPOSITE*/right; | 699 bot = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 664 bot = bot; | 700 bot = bot; |
| 665 } | 701 } |
| 666 } | 702 } |
| 667 ''' | 703 ''' |
| 668 }); | 704 }); |
| 669 | 705 |
| 670 testChecker('Function typing and subtyping: higher order function literals', { | 706 testChecker( |
| 671 '/main.dart': ''' | 707 'Function typing and subtyping: higher order function literals', |
| 708 () => { | |
| 709 '/main.dart': ''' | |
| 672 | 710 |
| 673 class A {} | 711 class A {} |
| 674 class B extends A {} | 712 class B extends A {} |
| 675 | 713 |
| 676 typedef T Function2<S, T>(S z); | 714 typedef T Function2<S, T>(S z); |
| 677 | 715 |
| 678 typedef A BToA(B x); // Top of the base lattice | 716 typedef A BToA(B x); // Top of the base lattice |
| 679 typedef B AToB(A x); // Bot of the base lattice | 717 typedef B AToB(A x); // Bot of the base lattice |
| 680 | 718 |
| 681 BToA top(AToB f) => f; | 719 BToA top(AToB f) => f; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 721 } | 759 } |
| 722 { | 760 { |
| 723 Function2<BToA, AToB> f; // Bot | 761 Function2<BToA, AToB> f; // Bot |
| 724 f = bot; | 762 f = bot; |
| 725 f = /*warning:DOWN_CAST_COMPOSITE*/left; | 763 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 726 f = /*warning:DOWN_CAST_COMPOSITE*/top; | 764 f = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 727 f = /*warning:DOWN_CAST_COMPOSITE*/left; | 765 f = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 728 } | 766 } |
| 729 } | 767 } |
| 730 ''' | 768 ''' |
| 731 }); | 769 }); |
| 732 | 770 |
| 733 testChecker( | 771 testChecker( |
| 734 'Function typing and subtyping: higher order function variables', { | 772 'Function typing and subtyping: higher order function variables', |
| 735 '/main.dart': ''' | 773 () => { |
| 774 '/main.dart': ''' | |
| 736 | 775 |
| 737 class A {} | 776 class A {} |
| 738 class B extends A {} | 777 class B extends A {} |
| 739 | 778 |
| 740 typedef T Function2<S, T>(S z); | 779 typedef T Function2<S, T>(S z); |
| 741 | 780 |
| 742 void main() { | 781 void main() { |
| 743 { | 782 { |
| 744 Function2<Function2<A, B>, Function2<B, A>> top; | 783 Function2<Function2<A, B>, Function2<B, A>> top; |
| 745 Function2<Function2<B, A>, Function2<B, A>> right; | 784 Function2<Function2<B, A>, Function2<B, A>> right; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 763 right = right; | 802 right = right; |
| 764 right = bot; | 803 right = bot; |
| 765 | 804 |
| 766 bot = /*warning:DOWN_CAST_COMPOSITE*/top; | 805 bot = /*warning:DOWN_CAST_COMPOSITE*/top; |
| 767 bot = /*warning:DOWN_CAST_COMPOSITE*/left; | 806 bot = /*warning:DOWN_CAST_COMPOSITE*/left; |
| 768 bot = /*warning:DOWN_CAST_COMPOSITE*/right; | 807 bot = /*warning:DOWN_CAST_COMPOSITE*/right; |
| 769 bot = bot; | 808 bot = bot; |
| 770 } | 809 } |
| 771 } | 810 } |
| 772 ''' | 811 ''' |
| 773 }); | 812 }); |
| 774 | 813 |
| 775 testChecker('Function typing and subtyping: named and optional parameters', { | 814 testChecker( |
| 776 '/main.dart': ''' | 815 'Function typing and subtyping: named and optional parameters', |
| 816 () => { | |
| 817 '/main.dart': ''' | |
| 777 | 818 |
| 778 class A {} | 819 class A {} |
| 779 | 820 |
| 780 typedef A FR(A x); | 821 typedef A FR(A x); |
| 781 typedef A FO([A x]); | 822 typedef A FO([A x]); |
| 782 typedef A FN({A x}); | 823 typedef A FN({A x}); |
| 783 typedef A FRR(A x, A y); | 824 typedef A FRR(A x, A y); |
| 784 typedef A FRO(A x, [A y]); | 825 typedef A FRO(A x, [A y]); |
| 785 typedef A FRN(A x, {A n}); | 826 typedef A FRN(A x, {A n}); |
| 786 typedef A FOO([A x, A y]); | 827 typedef A FOO([A x, A y]); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 nnn = /*severe:STATIC_TYPE_ERROR*/o; | 923 nnn = /*severe:STATIC_TYPE_ERROR*/o; |
| 883 nnn = /*warning:DOWN_CAST_COMPOSITE*/n; | 924 nnn = /*warning:DOWN_CAST_COMPOSITE*/n; |
| 884 nnn = /*severe:STATIC_TYPE_ERROR*/rr; | 925 nnn = /*severe:STATIC_TYPE_ERROR*/rr; |
| 885 nnn = /*severe:STATIC_TYPE_ERROR*/ro; | 926 nnn = /*severe:STATIC_TYPE_ERROR*/ro; |
| 886 nnn = /*severe:STATIC_TYPE_ERROR*/rn; | 927 nnn = /*severe:STATIC_TYPE_ERROR*/rn; |
| 887 nnn = /*severe:STATIC_TYPE_ERROR*/oo; | 928 nnn = /*severe:STATIC_TYPE_ERROR*/oo; |
| 888 nnn = /*warning:DOWN_CAST_COMPOSITE*/nn; | 929 nnn = /*warning:DOWN_CAST_COMPOSITE*/nn; |
| 889 nnn = nnn; | 930 nnn = nnn; |
| 890 } | 931 } |
| 891 ''' | 932 ''' |
| 892 }); | 933 }); |
| 893 | 934 |
| 894 testChecker('Function subtyping: objects with call methods', { | 935 testChecker( |
| 895 '/main.dart': ''' | 936 'Function subtyping: objects with call methods', |
| 937 () => { | |
| 938 '/main.dart': ''' | |
| 896 | 939 |
| 897 typedef int I2I(int x); | 940 typedef int I2I(int x); |
| 898 typedef num N2N(num x); | 941 typedef num N2N(num x); |
| 899 class A { | 942 class A { |
| 900 int call(int x) => x; | 943 int call(int x) => x; |
| 901 } | 944 } |
| 902 class B { | 945 class B { |
| 903 num call(num x) => x; | 946 num call(num x) => x; |
| 904 } | 947 } |
| 905 int i2i(int x) => x; | 948 int i2i(int x) => x; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 Function f; | 988 Function f; |
| 946 f = new A(); | 989 f = new A(); |
| 947 f = new B(); | 990 f = new B(); |
| 948 f = i2i; | 991 f = i2i; |
| 949 f = n2n; | 992 f = n2n; |
| 950 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; | 993 f = /*info:DOWN_CAST_IMPLICIT*/i2i as Object; |
| 951 f = (n2n as Function); | 994 f = (n2n as Function); |
| 952 } | 995 } |
| 953 } | 996 } |
| 954 ''' | 997 ''' |
| 955 }); | 998 }); |
| 956 | 999 |
| 957 testChecker('Function typing and subtyping: void', { | 1000 testChecker( |
| 958 '/main.dart': ''' | 1001 'Function typing and subtyping: void', |
| 1002 () => { | |
| 1003 '/main.dart': ''' | |
| 959 | 1004 |
| 960 class A { | 1005 class A { |
| 961 void bar() => null; | 1006 void bar() => null; |
| 962 void foo() => bar; // allowed | 1007 void foo() => bar; // allowed |
| 963 } | 1008 } |
| 964 ''' | 1009 ''' |
| 965 }); | 1010 }); |
| 966 | 1011 |
| 967 testChecker('Relaxed casts', { | 1012 testChecker( |
| 968 '/main.dart': ''' | 1013 'Relaxed casts', |
| 1014 () => { | |
| 1015 '/main.dart': ''' | |
| 969 | 1016 |
| 970 class A {} | 1017 class A {} |
| 971 | 1018 |
| 972 class L<T> {} | 1019 class L<T> {} |
| 973 class M<T> extends L<T> {} | 1020 class M<T> extends L<T> {} |
| 974 // L<dynamic|Object> | 1021 // L<dynamic|Object> |
| 975 // / \ | 1022 // / \ |
| 976 // M<dynamic|Object> L<A> | 1023 // M<dynamic|Object> L<A> |
| 977 // \ / | 1024 // \ / |
| 978 // M<A> | 1025 // M<A> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1033 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs; | 1080 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/mOfDs; |
| 1034 mOfAs = /*info:DOWN_CAST_IMPLICIT*/mOfOs; | 1081 mOfAs = /*info:DOWN_CAST_IMPLICIT*/mOfOs; |
| 1035 mOfAs = mOfAs; | 1082 mOfAs = mOfAs; |
| 1036 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs; | 1083 mOfAs = /*warning:DOWN_CAST_COMPOSITE*/lOfDs; |
| 1037 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; | 1084 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfOs; |
| 1038 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfAs; | 1085 mOfAs = /*info:DOWN_CAST_IMPLICIT*/lOfAs; |
| 1039 } | 1086 } |
| 1040 | 1087 |
| 1041 } | 1088 } |
| 1042 ''' | 1089 ''' |
| 1043 }); | 1090 }); |
| 1044 | 1091 |
| 1045 testChecker('Type checking literals', { | 1092 testChecker( |
| 1046 '/main.dart': ''' | 1093 'Type checking literals', |
| 1094 () => { | |
| 1095 '/main.dart': ''' | |
| 1047 test() { | 1096 test() { |
| 1048 num n = 3; | 1097 num n = 3; |
| 1049 int i = 3; | 1098 int i = 3; |
| 1050 String s = "hello"; | 1099 String s = "hello"; |
| 1051 { | 1100 { |
| 1052 List<int> l = <int>[i]; | 1101 List<int> l = <int>[i]; |
| 1053 l = <int>[/*severe:STATIC_TYPE_ERROR*/s]; | 1102 l = <int>[/*severe:STATIC_TYPE_ERROR*/s]; |
| 1054 l = <int>[/*info:DOWN_CAST_IMPLICIT*/n]; | 1103 l = <int>[/*info:DOWN_CAST_IMPLICIT*/n]; |
| 1055 l = <int>[i, /*info:DOWN_CAST_IMPLICIT*/n, /*severe:STATIC_TYPE_E RROR*/s]; | 1104 l = <int>[i, /*info:DOWN_CAST_IMPLICIT*/n, /*severe:STATIC_TYPE_E RROR*/s]; |
| 1056 } | 1105 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1076 m = {s: n}; | 1125 m = {s: n}; |
| 1077 m = {s: i, | 1126 m = {s: i, |
| 1078 s: n, | 1127 s: n, |
| 1079 s: s}; | 1128 s: s}; |
| 1080 m = {i: s, | 1129 m = {i: s, |
| 1081 n: s, | 1130 n: s, |
| 1082 s: s}; | 1131 s: s}; |
| 1083 } | 1132 } |
| 1084 } | 1133 } |
| 1085 ''' | 1134 ''' |
| 1086 }); | 1135 }); |
| 1087 | 1136 |
| 1088 testChecker('casts in constant contexts', { | 1137 testChecker( |
| 1089 '/main.dart': ''' | 1138 'casts in constant contexts', |
| 1139 () => { | |
| 1140 '/main.dart': ''' | |
| 1090 class A { | 1141 class A { |
| 1091 static const num n = 3.0; | 1142 static const num n = 3.0; |
| 1092 static const int i = /*info:ASSIGNMENT_CAST*/n; | 1143 static const int i = /*info:ASSIGNMENT_CAST*/n; |
| 1093 final int fi; | 1144 final int fi; |
| 1094 const A(num a) : this.fi = /*info:DOWN_CAST_IMPLICIT*/a; | 1145 const A(num a) : this.fi = /*info:DOWN_CAST_IMPLICIT*/a; |
| 1095 } | 1146 } |
| 1096 class B extends A { | 1147 class B extends A { |
| 1097 const B(Object a) : super(/*info:DOWN_CAST_IMPLICIT*/a); | 1148 const B(Object a) : super(/*info:DOWN_CAST_IMPLICIT*/a); |
| 1098 } | 1149 } |
| 1099 void foo(Object o) { | 1150 void foo(Object o) { |
| 1100 var a = const A(/*info:DOWN_CAST_IMPLICIT*/o); | 1151 var a = const A(/*info:DOWN_CAST_IMPLICIT*/o); |
| 1101 } | 1152 } |
| 1102 ''' | 1153 ''' |
| 1103 }); | 1154 }); |
| 1104 | 1155 |
| 1105 testChecker('casts in conditionals', { | 1156 testChecker( |
| 1106 '/main.dart': ''' | 1157 'casts in conditionals', |
| 1158 () => { | |
| 1159 '/main.dart': ''' | |
| 1107 main() { | 1160 main() { |
| 1108 bool b = true; | 1161 bool b = true; |
| 1109 num x = b ? 1 : 2.3; | 1162 num x = b ? 1 : 2.3; |
| 1110 int y = /*info:ASSIGNMENT_CAST*/b ? 1 : 2.3; | 1163 int y = /*info:ASSIGNMENT_CAST*/b ? 1 : 2.3; |
| 1111 String z = !b ? "hello" : null; | 1164 String z = !b ? "hello" : null; |
| 1112 z = b ? null : "hello"; | 1165 z = b ? null : "hello"; |
| 1113 } | 1166 } |
| 1114 ''' | 1167 ''' |
| 1115 }); | 1168 }); |
| 1116 | 1169 |
| 1117 // This is a regression test for https://github.com/dart-lang/sdk/issues/25071 | 1170 // This is a regression test for https://github.com/dart-lang/sdk/issues/25071 |
| 1118 testChecker('unbound redirecting constructor', { | 1171 testChecker( |
| 1119 '/main.dart': ''' | 1172 'unbound redirecting constructor', |
| 1173 () => { | |
| 1174 '/main.dart': ''' | |
| 1120 class Foo { | 1175 class Foo { |
| 1121 Foo() : this.init(); | 1176 Foo() : this.init(); |
| 1122 } | 1177 } |
| 1123 ''' | 1178 ''' |
| 1124 }); | 1179 }); |
| 1125 | 1180 |
| 1126 testChecker('redirecting constructor', { | 1181 testChecker( |
| 1127 '/main.dart': ''' | 1182 'redirecting constructor', |
| 1183 () => { | |
| 1184 '/main.dart': ''' | |
| 1128 class A { | 1185 class A { |
| 1129 A(A x) {} | 1186 A(A x) {} |
| 1130 A.two() : this(/*severe:STATIC_TYPE_ERROR*/3); | 1187 A.two() : this(/*severe:STATIC_TYPE_ERROR*/3); |
| 1131 } | 1188 } |
| 1132 ''' | 1189 ''' |
| 1133 }); | 1190 }); |
| 1134 | 1191 |
| 1135 testChecker('super constructor', { | 1192 testChecker( |
| 1136 '/main.dart': ''' | 1193 'super constructor', |
| 1194 () => { | |
| 1195 '/main.dart': ''' | |
| 1137 class A { A(A x) {} } | 1196 class A { A(A x) {} } |
| 1138 class B extends A { | 1197 class B extends A { |
| 1139 B() : super(/*severe:STATIC_TYPE_ERROR*/3); | 1198 B() : super(/*severe:STATIC_TYPE_ERROR*/3); |
| 1140 } | 1199 } |
| 1141 ''' | 1200 ''' |
| 1142 }); | 1201 }); |
| 1143 | 1202 |
| 1144 testChecker('factory constructor downcast', { | 1203 testChecker( |
| 1145 '/main.dart': r''' | 1204 'factory constructor downcast', |
| 1205 () => { | |
| 1206 '/main.dart': r''' | |
| 1146 class Animal { | 1207 class Animal { |
| 1147 Animal(); | 1208 Animal(); |
| 1148 factory Animal.cat() => return new Cat(); | 1209 factory Animal.cat() => return new Cat(); |
| 1149 } | 1210 } |
| 1150 | 1211 |
| 1151 class Cat extends Animal {} | 1212 class Cat extends Animal {} |
| 1152 | 1213 |
| 1153 void main() { | 1214 void main() { |
| 1154 Cat c = /*info:ASSIGNMENT_CAST*/new Animal.cat(); | 1215 Cat c = /*info:ASSIGNMENT_CAST*/new Animal.cat(); |
| 1155 c = /*severe:STATIC_TYPE_ERROR*/new Animal(); | 1216 c = /*severe:STATIC_TYPE_ERROR*/new Animal(); |
| 1156 }''' | 1217 }''' |
| 1157 }); | 1218 }); |
| 1158 | 1219 |
| 1159 testChecker('field/field override', { | 1220 testChecker( |
| 1160 '/main.dart': ''' | 1221 'field/field override', |
| 1222 () => { | |
| 1223 '/main.dart': ''' | |
| 1161 class A {} | 1224 class A {} |
| 1162 class B extends A {} | 1225 class B extends A {} |
| 1163 class C extends B {} | 1226 class C extends B {} |
| 1164 | 1227 |
| 1165 class Base { | 1228 class Base { |
| 1166 B f1; | 1229 B f1; |
| 1167 B f2; | 1230 B f2; |
| 1168 B f3; | 1231 B f3; |
| 1169 B f4; | 1232 B f4; |
| 1170 } | 1233 } |
| 1171 | 1234 |
| 1172 class Child extends Base { | 1235 class Child extends Base { |
| 1173 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A f1 ; // invalid for getter | 1236 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A f1 ; // invalid for getter |
| 1174 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/C f2 ; // invalid for setter | 1237 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/C f2 ; // invalid for setter |
| 1175 /*severe:INVALID_FIELD_OVERRIDE*/var f3; | 1238 /*severe:INVALID_FIELD_OVERRIDE*/var f3; |
| 1176 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sever e:INVALID_METHOD_OVERRIDE*/dynamic f4; | 1239 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE,sever e:INVALID_METHOD_OVERRIDE*/dynamic f4; |
| 1177 } | 1240 } |
| 1178 | 1241 |
| 1179 class Child2 implements Base { | 1242 class Child2 implements Base { |
| 1180 /*severe:INVALID_METHOD_OVERRIDE*/A f1; // invalid for getter | 1243 /*severe:INVALID_METHOD_OVERRIDE*/A f1; // invalid for getter |
| 1181 /*severe:INVALID_METHOD_OVERRIDE*/C f2; // invalid for setter | 1244 /*severe:INVALID_METHOD_OVERRIDE*/C f2; // invalid for setter |
| 1182 var f3; | 1245 var f3; |
| 1183 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyn amic f4; | 1246 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyn amic f4; |
| 1184 } | 1247 } |
| 1185 ''' | 1248 ''' |
| 1186 }); | 1249 }); |
| 1187 | 1250 |
| 1188 testChecker('private override', { | 1251 testChecker( |
| 1189 '/helper.dart': ''' | 1252 'private override', |
| 1253 () => { | |
| 1254 '/helper.dart': ''' | |
| 1190 import 'main.dart' as main; | 1255 import 'main.dart' as main; |
| 1191 | 1256 |
| 1192 class Base { | 1257 class Base { |
| 1193 var f1; | 1258 var f1; |
| 1194 var _f2; | 1259 var _f2; |
| 1195 var _f3; | 1260 var _f3; |
| 1196 get _f4 => null; | 1261 get _f4 => null; |
| 1197 | 1262 |
| 1198 int _m1(); | 1263 int _m1(); |
| 1199 } | 1264 } |
| 1200 | 1265 |
| 1201 class GrandChild extends main.Child { | 1266 class GrandChild extends main.Child { |
| 1202 /*severe:INVALID_FIELD_OVERRIDE*/var _f2; | 1267 /*severe:INVALID_FIELD_OVERRIDE*/var _f2; |
| 1203 /*severe:INVALID_FIELD_OVERRIDE*/var _f3; | 1268 /*severe:INVALID_FIELD_OVERRIDE*/var _f3; |
| 1204 var _f4; | 1269 var _f4; |
| 1205 | 1270 |
| 1206 /*severe:INVALID_METHOD_OVERRIDE*/String _m1(); | 1271 /*severe:INVALID_METHOD_OVERRIDE*/String _m1(); |
| 1207 } | 1272 } |
| 1208 ''', | 1273 ''', |
| 1209 '/main.dart': ''' | 1274 '/main.dart': ''' |
| 1210 import 'helper.dart' as helper; | 1275 import 'helper.dart' as helper; |
| 1211 | 1276 |
| 1212 class Child extends helper.Base { | 1277 class Child extends helper.Base { |
| 1213 /*severe:INVALID_FIELD_OVERRIDE*/var f1; | 1278 /*severe:INVALID_FIELD_OVERRIDE*/var f1; |
| 1214 var _f2; | 1279 var _f2; |
| 1215 var _f4; | 1280 var _f4; |
| 1216 | 1281 |
| 1217 String _m1(); | 1282 String _m1(); |
| 1218 } | 1283 } |
| 1219 ''' | 1284 ''' |
| 1220 }); | 1285 }); |
| 1221 | 1286 |
| 1222 testChecker('getter/getter override', { | 1287 testChecker( |
| 1223 '/main.dart': ''' | 1288 'getter/getter override', |
| 1289 () => { | |
| 1290 '/main.dart': ''' | |
| 1224 class A {} | 1291 class A {} |
| 1225 class B extends A {} | 1292 class B extends A {} |
| 1226 class C extends B {} | 1293 class C extends B {} |
| 1227 | 1294 |
| 1228 abstract class Base { | 1295 abstract class Base { |
| 1229 B get f1; | 1296 B get f1; |
| 1230 B get f2; | 1297 B get f2; |
| 1231 B get f3; | 1298 B get f3; |
| 1232 B get f4; | 1299 B get f4; |
| 1233 } | 1300 } |
| 1234 | 1301 |
| 1235 class Child extends Base { | 1302 class Child extends Base { |
| 1236 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; | 1303 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; |
| 1237 C get f2 => null; | 1304 C get f2 => null; |
| 1238 get f3 => null; | 1305 get f3 => null; |
| 1239 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; | 1306 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; |
| 1240 } | 1307 } |
| 1241 ''' | 1308 ''' |
| 1242 }); | 1309 }); |
| 1243 | 1310 |
| 1244 testChecker('field/getter override', { | 1311 testChecker( |
| 1245 '/main.dart': ''' | 1312 'field/getter override', |
| 1313 () => { | |
| 1314 '/main.dart': ''' | |
| 1246 class A {} | 1315 class A {} |
| 1247 class B extends A {} | 1316 class B extends A {} |
| 1248 class C extends B {} | 1317 class C extends B {} |
| 1249 | 1318 |
| 1250 abstract class Base { | 1319 abstract class Base { |
| 1251 B f1; | 1320 B f1; |
| 1252 B f2; | 1321 B f2; |
| 1253 B f3; | 1322 B f3; |
| 1254 B f4; | 1323 B f4; |
| 1255 } | 1324 } |
| 1256 | 1325 |
| 1257 class Child extends Base { | 1326 class Child extends Base { |
| 1258 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A ge t f1 => null; | 1327 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/A ge t f1 => null; |
| 1259 /*severe:INVALID_FIELD_OVERRIDE*/C get f2 => null; | 1328 /*severe:INVALID_FIELD_OVERRIDE*/C get f2 => null; |
| 1260 /*severe:INVALID_FIELD_OVERRIDE*/get f3 => null; | 1329 /*severe:INVALID_FIELD_OVERRIDE*/get f3 => null; |
| 1261 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyna mic get f4 => null; | 1330 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/dyna mic get f4 => null; |
| 1262 } | 1331 } |
| 1263 | 1332 |
| 1264 class Child2 implements Base { | 1333 class Child2 implements Base { |
| 1265 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; | 1334 /*severe:INVALID_METHOD_OVERRIDE*/A get f1 => null; |
| 1266 C get f2 => null; | 1335 C get f2 => null; |
| 1267 get f3 => null; | 1336 get f3 => null; |
| 1268 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; | 1337 /*severe:INVALID_METHOD_OVERRIDE*/dynamic get f4 => null; |
| 1269 } | 1338 } |
| 1270 ''' | 1339 ''' |
| 1271 }); | 1340 }); |
| 1272 | 1341 |
| 1273 testChecker('setter/setter override', { | 1342 testChecker( |
| 1274 '/main.dart': ''' | 1343 'setter/setter override', |
| 1344 () => { | |
| 1345 '/main.dart': ''' | |
| 1275 class A {} | 1346 class A {} |
| 1276 class B extends A {} | 1347 class B extends A {} |
| 1277 class C extends B {} | 1348 class C extends B {} |
| 1278 | 1349 |
| 1279 abstract class Base { | 1350 abstract class Base { |
| 1280 void set f1(B value); | 1351 void set f1(B value); |
| 1281 void set f2(B value); | 1352 void set f2(B value); |
| 1282 void set f3(B value); | 1353 void set f3(B value); |
| 1283 void set f4(B value); | 1354 void set f4(B value); |
| 1284 void set f5(B value); | 1355 void set f5(B value); |
| 1285 } | 1356 } |
| 1286 | 1357 |
| 1287 class Child extends Base { | 1358 class Child extends Base { |
| 1288 void set f1(A value) {} | 1359 void set f1(A value) {} |
| 1289 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {} | 1360 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {} |
| 1290 void set f3(value) {} | 1361 void set f3(value) {} |
| 1291 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {} | 1362 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {} |
| 1292 set f5(B value) {} | 1363 set f5(B value) {} |
| 1293 } | 1364 } |
| 1294 ''' | 1365 ''' |
| 1295 }); | 1366 }); |
| 1296 | 1367 |
| 1297 testChecker('field/setter override', { | 1368 testChecker( |
| 1298 '/main.dart': ''' | 1369 'field/setter override', |
| 1370 () => { | |
| 1371 '/main.dart': ''' | |
| 1299 class A {} | 1372 class A {} |
| 1300 class B extends A {} | 1373 class B extends A {} |
| 1301 class C extends B {} | 1374 class C extends B {} |
| 1302 | 1375 |
| 1303 class Base { | 1376 class Base { |
| 1304 B f1; | 1377 B f1; |
| 1305 B f2; | 1378 B f2; |
| 1306 B f3; | 1379 B f3; |
| 1307 B f4; | 1380 B f4; |
| 1308 B f5; | 1381 B f5; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1329 B get f4 => null; | 1402 B get f4 => null; |
| 1330 B get f5 => null; | 1403 B get f5 => null; |
| 1331 | 1404 |
| 1332 void set f1(A value) {} | 1405 void set f1(A value) {} |
| 1333 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {} | 1406 /*severe:INVALID_METHOD_OVERRIDE*/void set f2(C value) {} |
| 1334 void set f3(value) {} | 1407 void set f3(value) {} |
| 1335 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {} | 1408 /*severe:INVALID_METHOD_OVERRIDE*/void set f4(dynamic value) {} |
| 1336 set f5(B value) {} | 1409 set f5(B value) {} |
| 1337 } | 1410 } |
| 1338 ''' | 1411 ''' |
| 1339 }); | 1412 }); |
| 1340 | 1413 |
| 1341 testChecker('method override', { | 1414 testChecker( |
| 1342 '/main.dart': ''' | 1415 'method override', |
| 1416 () => { | |
| 1417 '/main.dart': ''' | |
| 1343 class A {} | 1418 class A {} |
| 1344 class B extends A {} | 1419 class B extends A {} |
| 1345 class C extends B {} | 1420 class C extends B {} |
| 1346 | 1421 |
| 1347 class Base { | 1422 class Base { |
| 1348 B m1(B a); | 1423 B m1(B a); |
| 1349 B m2(B a); | 1424 B m2(B a); |
| 1350 B m3(B a); | 1425 B m3(B a); |
| 1351 B m4(B a); | 1426 B m4(B a); |
| 1352 B m5(B a); | 1427 B m5(B a); |
| 1353 B m6(B a); | 1428 B m6(B a); |
| 1354 } | 1429 } |
| 1355 | 1430 |
| 1356 class Child extends Base { | 1431 class Child extends Base { |
| 1357 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {} | 1432 /*severe:INVALID_METHOD_OVERRIDE*/A m1(A value) {} |
| 1358 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {} | 1433 /*severe:INVALID_METHOD_OVERRIDE*/C m2(C value) {} |
| 1359 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) {} | 1434 /*severe:INVALID_METHOD_OVERRIDE*/A m3(C value) {} |
| 1360 C m4(A value) {} | 1435 C m4(A value) {} |
| 1361 m5(value) {} | 1436 m5(value) {} |
| 1362 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {} | 1437 /*severe:INVALID_METHOD_OVERRIDE*/dynamic m6(dynamic value) {} |
| 1363 } | 1438 } |
| 1364 ''' | 1439 ''' |
| 1365 }); | 1440 }); |
| 1366 | 1441 |
| 1367 testChecker('generic class method override', { | 1442 testChecker( |
| 1368 '/main.dart': ''' | 1443 'generic class method override', |
| 1444 () => { | |
| 1445 '/main.dart': ''' | |
| 1369 class A {} | 1446 class A {} |
| 1370 class B extends A {} | 1447 class B extends A {} |
| 1371 | 1448 |
| 1372 class Base<T extends B> { | 1449 class Base<T extends B> { |
| 1373 T foo() => null; | 1450 T foo() => null; |
| 1374 } | 1451 } |
| 1375 | 1452 |
| 1376 class Derived<S extends A> extends Base<B> { | 1453 class Derived<S extends A> extends Base<B> { |
| 1377 /*severe:INVALID_METHOD_OVERRIDE*/S foo() => null; | 1454 /*severe:INVALID_METHOD_OVERRIDE*/S foo() => null; |
| 1378 } | 1455 } |
| 1379 | 1456 |
| 1380 class Derived2<S extends B> extends Base<B> { | 1457 class Derived2<S extends B> extends Base<B> { |
| 1381 S foo() => null; | 1458 S foo() => null; |
| 1382 } | 1459 } |
| 1383 ''' | 1460 ''' |
| 1384 }); | 1461 }); |
| 1385 | 1462 |
| 1386 testChecker('generic method override', { | 1463 testChecker( |
| 1387 '/main.dart': ''' | 1464 'generic method override', |
| 1465 () => { | |
| 1466 '/main.dart': ''' | |
| 1388 class Future<T> { | 1467 class Future<T> { |
| 1389 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; | 1468 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; |
| 1390 } | 1469 } |
| 1391 | 1470 |
| 1392 class DerivedFuture<T> extends Future<T> { | 1471 class DerivedFuture<T> extends Future<T> { |
| 1393 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; | 1472 /*=S*/ then/*<S>*/(/*=S*/ onValue(T t)) => null; |
| 1394 } | 1473 } |
| 1395 | 1474 |
| 1396 class DerivedFuture2<A> extends Future<A> { | 1475 class DerivedFuture2<A> extends Future<A> { |
| 1397 /*=B*/ then/*<B>*/(/*=B*/ onValue(A a)) => null; | 1476 /*=B*/ then/*<B>*/(/*=B*/ onValue(A a)) => null; |
| 1398 } | 1477 } |
| 1399 | 1478 |
| 1400 class DerivedFuture3<T> extends Future<T> { | 1479 class DerivedFuture3<T> extends Future<T> { |
| 1401 /*=S*/ then/*<S>*/(Object onValue(T t)) => null; | 1480 /*=S*/ then/*<S>*/(Object onValue(T t)) => null; |
| 1402 } | 1481 } |
| 1403 | 1482 |
| 1404 class DerivedFuture4<A> extends Future<A> { | 1483 class DerivedFuture4<A> extends Future<A> { |
| 1405 /*=B*/ then/*<B>*/(Object onValue(A a)) => null; | 1484 /*=B*/ then/*<B>*/(Object onValue(A a)) => null; |
| 1406 } | 1485 } |
| 1407 ''' | 1486 ''' |
| 1408 }); | 1487 }); |
| 1409 | 1488 |
| 1410 testChecker('generic function wrong number of arguments', { | 1489 testChecker( |
| 1411 '/main.dart': r''' | 1490 'generic function wrong number of arguments', |
| 1491 () => { | |
| 1492 '/main.dart': r''' | |
| 1412 /*=T*/ foo/*<T>*/(/*=T*/ x, /*=T*/ y) => x; | 1493 /*=T*/ foo/*<T>*/(/*=T*/ x, /*=T*/ y) => x; |
| 1413 /*=T*/ bar/*<T>*/({/*=T*/ x, /*=T*/ y}) => x; | 1494 /*=T*/ bar/*<T>*/({/*=T*/ x, /*=T*/ y}) => x; |
| 1414 | 1495 |
| 1415 main() { | 1496 main() { |
| 1416 // resolving thses shouldn't crash. | 1497 // resolving thses shouldn't crash. |
| 1417 foo(1, 2, 3); | 1498 foo(1, 2, 3); |
| 1418 String x = foo('1', '2', '3'); | 1499 String x = foo('1', '2', '3'); |
| 1419 foo(1); | 1500 foo(1); |
| 1420 String x = foo('1'); | 1501 String x = foo('1'); |
| 1421 x = /*severe:STATIC_TYPE_ERROR*/foo(1, 2, 3); | 1502 x = /*severe:STATIC_TYPE_ERROR*/foo(1, 2, 3); |
| 1422 x = /*severe:STATIC_TYPE_ERROR*/foo(1); | 1503 x = /*severe:STATIC_TYPE_ERROR*/foo(1); |
| 1423 | 1504 |
| 1424 // named arguments | 1505 // named arguments |
| 1425 bar(y: 1, x: 2, z: 3); | 1506 bar(y: 1, x: 2, z: 3); |
| 1426 String x = bar(z: '1', x: '2', y: '3'); | 1507 String x = bar(z: '1', x: '2', y: '3'); |
| 1427 bar(y: 1); | 1508 bar(y: 1); |
| 1428 x = bar(x: '1', z: 42); | 1509 x = bar(x: '1', z: 42); |
| 1429 x = /*severe:STATIC_TYPE_ERROR*/bar(y: 1, x: 2, z: 3); | 1510 x = /*severe:STATIC_TYPE_ERROR*/bar(y: 1, x: 2, z: 3); |
| 1430 x = /*severe:STATIC_TYPE_ERROR*/bar(x: 1); | 1511 x = /*severe:STATIC_TYPE_ERROR*/bar(x: 1); |
| 1431 } | 1512 } |
| 1432 ''' | 1513 ''' |
| 1433 }); | 1514 }); |
| 1434 | 1515 |
| 1435 testChecker('type promotion from dynamic', { | 1516 testChecker( |
| 1436 '/main.dart': r''' | 1517 'type promotion from dynamic', |
| 1518 () => { | |
| 1519 '/main.dart': r''' | |
| 1437 f() { | 1520 f() { |
| 1438 dynamic x; | 1521 dynamic x; |
| 1439 if (x is int) { | 1522 if (x is int) { |
| 1440 int y = x; | 1523 int y = x; |
| 1441 String z = /*severe:STATIC_TYPE_ERROR*/x; | 1524 String z = /*severe:STATIC_TYPE_ERROR*/x; |
| 1442 } | 1525 } |
| 1443 } | 1526 } |
| 1444 g() { | 1527 g() { |
| 1445 Object x; | 1528 Object x; |
| 1446 if (x is int) { | 1529 if (x is int) { |
| 1447 int y = x; | 1530 int y = x; |
| 1448 String z = /*severe:STATIC_TYPE_ERROR*/x; | 1531 String z = /*severe:STATIC_TYPE_ERROR*/x; |
| 1449 } | 1532 } |
| 1450 } | 1533 } |
| 1451 ''' | 1534 ''' |
| 1452 }); | 1535 }); |
| 1453 | 1536 |
| 1454 testChecker('unary operators', { | 1537 testChecker( |
| 1455 '/main.dart': ''' | 1538 'unary operators', |
| 1539 () => { | |
| 1540 '/main.dart': ''' | |
| 1456 class A { | 1541 class A { |
| 1457 A operator ~() {} | 1542 A operator ~() {} |
| 1458 A operator +(int x) {} | 1543 A operator +(int x) {} |
| 1459 A operator -(int x) {} | 1544 A operator -(int x) {} |
| 1460 A operator -() {} | 1545 A operator -() {} |
| 1461 } | 1546 } |
| 1462 | 1547 |
| 1463 foo() => new A(); | 1548 foo() => new A(); |
| 1464 | 1549 |
| 1465 test() { | 1550 test() { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1478 ++a; | 1563 ++a; |
| 1479 --a; | 1564 --a; |
| 1480 (/*info:DYNAMIC_INVOKE*/++d); | 1565 (/*info:DYNAMIC_INVOKE*/++d); |
| 1481 (/*info:DYNAMIC_INVOKE*/--d); | 1566 (/*info:DYNAMIC_INVOKE*/--d); |
| 1482 | 1567 |
| 1483 a++; | 1568 a++; |
| 1484 a--; | 1569 a--; |
| 1485 (/*info:DYNAMIC_INVOKE*/d++); | 1570 (/*info:DYNAMIC_INVOKE*/d++); |
| 1486 (/*info:DYNAMIC_INVOKE*/d--); | 1571 (/*info:DYNAMIC_INVOKE*/d--); |
| 1487 }''' | 1572 }''' |
| 1488 }); | 1573 }); |
| 1489 | 1574 |
| 1490 testChecker('binary and index operators', { | 1575 testChecker( |
| 1491 '/main.dart': ''' | 1576 'binary and index operators', |
| 1577 () => { | |
| 1578 '/main.dart': ''' | |
| 1492 class A { | 1579 class A { |
| 1493 A operator *(B b) {} | 1580 A operator *(B b) {} |
| 1494 A operator /(B b) {} | 1581 A operator /(B b) {} |
| 1495 A operator ~/(B b) {} | 1582 A operator ~/(B b) {} |
| 1496 A operator %(B b) {} | 1583 A operator %(B b) {} |
| 1497 A operator +(B b) {} | 1584 A operator +(B b) {} |
| 1498 A operator -(B b) {} | 1585 A operator -(B b) {} |
| 1499 A operator <<(B b) {} | 1586 A operator <<(B b) {} |
| 1500 A operator >>(B b) {} | 1587 A operator >>(B b) {} |
| 1501 A operator &(B b) {} | 1588 A operator &(B b) {} |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1543 p = (/*info:DYNAMIC_CAST*/c) && /*info:DYNAMIC_CAST*/c; | 1630 p = (/*info:DYNAMIC_CAST*/c) && /*info:DYNAMIC_CAST*/c; |
| 1544 p = (/*severe:STATIC_TYPE_ERROR*/y) && p; | 1631 p = (/*severe:STATIC_TYPE_ERROR*/y) && p; |
| 1545 p = c == y; | 1632 p = c == y; |
| 1546 | 1633 |
| 1547 a = a[b]; | 1634 a = a[b]; |
| 1548 a = a[/*info:DYNAMIC_CAST*/c]; | 1635 a = a[/*info:DYNAMIC_CAST*/c]; |
| 1549 c = (/*info:DYNAMIC_INVOKE*/c[b]); | 1636 c = (/*info:DYNAMIC_INVOKE*/c[b]); |
| 1550 a[/*severe:STATIC_TYPE_ERROR*/y]; | 1637 a[/*severe:STATIC_TYPE_ERROR*/y]; |
| 1551 } | 1638 } |
| 1552 ''' | 1639 ''' |
| 1553 }); | 1640 }); |
| 1554 | 1641 |
| 1555 testChecker('null coalescing operator', { | 1642 testChecker( |
| 1556 '/main.dart': ''' | 1643 'null coalescing operator', |
| 1644 () => { | |
| 1645 '/main.dart': ''' | |
| 1557 class A {} | 1646 class A {} |
| 1558 class C<T> {} | 1647 class C<T> {} |
| 1559 main() { | 1648 main() { |
| 1560 A a, b; | 1649 A a, b; |
| 1561 a ??= new A(); | 1650 a ??= new A(); |
| 1562 b = b ?? new A(); | 1651 b = b ?? new A(); |
| 1563 | 1652 |
| 1564 // downwards inference | 1653 // downwards inference |
| 1565 C<int> c, d; | 1654 C<int> c, d; |
| 1566 c ??= /*info:INFERRED_TYPE_ALLOCATION*/new C(); | 1655 c ??= /*info:INFERRED_TYPE_ALLOCATION*/new C(); |
| 1567 d = d ?? /*info:INFERRED_TYPE_ALLOCATION*/new C(); | 1656 d = d ?? /*info:INFERRED_TYPE_ALLOCATION*/new C(); |
| 1568 } | 1657 } |
| 1569 ''' | 1658 ''' |
| 1570 }); | 1659 }); |
| 1571 | 1660 |
| 1572 testChecker('compound assignments', { | 1661 testChecker( |
| 1573 '/main.dart': ''' | 1662 'compound assignments', |
| 1663 () => { | |
| 1664 '/main.dart': ''' | |
| 1574 class A { | 1665 class A { |
| 1575 A operator *(B b) {} | 1666 A operator *(B b) {} |
| 1576 A operator /(B b) {} | 1667 A operator /(B b) {} |
| 1577 A operator ~/(B b) {} | 1668 A operator ~/(B b) {} |
| 1578 A operator %(B b) {} | 1669 A operator %(B b) {} |
| 1579 A operator +(B b) {} | 1670 A operator +(B b) {} |
| 1580 A operator -(B b) {} | 1671 A operator -(B b) {} |
| 1581 A operator <<(B b) {} | 1672 A operator <<(B b) {} |
| 1582 A operator >>(B b) {} | 1673 A operator >>(B b) {} |
| 1583 A operator &(B b) {} | 1674 A operator &(B b) {} |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1642 | 1733 |
| 1643 var d = new D(); | 1734 var d = new D(); |
| 1644 a[b] += d; | 1735 a[b] += d; |
| 1645 a[/*info:DYNAMIC_CAST*/c] += d; | 1736 a[/*info:DYNAMIC_CAST*/c] += d; |
| 1646 a[/*severe:STATIC_TYPE_ERROR*/z] += d; | 1737 a[/*severe:STATIC_TYPE_ERROR*/z] += d; |
| 1647 a[b] += /*info:DYNAMIC_CAST*/c; | 1738 a[b] += /*info:DYNAMIC_CAST*/c; |
| 1648 a[b] += /*severe:STATIC_TYPE_ERROR*/z; | 1739 a[b] += /*severe:STATIC_TYPE_ERROR*/z; |
| 1649 (/*info:DYNAMIC_INVOKE*/(/*info:DYNAMIC_INVOKE*/c[b]) += d); | 1740 (/*info:DYNAMIC_INVOKE*/(/*info:DYNAMIC_INVOKE*/c[b]) += d); |
| 1650 } | 1741 } |
| 1651 ''' | 1742 ''' |
| 1652 }); | 1743 }); |
| 1653 | 1744 |
| 1654 testChecker('super call placement', { | 1745 testChecker( |
| 1655 '/main.dart': ''' | 1746 'super call placement', |
| 1747 () => { | |
| 1748 '/main.dart': ''' | |
| 1656 class Base { | 1749 class Base { |
| 1657 var x; | 1750 var x; |
| 1658 Base() : x = print('Base.1') { print('Base.2'); } | 1751 Base() : x = print('Base.1') { print('Base.2'); } |
| 1659 } | 1752 } |
| 1660 | 1753 |
| 1661 class Derived extends Base { | 1754 class Derived extends Base { |
| 1662 var y, z; | 1755 var y, z; |
| 1663 Derived() | 1756 Derived() |
| 1664 : y = print('Derived.1'), | 1757 : y = print('Derived.1'), |
| 1665 /*severe:INVALID_SUPER_INVOCATION*/super(), | 1758 /*severe:INVALID_SUPER_INVOCATION*/super(), |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1677 print('Valid.3'); | 1770 print('Valid.3'); |
| 1678 } | 1771 } |
| 1679 } | 1772 } |
| 1680 | 1773 |
| 1681 class AlsoValid extends Base { | 1774 class AlsoValid extends Base { |
| 1682 AlsoValid() : super(); | 1775 AlsoValid() : super(); |
| 1683 } | 1776 } |
| 1684 | 1777 |
| 1685 main() => new Derived(); | 1778 main() => new Derived(); |
| 1686 ''' | 1779 ''' |
| 1687 }); | 1780 }); |
| 1688 | 1781 |
| 1689 testChecker('for loop variable', { | 1782 testChecker( |
| 1690 '/main.dart': ''' | 1783 'for loop variable', |
| 1784 () => { | |
| 1785 '/main.dart': ''' | |
| 1691 foo() { | 1786 foo() { |
| 1692 for (int i = 0; i < 10; i++) { | 1787 for (int i = 0; i < 10; i++) { |
| 1693 i = /*severe:STATIC_TYPE_ERROR*/"hi"; | 1788 i = /*severe:STATIC_TYPE_ERROR*/"hi"; |
| 1694 } | 1789 } |
| 1695 } | 1790 } |
| 1696 bar() { | 1791 bar() { |
| 1697 for (var i = 0; i < 10; i++) { | 1792 for (var i = 0; i < 10; i++) { |
| 1698 int j = i + 1; | 1793 int j = i + 1; |
| 1699 } | 1794 } |
| 1700 } | 1795 } |
| 1701 ''' | 1796 ''' |
| 1702 }); | 1797 }); |
| 1703 | 1798 |
| 1704 testChecker('loadLibrary', { | 1799 testChecker( |
| 1705 '/lib1.dart': '''library lib1;''', | 1800 'loadLibrary', |
| 1706 '/main.dart': r''' | 1801 () => { |
| 1802 '/lib1.dart': '''library lib1;''', | |
| 1803 '/main.dart': r''' | |
| 1707 import 'lib1.dart' deferred as lib1; | 1804 import 'lib1.dart' deferred as lib1; |
| 1708 main() { | 1805 main() { |
| 1709 Future f = lib1.loadLibrary(); | 1806 Future f = lib1.loadLibrary(); |
| 1710 }''' | 1807 }''' |
| 1711 }); | 1808 }); |
| 1712 | 1809 |
| 1713 group('invalid overrides', () { | 1810 group('invalid overrides', () { |
| 1714 testChecker('child override', { | 1811 testChecker( |
| 1715 '/main.dart': ''' | 1812 'child override', |
| 1813 () => { | |
| 1814 '/main.dart': ''' | |
| 1716 class A {} | 1815 class A {} |
| 1717 class B {} | 1816 class B {} |
| 1718 | 1817 |
| 1719 class Base { | 1818 class Base { |
| 1720 A f; | 1819 A f; |
| 1721 } | 1820 } |
| 1722 | 1821 |
| 1723 class T1 extends Base { | 1822 class T1 extends Base { |
| 1724 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B get f => null; | 1823 /*severe:INVALID_FIELD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B get f => null; |
| 1725 } | 1824 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1745 } | 1844 } |
| 1746 | 1845 |
| 1747 class T7 implements Base { | 1846 class T7 implements Base { |
| 1748 /*severe:INVALID_METHOD_OVERRIDE*/final B f; | 1847 /*severe:INVALID_METHOD_OVERRIDE*/final B f; |
| 1749 } | 1848 } |
| 1750 class T8 implements Base { | 1849 class T8 implements Base { |
| 1751 // two: one for the getter one for the setter. | 1850 // two: one for the getter one for the setter. |
| 1752 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B f; | 1851 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE*/B f; |
| 1753 } | 1852 } |
| 1754 ''' | 1853 ''' |
| 1755 }); | 1854 }); |
| 1756 | 1855 |
| 1757 testChecker('child override 2', { | 1856 testChecker( |
| 1758 '/main.dart': ''' | 1857 'child override 2', |
| 1858 () => { | |
| 1859 '/main.dart': ''' | |
| 1759 class A {} | 1860 class A {} |
| 1760 class B {} | 1861 class B {} |
| 1761 | 1862 |
| 1762 class Base { | 1863 class Base { |
| 1763 m(A a) {} | 1864 m(A a) {} |
| 1764 } | 1865 } |
| 1765 | 1866 |
| 1766 class Test extends Base { | 1867 class Test extends Base { |
| 1767 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 1868 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1768 } | 1869 } |
| 1769 ''' | 1870 ''' |
| 1770 }); | 1871 }); |
| 1771 testChecker('grandchild override', { | 1872 testChecker( |
| 1772 '/main.dart': ''' | 1873 'grandchild override', |
| 1874 () => { | |
| 1875 '/main.dart': ''' | |
| 1773 class A {} | 1876 class A {} |
| 1774 class B {} | 1877 class B {} |
| 1775 | 1878 |
| 1776 class Grandparent { | 1879 class Grandparent { |
| 1777 m(A a) {} | 1880 m(A a) {} |
| 1778 int x; | 1881 int x; |
| 1779 } | 1882 } |
| 1780 class Parent extends Grandparent { | 1883 class Parent extends Grandparent { |
| 1781 } | 1884 } |
| 1782 | 1885 |
| 1783 class Test extends Parent { | 1886 class Test extends Parent { |
| 1784 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 1887 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1785 /*severe:INVALID_FIELD_OVERRIDE*/int x; | 1888 /*severe:INVALID_FIELD_OVERRIDE*/int x; |
| 1786 } | 1889 } |
| 1787 ''' | 1890 ''' |
| 1788 }); | 1891 }); |
| 1789 | 1892 |
| 1790 testChecker('double override', { | 1893 testChecker( |
| 1791 '/main.dart': ''' | 1894 'double override', |
| 1895 () => { | |
| 1896 '/main.dart': ''' | |
| 1792 class A {} | 1897 class A {} |
| 1793 class B {} | 1898 class B {} |
| 1794 | 1899 |
| 1795 class Grandparent { | 1900 class Grandparent { |
| 1796 m(A a) {} | 1901 m(A a) {} |
| 1797 } | 1902 } |
| 1798 class Parent extends Grandparent { | 1903 class Parent extends Grandparent { |
| 1799 m(A a) {} | 1904 m(A a) {} |
| 1800 } | 1905 } |
| 1801 | 1906 |
| 1802 class Test extends Parent { | 1907 class Test extends Parent { |
| 1803 // Reported only once | 1908 // Reported only once |
| 1804 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 1909 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1805 } | 1910 } |
| 1806 ''' | 1911 ''' |
| 1807 }); | 1912 }); |
| 1808 | 1913 |
| 1809 testChecker('double override 2', { | 1914 testChecker( |
| 1810 '/main.dart': ''' | 1915 'double override 2', |
| 1916 () => { | |
| 1917 '/main.dart': ''' | |
| 1811 class A {} | 1918 class A {} |
| 1812 class B {} | 1919 class B {} |
| 1813 | 1920 |
| 1814 class Grandparent { | 1921 class Grandparent { |
| 1815 m(A a) {} | 1922 m(A a) {} |
| 1816 } | 1923 } |
| 1817 class Parent extends Grandparent { | 1924 class Parent extends Grandparent { |
| 1818 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 1925 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1819 } | 1926 } |
| 1820 | 1927 |
| 1821 class Test extends Parent { | 1928 class Test extends Parent { |
| 1822 m(B a) {} | 1929 m(B a) {} |
| 1823 } | 1930 } |
| 1824 ''' | 1931 ''' |
| 1825 }); | 1932 }); |
| 1826 | 1933 |
| 1827 testChecker('mixin override to base', { | 1934 testChecker( |
| 1828 '/main.dart': ''' | 1935 'mixin override to base', |
| 1936 () => { | |
| 1937 '/main.dart': ''' | |
| 1829 class A {} | 1938 class A {} |
| 1830 class B {} | 1939 class B {} |
| 1831 | 1940 |
| 1832 class Base { | 1941 class Base { |
| 1833 m(A a) {} | 1942 m(A a) {} |
| 1834 int x; | 1943 int x; |
| 1835 } | 1944 } |
| 1836 | 1945 |
| 1837 class M1 { | 1946 class M1 { |
| 1838 m(B a) {} | 1947 m(B a) {} |
| 1839 } | 1948 } |
| 1840 | 1949 |
| 1841 class M2 { | 1950 class M2 { |
| 1842 int x; | 1951 int x; |
| 1843 } | 1952 } |
| 1844 | 1953 |
| 1845 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1 {} | 1954 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1 {} |
| 1846 class T2 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1, /*s evere:INVALID_FIELD_OVERRIDE*/M2 {} | 1955 class T2 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M1, /*s evere:INVALID_FIELD_OVERRIDE*/M2 {} |
| 1847 class T3 extends Base with /*severe:INVALID_FIELD_OVERRIDE*/M2, /*se vere:INVALID_METHOD_OVERRIDE*/M1 {} | 1956 class T3 extends Base with /*severe:INVALID_FIELD_OVERRIDE*/M2, /*se vere:INVALID_METHOD_OVERRIDE*/M1 {} |
| 1848 ''' | 1957 ''' |
| 1849 }); | 1958 }); |
| 1850 | 1959 |
| 1851 testChecker('mixin override to mixin', { | 1960 testChecker( |
| 1852 '/main.dart': ''' | 1961 'mixin override to mixin', |
| 1962 () => { | |
| 1963 '/main.dart': ''' | |
| 1853 class A {} | 1964 class A {} |
| 1854 class B {} | 1965 class B {} |
| 1855 | 1966 |
| 1856 class Base { | 1967 class Base { |
| 1857 } | 1968 } |
| 1858 | 1969 |
| 1859 class M1 { | 1970 class M1 { |
| 1860 m(B a) {} | 1971 m(B a) {} |
| 1861 int x; | 1972 int x; |
| 1862 } | 1973 } |
| 1863 | 1974 |
| 1864 class M2 { | 1975 class M2 { |
| 1865 m(A a) {} | 1976 m(A a) {} |
| 1866 int x; | 1977 int x; |
| 1867 } | 1978 } |
| 1868 | 1979 |
| 1869 class T1 extends Base with M1, /*severe:INVALID_METHOD_OVERRIDE,seve re:INVALID_FIELD_OVERRIDE*/M2 {} | 1980 class T1 extends Base with M1, /*severe:INVALID_METHOD_OVERRIDE,seve re:INVALID_FIELD_OVERRIDE*/M2 {} |
| 1870 ''' | 1981 ''' |
| 1871 }); | 1982 }); |
| 1872 | 1983 |
| 1873 // This is a regression test for a bug in an earlier implementation were | 1984 // This is a regression test for a bug in an earlier implementation were |
| 1874 // names were hiding errors if the first mixin override looked correct, | 1985 // names were hiding errors if the first mixin override looked correct, |
| 1875 // but subsequent ones did not. | 1986 // but subsequent ones did not. |
| 1876 testChecker('no duplicate mixin override', { | 1987 testChecker( |
| 1877 '/main.dart': ''' | 1988 'no duplicate mixin override', |
| 1989 () => { | |
| 1990 '/main.dart': ''' | |
| 1878 class A {} | 1991 class A {} |
| 1879 class B {} | 1992 class B {} |
| 1880 | 1993 |
| 1881 class Base { | 1994 class Base { |
| 1882 m(A a) {} | 1995 m(A a) {} |
| 1883 } | 1996 } |
| 1884 | 1997 |
| 1885 class M1 { | 1998 class M1 { |
| 1886 m(A a) {} | 1999 m(A a) {} |
| 1887 } | 2000 } |
| 1888 | 2001 |
| 1889 class M2 { | 2002 class M2 { |
| 1890 m(B a) {} | 2003 m(B a) {} |
| 1891 } | 2004 } |
| 1892 | 2005 |
| 1893 class M3 { | 2006 class M3 { |
| 1894 m(B a) {} | 2007 m(B a) {} |
| 1895 } | 2008 } |
| 1896 | 2009 |
| 1897 class T1 extends Base | 2010 class T1 extends Base |
| 1898 with M1, /*severe:INVALID_METHOD_OVERRIDE*/M2, M3 {} | 2011 with M1, /*severe:INVALID_METHOD_OVERRIDE*/M2, M3 {} |
| 1899 ''' | 2012 ''' |
| 1900 }); | 2013 }); |
| 1901 | 2014 |
| 1902 testChecker('class override of interface', { | 2015 testChecker( |
| 1903 '/main.dart': ''' | 2016 'class override of interface', |
| 2017 () => { | |
| 2018 '/main.dart': ''' | |
| 1904 class A {} | 2019 class A {} |
| 1905 class B {} | 2020 class B {} |
| 1906 | 2021 |
| 1907 abstract class I { | 2022 abstract class I { |
| 1908 m(A a); | 2023 m(A a); |
| 1909 } | 2024 } |
| 1910 | 2025 |
| 1911 class T1 implements I { | 2026 class T1 implements I { |
| 1912 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2027 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 1913 } | 2028 } |
| 1914 ''' | 2029 ''' |
| 1915 }); | 2030 }); |
| 1916 | 2031 |
| 1917 testChecker('base class override to child interface', { | 2032 testChecker( |
| 1918 '/main.dart': ''' | 2033 'base class override to child interface', |
| 2034 () => { | |
| 2035 '/main.dart': ''' | |
| 1919 class A {} | 2036 class A {} |
| 1920 class B {} | 2037 class B {} |
| 1921 | 2038 |
| 1922 abstract class I { | 2039 abstract class I { |
| 1923 m(A a); | 2040 m(A a); |
| 1924 } | 2041 } |
| 1925 | 2042 |
| 1926 class Base { | 2043 class Base { |
| 1927 m(B a) {} | 2044 m(B a) {} |
| 1928 } | 2045 } |
| 1929 | 2046 |
| 1930 | 2047 |
| 1931 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I { | 2048 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base implements I { |
| 1932 } | 2049 } |
| 1933 ''' | 2050 ''' |
| 1934 }); | 2051 }); |
| 1935 | 2052 |
| 1936 testChecker('mixin override of interface', { | 2053 testChecker( |
| 1937 '/main.dart': ''' | 2054 'mixin override of interface', |
| 2055 () => { | |
| 2056 '/main.dart': ''' | |
| 1938 class A {} | 2057 class A {} |
| 1939 class B {} | 2058 class B {} |
| 1940 | 2059 |
| 1941 abstract class I { | 2060 abstract class I { |
| 1942 m(A a); | 2061 m(A a); |
| 1943 } | 2062 } |
| 1944 | 2063 |
| 1945 class M { | 2064 class M { |
| 1946 m(B a) {} | 2065 m(B a) {} |
| 1947 } | 2066 } |
| 1948 | 2067 |
| 1949 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M | 2068 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 1950 implements I {} | 2069 implements I {} |
| 1951 ''' | 2070 ''' |
| 1952 }); | 2071 }); |
| 1953 | 2072 |
| 1954 // This is a case were it is incorrect to say that the base class | 2073 // This is a case were it is incorrect to say that the base class |
| 1955 // incorrectly overrides the interface. | 2074 // incorrectly overrides the interface. |
| 1956 testChecker( | 2075 testChecker( |
| 1957 'no errors if subclass correctly overrides base and interface', { | 2076 'no errors if subclass correctly overrides base and interface', |
| 1958 '/main.dart': ''' | 2077 () => { |
| 2078 '/main.dart': ''' | |
| 1959 class A {} | 2079 class A {} |
| 1960 class B {} | 2080 class B {} |
| 1961 | 2081 |
| 1962 class Base { | 2082 class Base { |
| 1963 m(A a) {} | 2083 m(A a) {} |
| 1964 } | 2084 } |
| 1965 | 2085 |
| 1966 class I1 { | 2086 class I1 { |
| 1967 m(B a) {} | 2087 m(B a) {} |
| 1968 } | 2088 } |
| 1969 | 2089 |
| 1970 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base | 2090 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 1971 implements I1 {} | 2091 implements I1 {} |
| 1972 | 2092 |
| 1973 class T2 extends Base implements I1 { | 2093 class T2 extends Base implements I1 { |
| 1974 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} | 2094 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} |
| 1975 } | 2095 } |
| 1976 | 2096 |
| 1977 class T3 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base | 2097 class T3 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/Base |
| 1978 implements I1 {} | 2098 implements I1 {} |
| 1979 | 2099 |
| 1980 class T4 extends Object with Base implements I1 { | 2100 class T4 extends Object with Base implements I1 { |
| 1981 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} | 2101 /*severe:INVALID_METHOD_OVERRIDE,severe:INVALID_METHOD_OVERRIDE* /m(a) {} |
| 1982 } | 2102 } |
| 1983 ''' | 2103 ''' |
| 1984 }); | 2104 }); |
| 1985 }); | 2105 }); |
| 1986 | 2106 |
| 1987 group('class override of grand interface', () { | 2107 group('class override of grand interface', () { |
| 1988 testChecker('interface of interface of child', { | 2108 testChecker( |
| 1989 '/main.dart': ''' | 2109 'interface of interface of child', |
| 2110 () => { | |
| 2111 '/main.dart': ''' | |
| 1990 class A {} | 2112 class A {} |
| 1991 class B {} | 2113 class B {} |
| 1992 | 2114 |
| 1993 abstract class I1 { | 2115 abstract class I1 { |
| 1994 m(A a); | 2116 m(A a); |
| 1995 } | 2117 } |
| 1996 abstract class I2 implements I1 {} | 2118 abstract class I2 implements I1 {} |
| 1997 | 2119 |
| 1998 class T1 implements I2 { | 2120 class T1 implements I2 { |
| 1999 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2121 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2000 } | 2122 } |
| 2001 ''' | 2123 ''' |
| 2002 }); | 2124 }); |
| 2003 testChecker('superclass of interface of child', { | 2125 testChecker( |
| 2004 '/main.dart': ''' | 2126 'superclass of interface of child', |
| 2127 () => { | |
| 2128 '/main.dart': ''' | |
| 2005 class A {} | 2129 class A {} |
| 2006 class B {} | 2130 class B {} |
| 2007 | 2131 |
| 2008 abstract class I1 { | 2132 abstract class I1 { |
| 2009 m(A a); | 2133 m(A a); |
| 2010 } | 2134 } |
| 2011 abstract class I2 extends I1 {} | 2135 abstract class I2 extends I1 {} |
| 2012 | 2136 |
| 2013 class T1 implements I2 { | 2137 class T1 implements I2 { |
| 2014 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2138 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2015 } | 2139 } |
| 2016 ''' | 2140 ''' |
| 2017 }); | 2141 }); |
| 2018 testChecker('mixin of interface of child', { | 2142 testChecker( |
| 2019 '/main.dart': ''' | 2143 'mixin of interface of child', |
| 2144 () => { | |
| 2145 '/main.dart': ''' | |
| 2020 class A {} | 2146 class A {} |
| 2021 class B {} | 2147 class B {} |
| 2022 | 2148 |
| 2023 abstract class M1 { | 2149 abstract class M1 { |
| 2024 m(A a); | 2150 m(A a); |
| 2025 } | 2151 } |
| 2026 abstract class I2 extends Object with M1 {} | 2152 abstract class I2 extends Object with M1 {} |
| 2027 | 2153 |
| 2028 class T1 implements I2 { | 2154 class T1 implements I2 { |
| 2029 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2155 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2030 } | 2156 } |
| 2031 ''' | 2157 ''' |
| 2032 }); | 2158 }); |
| 2033 testChecker('interface of abstract superclass', { | 2159 testChecker( |
| 2034 '/main.dart': ''' | 2160 'interface of abstract superclass', |
| 2161 () => { | |
| 2162 '/main.dart': ''' | |
| 2035 class A {} | 2163 class A {} |
| 2036 class B {} | 2164 class B {} |
| 2037 | 2165 |
| 2038 abstract class I1 { | 2166 abstract class I1 { |
| 2039 m(A a); | 2167 m(A a); |
| 2040 } | 2168 } |
| 2041 abstract class Base implements I1 {} | 2169 abstract class Base implements I1 {} |
| 2042 | 2170 |
| 2043 class T1 extends Base { | 2171 class T1 extends Base { |
| 2044 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2172 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2045 } | 2173 } |
| 2046 ''' | 2174 ''' |
| 2047 }); | 2175 }); |
| 2048 testChecker('interface of concrete superclass', { | 2176 testChecker( |
| 2049 '/main.dart': ''' | 2177 'interface of concrete superclass', |
| 2178 () => { | |
| 2179 '/main.dart': ''' | |
| 2050 class A {} | 2180 class A {} |
| 2051 class B {} | 2181 class B {} |
| 2052 | 2182 |
| 2053 abstract class I1 { | 2183 abstract class I1 { |
| 2054 m(A a); | 2184 m(A a); |
| 2055 } | 2185 } |
| 2056 | 2186 |
| 2057 // See issue #25 | 2187 // See issue #25 |
| 2058 /*pass should be warning:AnalyzerError*/class Base implements I1 { | 2188 /*pass should be warning:AnalyzerError*/class Base implements I1 { |
| 2059 } | 2189 } |
| 2060 | 2190 |
| 2061 class T1 extends Base { | 2191 class T1 extends Base { |
| 2062 // not reported technically because if the class is concrete, | 2192 // not reported technically because if the class is concrete, |
| 2063 // it should implement all its interfaces and hence it is | 2193 // it should implement all its interfaces and hence it is |
| 2064 // sufficient to check overrides against it. | 2194 // sufficient to check overrides against it. |
| 2065 m(B a) {} | 2195 m(B a) {} |
| 2066 } | 2196 } |
| 2067 ''' | 2197 ''' |
| 2068 }); | 2198 }); |
| 2069 }); | 2199 }); |
| 2070 | 2200 |
| 2071 group('mixin override of grand interface', () { | 2201 group('mixin override of grand interface', () { |
| 2072 testChecker('interface of interface of child', { | 2202 testChecker( |
| 2073 '/main.dart': ''' | 2203 'interface of interface of child', |
| 2204 () => { | |
| 2205 '/main.dart': ''' | |
| 2074 class A {} | 2206 class A {} |
| 2075 class B {} | 2207 class B {} |
| 2076 | 2208 |
| 2077 abstract class I1 { | 2209 abstract class I1 { |
| 2078 m(A a); | 2210 m(A a); |
| 2079 } | 2211 } |
| 2080 abstract class I2 implements I1 {} | 2212 abstract class I2 implements I1 {} |
| 2081 | 2213 |
| 2082 class M { | 2214 class M { |
| 2083 m(B a) {} | 2215 m(B a) {} |
| 2084 } | 2216 } |
| 2085 | 2217 |
| 2086 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M | 2218 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 2087 implements I2 { | 2219 implements I2 { |
| 2088 } | 2220 } |
| 2089 ''' | 2221 ''' |
| 2090 }); | 2222 }); |
| 2091 testChecker('superclass of interface of child', { | 2223 testChecker( |
| 2092 '/main.dart': ''' | 2224 'superclass of interface of child', |
| 2225 () => { | |
| 2226 '/main.dart': ''' | |
| 2093 class A {} | 2227 class A {} |
| 2094 class B {} | 2228 class B {} |
| 2095 | 2229 |
| 2096 abstract class I1 { | 2230 abstract class I1 { |
| 2097 m(A a); | 2231 m(A a); |
| 2098 } | 2232 } |
| 2099 abstract class I2 extends I1 {} | 2233 abstract class I2 extends I1 {} |
| 2100 | 2234 |
| 2101 class M { | 2235 class M { |
| 2102 m(B a) {} | 2236 m(B a) {} |
| 2103 } | 2237 } |
| 2104 | 2238 |
| 2105 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M | 2239 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 2106 implements I2 { | 2240 implements I2 { |
| 2107 } | 2241 } |
| 2108 ''' | 2242 ''' |
| 2109 }); | 2243 }); |
| 2110 testChecker('mixin of interface of child', { | 2244 testChecker( |
| 2111 '/main.dart': ''' | 2245 'mixin of interface of child', |
| 2246 () => { | |
| 2247 '/main.dart': ''' | |
| 2112 class A {} | 2248 class A {} |
| 2113 class B {} | 2249 class B {} |
| 2114 | 2250 |
| 2115 abstract class M1 { | 2251 abstract class M1 { |
| 2116 m(A a); | 2252 m(A a); |
| 2117 } | 2253 } |
| 2118 abstract class I2 extends Object with M1 {} | 2254 abstract class I2 extends Object with M1 {} |
| 2119 | 2255 |
| 2120 class M { | 2256 class M { |
| 2121 m(B a) {} | 2257 m(B a) {} |
| 2122 } | 2258 } |
| 2123 | 2259 |
| 2124 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M | 2260 class T1 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 2125 implements I2 { | 2261 implements I2 { |
| 2126 } | 2262 } |
| 2127 ''' | 2263 ''' |
| 2128 }); | 2264 }); |
| 2129 testChecker('interface of abstract superclass', { | 2265 testChecker( |
| 2130 '/main.dart': ''' | 2266 'interface of abstract superclass', |
| 2267 () => { | |
| 2268 '/main.dart': ''' | |
| 2131 class A {} | 2269 class A {} |
| 2132 class B {} | 2270 class B {} |
| 2133 | 2271 |
| 2134 abstract class I1 { | 2272 abstract class I1 { |
| 2135 m(A a); | 2273 m(A a); |
| 2136 } | 2274 } |
| 2137 abstract class Base implements I1 {} | 2275 abstract class Base implements I1 {} |
| 2138 | 2276 |
| 2139 class M { | 2277 class M { |
| 2140 m(B a) {} | 2278 m(B a) {} |
| 2141 } | 2279 } |
| 2142 | 2280 |
| 2143 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M { | 2281 class T1 extends Base with /*severe:INVALID_METHOD_OVERRIDE*/M { |
| 2144 } | 2282 } |
| 2145 ''' | 2283 ''' |
| 2146 }); | 2284 }); |
| 2147 testChecker('interface of concrete superclass', { | 2285 testChecker( |
| 2148 '/main.dart': ''' | 2286 'interface of concrete superclass', |
| 2287 () => { | |
| 2288 '/main.dart': ''' | |
| 2149 class A {} | 2289 class A {} |
| 2150 class B {} | 2290 class B {} |
| 2151 | 2291 |
| 2152 abstract class I1 { | 2292 abstract class I1 { |
| 2153 m(A a); | 2293 m(A a); |
| 2154 } | 2294 } |
| 2155 | 2295 |
| 2156 // See issue #25 | 2296 // See issue #25 |
| 2157 /*pass should be warning:AnalyzerError*/class Base implements I1 { | 2297 /*pass should be warning:AnalyzerError*/class Base implements I1 { |
| 2158 } | 2298 } |
| 2159 | 2299 |
| 2160 class M { | 2300 class M { |
| 2161 m(B a) {} | 2301 m(B a) {} |
| 2162 } | 2302 } |
| 2163 | 2303 |
| 2164 class T1 extends Base with M { | 2304 class T1 extends Base with M { |
| 2165 } | 2305 } |
| 2166 ''' | 2306 ''' |
| 2167 }); | 2307 }); |
| 2168 }); | 2308 }); |
| 2169 | 2309 |
| 2170 group('superclass override of grand interface', () { | 2310 group('superclass override of grand interface', () { |
| 2171 testChecker('interface of interface of child', { | 2311 testChecker( |
| 2172 '/main.dart': ''' | 2312 'interface of interface of child', |
| 2313 () => { | |
| 2314 '/main.dart': ''' | |
| 2173 class A {} | 2315 class A {} |
| 2174 class B {} | 2316 class B {} |
| 2175 | 2317 |
| 2176 abstract class I1 { | 2318 abstract class I1 { |
| 2177 m(A a); | 2319 m(A a); |
| 2178 } | 2320 } |
| 2179 abstract class I2 implements I1 {} | 2321 abstract class I2 implements I1 {} |
| 2180 | 2322 |
| 2181 class Base { | 2323 class Base { |
| 2182 m(B a) {} | 2324 m(B a) {} |
| 2183 } | 2325 } |
| 2184 | 2326 |
| 2185 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base | 2327 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2186 implements I2 { | 2328 implements I2 { |
| 2187 } | 2329 } |
| 2188 ''' | 2330 ''' |
| 2189 }); | 2331 }); |
| 2190 testChecker('superclass of interface of child', { | 2332 testChecker( |
| 2191 '/main.dart': ''' | 2333 'superclass of interface of child', |
| 2334 () => { | |
| 2335 '/main.dart': ''' | |
| 2192 class A {} | 2336 class A {} |
| 2193 class B {} | 2337 class B {} |
| 2194 | 2338 |
| 2195 abstract class I1 { | 2339 abstract class I1 { |
| 2196 m(A a); | 2340 m(A a); |
| 2197 } | 2341 } |
| 2198 abstract class I2 extends I1 {} | 2342 abstract class I2 extends I1 {} |
| 2199 | 2343 |
| 2200 class Base { | 2344 class Base { |
| 2201 m(B a) {} | 2345 m(B a) {} |
| 2202 } | 2346 } |
| 2203 | 2347 |
| 2204 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base | 2348 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2205 implements I2 { | 2349 implements I2 { |
| 2206 } | 2350 } |
| 2207 ''' | 2351 ''' |
| 2208 }); | 2352 }); |
| 2209 testChecker('mixin of interface of child', { | 2353 testChecker( |
| 2210 '/main.dart': ''' | 2354 'mixin of interface of child', |
| 2355 () => { | |
| 2356 '/main.dart': ''' | |
| 2211 class A {} | 2357 class A {} |
| 2212 class B {} | 2358 class B {} |
| 2213 | 2359 |
| 2214 abstract class M1 { | 2360 abstract class M1 { |
| 2215 m(A a); | 2361 m(A a); |
| 2216 } | 2362 } |
| 2217 abstract class I2 extends Object with M1 {} | 2363 abstract class I2 extends Object with M1 {} |
| 2218 | 2364 |
| 2219 class Base { | 2365 class Base { |
| 2220 m(B a) {} | 2366 m(B a) {} |
| 2221 } | 2367 } |
| 2222 | 2368 |
| 2223 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base | 2369 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2224 implements I2 { | 2370 implements I2 { |
| 2225 } | 2371 } |
| 2226 ''' | 2372 ''' |
| 2227 }); | 2373 }); |
| 2228 testChecker('interface of abstract superclass', { | 2374 testChecker( |
| 2229 '/main.dart': ''' | 2375 'interface of abstract superclass', |
| 2376 () => { | |
| 2377 '/main.dart': ''' | |
| 2230 class A {} | 2378 class A {} |
| 2231 class B {} | 2379 class B {} |
| 2232 | 2380 |
| 2233 abstract class I1 { | 2381 abstract class I1 { |
| 2234 m(A a); | 2382 m(A a); |
| 2235 } | 2383 } |
| 2236 | 2384 |
| 2237 abstract class Base implements I1 { | 2385 abstract class Base implements I1 { |
| 2238 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2386 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2239 } | 2387 } |
| 2240 | 2388 |
| 2241 class T1 extends Base { | 2389 class T1 extends Base { |
| 2242 // we consider the base class incomplete because it is | 2390 // we consider the base class incomplete because it is |
| 2243 // abstract, so we report the error here too. | 2391 // abstract, so we report the error here too. |
| 2244 // TODO(sigmund): consider tracking overrides in a fine-grain | 2392 // TODO(sigmund): consider tracking overrides in a fine-grain |
| 2245 // manner, then this and the double-overrides would not be | 2393 // manner, then this and the double-overrides would not be |
| 2246 // reported. | 2394 // reported. |
| 2247 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2395 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2248 } | 2396 } |
| 2249 ''' | 2397 ''' |
| 2250 }); | 2398 }); |
| 2251 testChecker('interface of concrete superclass', { | 2399 testChecker( |
| 2252 '/main.dart': ''' | 2400 'interface of concrete superclass', |
| 2401 () => { | |
| 2402 '/main.dart': ''' | |
| 2253 class A {} | 2403 class A {} |
| 2254 class B {} | 2404 class B {} |
| 2255 | 2405 |
| 2256 abstract class I1 { | 2406 abstract class I1 { |
| 2257 m(A a); | 2407 m(A a); |
| 2258 } | 2408 } |
| 2259 | 2409 |
| 2260 class Base implements I1 { | 2410 class Base implements I1 { |
| 2261 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2411 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2262 } | 2412 } |
| 2263 | 2413 |
| 2264 class T1 extends Base { | 2414 class T1 extends Base { |
| 2265 m(B a) {} | 2415 m(B a) {} |
| 2266 } | 2416 } |
| 2267 ''' | 2417 ''' |
| 2268 }); | 2418 }); |
| 2269 }); | 2419 }); |
| 2270 | 2420 |
| 2271 group('no duplicate reports from overriding interfaces', () { | 2421 group('no duplicate reports from overriding interfaces', () { |
| 2272 testChecker('type overrides same method in multiple interfaces', { | 2422 testChecker( |
| 2273 '/main.dart': ''' | 2423 'type overrides same method in multiple interfaces', |
| 2424 () => { | |
| 2425 '/main.dart': ''' | |
| 2274 class A {} | 2426 class A {} |
| 2275 class B {} | 2427 class B {} |
| 2276 | 2428 |
| 2277 abstract class I1 { | 2429 abstract class I1 { |
| 2278 m(A a); | 2430 m(A a); |
| 2279 } | 2431 } |
| 2280 abstract class I2 implements I1 { | 2432 abstract class I2 implements I1 { |
| 2281 m(A a); | 2433 m(A a); |
| 2282 } | 2434 } |
| 2283 | 2435 |
| 2284 class Base { | 2436 class Base { |
| 2285 } | 2437 } |
| 2286 | 2438 |
| 2287 class T1 implements I2 { | 2439 class T1 implements I2 { |
| 2288 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2440 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2289 } | 2441 } |
| 2290 ''' | 2442 ''' |
| 2291 }); | 2443 }); |
| 2292 | 2444 |
| 2293 testChecker('type and base type override same method in interface', { | 2445 testChecker( |
| 2294 '/main.dart': ''' | 2446 'type and base type override same method in interface', |
| 2447 () => { | |
| 2448 '/main.dart': ''' | |
| 2295 class A {} | 2449 class A {} |
| 2296 class B {} | 2450 class B {} |
| 2297 | 2451 |
| 2298 abstract class I1 { | 2452 abstract class I1 { |
| 2299 m(A a); | 2453 m(A a); |
| 2300 } | 2454 } |
| 2301 | 2455 |
| 2302 class Base { | 2456 class Base { |
| 2303 m(B a); | 2457 m(B a); |
| 2304 } | 2458 } |
| 2305 | 2459 |
| 2306 // Note: no error reported in `extends Base` to avoid duplicating | 2460 // Note: no error reported in `extends Base` to avoid duplicating |
| 2307 // the error in T1. | 2461 // the error in T1. |
| 2308 class T1 extends Base implements I1 { | 2462 class T1 extends Base implements I1 { |
| 2309 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2463 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2310 } | 2464 } |
| 2311 | 2465 |
| 2312 // If there is no error in the class, we do report the error at | 2466 // If there is no error in the class, we do report the error at |
| 2313 // the base class: | 2467 // the base class: |
| 2314 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Base | 2468 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2315 implements I1 { | 2469 implements I1 { |
| 2316 } | 2470 } |
| 2317 ''' | 2471 ''' |
| 2318 }); | 2472 }); |
| 2319 | 2473 |
| 2320 testChecker('type and mixin override same method in interface', { | 2474 testChecker( |
| 2321 '/main.dart': ''' | 2475 'type and mixin override same method in interface', |
| 2476 () => { | |
| 2477 '/main.dart': ''' | |
| 2322 class A {} | 2478 class A {} |
| 2323 class B {} | 2479 class B {} |
| 2324 | 2480 |
| 2325 abstract class I1 { | 2481 abstract class I1 { |
| 2326 m(A a); | 2482 m(A a); |
| 2327 } | 2483 } |
| 2328 | 2484 |
| 2329 class M { | 2485 class M { |
| 2330 m(B a); | 2486 m(B a); |
| 2331 } | 2487 } |
| 2332 | 2488 |
| 2333 class T1 extends Object with M implements I1 { | 2489 class T1 extends Object with M implements I1 { |
| 2334 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} | 2490 /*severe:INVALID_METHOD_OVERRIDE*/m(B a) {} |
| 2335 } | 2491 } |
| 2336 | 2492 |
| 2337 class T2 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M | 2493 class T2 extends Object with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 2338 implements I1 { | 2494 implements I1 { |
| 2339 } | 2495 } |
| 2340 ''' | 2496 ''' |
| 2341 }); | 2497 }); |
| 2342 | 2498 |
| 2343 testChecker('two grand types override same method in interface', { | 2499 testChecker( |
| 2344 '/main.dart': ''' | 2500 'two grand types override same method in interface', |
| 2501 () => { | |
| 2502 '/main.dart': ''' | |
| 2345 class A {} | 2503 class A {} |
| 2346 class B {} | 2504 class B {} |
| 2347 | 2505 |
| 2348 abstract class I1 { | 2506 abstract class I1 { |
| 2349 m(A a); | 2507 m(A a); |
| 2350 } | 2508 } |
| 2351 | 2509 |
| 2352 class Grandparent { | 2510 class Grandparent { |
| 2353 m(B a) {} | 2511 m(B a) {} |
| 2354 } | 2512 } |
| 2355 | 2513 |
| 2356 class Parent1 extends Grandparent { | 2514 class Parent1 extends Grandparent { |
| 2357 m(B a) {} | 2515 m(B a) {} |
| 2358 } | 2516 } |
| 2359 class Parent2 extends Grandparent { | 2517 class Parent2 extends Grandparent { |
| 2360 } | 2518 } |
| 2361 | 2519 |
| 2362 // Note: otherwise both errors would be reported on this line | 2520 // Note: otherwise both errors would be reported on this line |
| 2363 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent1 | 2521 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent1 |
| 2364 implements I1 { | 2522 implements I1 { |
| 2365 } | 2523 } |
| 2366 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent2 | 2524 class T2 /*severe:INVALID_METHOD_OVERRIDE*/extends Parent2 |
| 2367 implements I1 { | 2525 implements I1 { |
| 2368 } | 2526 } |
| 2369 ''' | 2527 ''' |
| 2370 }); | 2528 }); |
| 2371 | 2529 |
| 2372 testChecker('two mixins override same method in interface', { | 2530 testChecker( |
| 2373 '/main.dart': ''' | 2531 'two mixins override same method in interface', |
| 2532 () => { | |
| 2533 '/main.dart': ''' | |
| 2374 class A {} | 2534 class A {} |
| 2375 class B {} | 2535 class B {} |
| 2376 | 2536 |
| 2377 abstract class I1 { | 2537 abstract class I1 { |
| 2378 m(A a); | 2538 m(A a); |
| 2379 } | 2539 } |
| 2380 | 2540 |
| 2381 class M1 { | 2541 class M1 { |
| 2382 m(B a) {} | 2542 m(B a) {} |
| 2383 } | 2543 } |
| 2384 | 2544 |
| 2385 class M2 { | 2545 class M2 { |
| 2386 m(B a) {} | 2546 m(B a) {} |
| 2387 } | 2547 } |
| 2388 | 2548 |
| 2389 // Here we want to report both, because the error location is | 2549 // Here we want to report both, because the error location is |
| 2390 // different. | 2550 // different. |
| 2391 // TODO(sigmund): should we merge these as well? | 2551 // TODO(sigmund): should we merge these as well? |
| 2392 class T1 extends Object | 2552 class T1 extends Object |
| 2393 with /*severe:INVALID_METHOD_OVERRIDE*/M1 | 2553 with /*severe:INVALID_METHOD_OVERRIDE*/M1 |
| 2394 with /*severe:INVALID_METHOD_OVERRIDE*/M2 | 2554 with /*severe:INVALID_METHOD_OVERRIDE*/M2 |
| 2395 implements I1 { | 2555 implements I1 { |
| 2396 } | 2556 } |
| 2397 ''' | 2557 ''' |
| 2398 }); | 2558 }); |
| 2399 | 2559 |
| 2400 testChecker('base type and mixin override same method in interface', { | 2560 testChecker( |
| 2401 '/main.dart': ''' | 2561 'base type and mixin override same method in interface', |
| 2562 () => { | |
| 2563 '/main.dart': ''' | |
| 2402 class A {} | 2564 class A {} |
| 2403 class B {} | 2565 class B {} |
| 2404 | 2566 |
| 2405 abstract class I1 { | 2567 abstract class I1 { |
| 2406 m(A a); | 2568 m(A a); |
| 2407 } | 2569 } |
| 2408 | 2570 |
| 2409 class Base { | 2571 class Base { |
| 2410 m(B a) {} | 2572 m(B a) {} |
| 2411 } | 2573 } |
| 2412 | 2574 |
| 2413 class M { | 2575 class M { |
| 2414 m(B a) {} | 2576 m(B a) {} |
| 2415 } | 2577 } |
| 2416 | 2578 |
| 2417 // Here we want to report both, because the error location is | 2579 // Here we want to report both, because the error location is |
| 2418 // different. | 2580 // different. |
| 2419 // TODO(sigmund): should we merge these as well? | 2581 // TODO(sigmund): should we merge these as well? |
| 2420 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base | 2582 class T1 /*severe:INVALID_METHOD_OVERRIDE*/extends Base |
| 2421 with /*severe:INVALID_METHOD_OVERRIDE*/M | 2583 with /*severe:INVALID_METHOD_OVERRIDE*/M |
| 2422 implements I1 { | 2584 implements I1 { |
| 2423 } | 2585 } |
| 2424 ''' | 2586 ''' |
| 2425 }); | 2587 }); |
| 2426 }); | 2588 }); |
| 2427 | 2589 |
| 2428 testChecker('invalid runtime checks', { | 2590 testChecker( |
| 2429 '/main.dart': ''' | 2591 'invalid runtime checks', |
| 2592 () => { | |
| 2593 '/main.dart': ''' | |
| 2430 typedef int I2I(int x); | 2594 typedef int I2I(int x); |
| 2431 typedef int D2I(x); | 2595 typedef int D2I(x); |
| 2432 typedef int II2I(int x, int y); | 2596 typedef int II2I(int x, int y); |
| 2433 typedef int DI2I(x, int y); | 2597 typedef int DI2I(x, int y); |
| 2434 typedef int ID2I(int x, y); | 2598 typedef int ID2I(int x, y); |
| 2435 typedef int DD2I(x, y); | 2599 typedef int DD2I(x, y); |
| 2436 | 2600 |
| 2437 typedef I2D(int x); | 2601 typedef I2D(int x); |
| 2438 typedef D2D(x); | 2602 typedef D2D(x); |
| 2439 typedef II2D(int x, int y); | 2603 typedef II2D(int x, int y); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2470 f = bar as II2I; | 2634 f = bar as II2I; |
| 2471 f = bar as DI2I; | 2635 f = bar as DI2I; |
| 2472 f = bar as ID2I; | 2636 f = bar as ID2I; |
| 2473 f = bar as II2D; | 2637 f = bar as II2D; |
| 2474 f = bar as DD2I; | 2638 f = bar as DD2I; |
| 2475 f = bar as DI2D; | 2639 f = bar as DI2D; |
| 2476 f = bar as ID2D; | 2640 f = bar as ID2D; |
| 2477 f = bar as DD2D; | 2641 f = bar as DD2D; |
| 2478 } | 2642 } |
| 2479 ''' | 2643 ''' |
| 2480 }); | 2644 }); |
| 2481 | 2645 |
| 2482 group('function modifiers', () { | 2646 group('function modifiers', () { |
| 2483 testChecker('async', { | 2647 testChecker( |
| 2484 '/main.dart': ''' | 2648 'async', |
| 2649 () => { | |
| 2650 '/main.dart': ''' | |
| 2485 import 'dart:async'; | 2651 import 'dart:async'; |
| 2486 import 'dart:math' show Random; | 2652 import 'dart:math' show Random; |
| 2487 | 2653 |
| 2488 dynamic x; | 2654 dynamic x; |
| 2489 | 2655 |
| 2490 foo1() async => x; | 2656 foo1() async => x; |
| 2491 Future foo2() async => x; | 2657 Future foo2() async => x; |
| 2492 Future<int> foo3() async => (/*info:DYNAMIC_CAST*/x); | 2658 Future<int> foo3() async => (/*info:DYNAMIC_CAST*/x); |
| 2493 Future<int> foo4() async => (new Future<int>.value(/*info:DYNAMIC_CAST*/ x)); | 2659 Future<int> foo4() async => (new Future<int>.value(/*info:DYNAMIC_CAST*/ x)); |
| 2494 Future<int> foo5() async => (/*severe:STATIC_TYPE_ERROR*/new Future<Stri ng>.value(/*info:DYNAMIC_CAST*/x)); | 2660 Future<int> foo5() async => (/*severe:STATIC_TYPE_ERROR*/new Future<Stri ng>.value(/*info:DYNAMIC_CAST*/x)); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2511 | 2677 |
| 2512 Future<bool> get issue_264 async { | 2678 Future<bool> get issue_264 async { |
| 2513 await 42; | 2679 await 42; |
| 2514 if (new Random().nextBool()) { | 2680 if (new Random().nextBool()) { |
| 2515 return true; | 2681 return true; |
| 2516 } else { | 2682 } else { |
| 2517 return new Future<bool>.value(false); | 2683 return new Future<bool>.value(false); |
| 2518 } | 2684 } |
| 2519 } | 2685 } |
| 2520 ''' | 2686 ''' |
| 2521 }); | 2687 }); |
| 2522 | 2688 |
| 2523 testChecker('async*', { | 2689 testChecker( |
| 2524 '/main.dart': ''' | 2690 'async*', |
| 2691 () => { | |
| 2692 '/main.dart': ''' | |
| 2525 import 'dart:async'; | 2693 import 'dart:async'; |
| 2526 | 2694 |
| 2527 dynamic x; | 2695 dynamic x; |
| 2528 | 2696 |
| 2529 bar1() async* { yield x; } | 2697 bar1() async* { yield x; } |
| 2530 Stream bar2() async* { yield x; } | 2698 Stream bar2() async* { yield x; } |
| 2531 Stream<int> bar3() async* { yield (/*info:DYNAMIC_CAST*/x); } | 2699 Stream<int> bar3() async* { yield (/*info:DYNAMIC_CAST*/x); } |
| 2532 Stream<int> bar4() async* { yield (/*severe:STATIC_TYPE_ERROR*/new Strea m<int>()); } | 2700 Stream<int> bar4() async* { yield (/*severe:STATIC_TYPE_ERROR*/new Strea m<int>()); } |
| 2533 | 2701 |
| 2534 baz1() async* { yield* (/*info:DYNAMIC_CAST*/x); } | 2702 baz1() async* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2535 Stream baz2() async* { yield* (/*info:DYNAMIC_CAST*/x); } | 2703 Stream baz2() async* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2536 Stream<int> baz3() async* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } | 2704 Stream<int> baz3() async* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } |
| 2537 Stream<int> baz4() async* { yield* new Stream<int>(); } | 2705 Stream<int> baz4() async* { yield* new Stream<int>(); } |
| 2538 Stream<int> baz5() async* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/new Stream()); } | 2706 Stream<int> baz5() async* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/new Stream()); } |
| 2539 ''' | 2707 ''' |
| 2540 }); | 2708 }); |
| 2541 | 2709 |
| 2542 testChecker('sync*', { | 2710 testChecker( |
| 2543 '/main.dart': ''' | 2711 'sync*', |
| 2712 () => { | |
| 2713 '/main.dart': ''' | |
| 2544 import 'dart:async'; | 2714 import 'dart:async'; |
| 2545 | 2715 |
| 2546 dynamic x; | 2716 dynamic x; |
| 2547 | 2717 |
| 2548 bar1() sync* { yield x; } | 2718 bar1() sync* { yield x; } |
| 2549 Iterable bar2() sync* { yield x; } | 2719 Iterable bar2() sync* { yield x; } |
| 2550 Iterable<int> bar3() sync* { yield (/*info:DYNAMIC_CAST*/x); } | 2720 Iterable<int> bar3() sync* { yield (/*info:DYNAMIC_CAST*/x); } |
| 2551 Iterable<int> bar4() sync* { yield (/*severe:STATIC_TYPE_ERROR*/new Iter able<int>()); } | 2721 Iterable<int> bar4() sync* { yield (/*severe:STATIC_TYPE_ERROR*/new Iter able<int>()); } |
| 2552 | 2722 |
| 2553 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } | 2723 baz1() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2554 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } | 2724 Iterable baz2() sync* { yield* (/*info:DYNAMIC_CAST*/x); } |
| 2555 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } | 2725 Iterable<int> baz3() sync* { yield* (/*warning:DOWN_CAST_COMPOSITE*/x); } |
| 2556 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } | 2726 Iterable<int> baz4() sync* { yield* new Iterable<int>(); } |
| 2557 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); } | 2727 Iterable<int> baz5() sync* { yield* (/*info:INFERRED_TYPE_ALLOCATION*/ne w Iterable()); } |
| 2558 ''' | 2728 ''' |
| 2559 }); | 2729 }); |
| 2560 }); | 2730 }); |
| 2561 } | 2731 } |
| OLD | NEW |