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 library analyzer.test.src.task.strong.checker_test; | 5 library analyzer.test.src.task.strong.checker_test; |
6 | 6 |
7 import '../../../reflective_tests.dart'; | 7 import '../../../reflective_tests.dart'; |
8 import 'strong_test_helper.dart'; | 8 import 'strong_test_helper.dart'; |
9 | 9 |
10 void main() { | 10 void main() { |
(...skipping 3404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3415 g() { | 3415 g() { |
3416 Object x; | 3416 Object x; |
3417 if (x is int) { | 3417 if (x is int) { |
3418 int y = x; | 3418 int y = x; |
3419 String z = /*error:INVALID_ASSIGNMENT*/x; | 3419 String z = /*error:INVALID_ASSIGNMENT*/x; |
3420 } | 3420 } |
3421 } | 3421 } |
3422 '''); | 3422 '''); |
3423 } | 3423 } |
3424 | 3424 |
| 3425 void test_typePromotionFromTypeParameter() { |
| 3426 // Regression test for https://github.com/dart-lang/sdk/issues/26965 |
| 3427 checkFile(r''' |
| 3428 void f/*<T>*/(/*=T*/ object) { |
| 3429 if (object is String) print(object.substring(1)); |
| 3430 } |
| 3431 void g/*<T extends num>*/(/*=T*/ object) { |
| 3432 if (object is int) print(object.isEven); |
| 3433 if (object is String) print(/*info:DYNAMIC_INVOKE*/object.substring(1)); |
| 3434 } |
| 3435 class Clonable<T> {} |
| 3436 class SubClonable<T> extends Clonable<T> { |
| 3437 T m(T t) => t; |
| 3438 } |
| 3439 void h/*<T extends Clonable<T>>*/(/*=T*/ object) { |
| 3440 if (/*info:NON_GROUND_TYPE_CHECK_INFO*/object is SubClonable/*<T>*/) { |
| 3441 // Note we need to cast back to T, because promotion lost that type info. |
| 3442 print(object.m(object as dynamic/*=T*/)); |
| 3443 } |
| 3444 } |
| 3445 '''); |
| 3446 } |
| 3447 |
3425 void test_typeSubtyping_assigningClass() { | 3448 void test_typeSubtyping_assigningClass() { |
3426 checkFile(''' | 3449 checkFile(''' |
3427 class A {} | 3450 class A {} |
3428 class B extends A {} | 3451 class B extends A {} |
3429 | 3452 |
3430 void main() { | 3453 void main() { |
3431 dynamic y; | 3454 dynamic y; |
3432 Object o; | 3455 Object o; |
3433 int i = 0; | 3456 int i = 0; |
3434 double d = 0.0; | 3457 double d = 0.0; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3625 // Regression test for https://github.com/dart-lang/sdk/issues/25069 | 3648 // Regression test for https://github.com/dart-lang/sdk/issues/25069 |
3626 checkFile(''' | 3649 checkFile(''' |
3627 typedef int Foo(); | 3650 typedef int Foo(); |
3628 void foo() {} | 3651 void foo() {} |
3629 void main () { | 3652 void main () { |
3630 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); | 3653 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); |
3631 } | 3654 } |
3632 '''); | 3655 '''); |
3633 } | 3656 } |
3634 } | 3657 } |
OLD | NEW |