| 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.inferred_type_test; | 5 library analyzer.test.src.task.strong.inferred_type_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 2615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2626 void f() {} | 2626 void f() {} |
| 2627 } | 2627 } |
| 2628 class C extends B { | 2628 class C extends B { |
| 2629 f() {} | 2629 f() {} |
| 2630 } | 2630 } |
| 2631 var x = new C()./*info:USE_OF_VOID_RESULT*/f(); | 2631 var x = new C()./*info:USE_OF_VOID_RESULT*/f(); |
| 2632 '''); | 2632 '''); |
| 2633 } | 2633 } |
| 2634 | 2634 |
| 2635 test_inferConstsTransitively() async { | 2635 test_inferConstsTransitively() async { |
| 2636 addFile( | 2636 addFile(''' |
| 2637 ''' | |
| 2638 const b1 = 2; | 2637 const b1 = 2; |
| 2639 ''', | 2638 ''', name: '/b.dart'); |
| 2640 name: '/b.dart'); | 2639 addFile(''' |
| 2641 addFile( | |
| 2642 ''' | |
| 2643 import 'main.dart'; | 2640 import 'main.dart'; |
| 2644 import 'b.dart'; | 2641 import 'b.dart'; |
| 2645 const a1 = m2; | 2642 const a1 = m2; |
| 2646 const a2 = b1; | 2643 const a2 = b1; |
| 2647 ''', | 2644 ''', name: '/a.dart'); |
| 2648 name: '/a.dart'); | |
| 2649 await checkFileElement(''' | 2645 await checkFileElement(''' |
| 2650 import 'a.dart'; | 2646 import 'a.dart'; |
| 2651 const m1 = a1; | 2647 const m1 = a1; |
| 2652 const m2 = a2; | 2648 const m2 = a2; |
| 2653 | 2649 |
| 2654 foo() { | 2650 foo() { |
| 2655 int i; | 2651 int i; |
| 2656 i = m1; | 2652 i = m1; |
| 2657 } | 2653 } |
| 2658 '''); | 2654 '''); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2809 } | 2805 } |
| 2810 | 2806 |
| 2811 foo() { | 2807 foo() { |
| 2812 String y = /*info:DYNAMIC_CAST*/new B().x; | 2808 String y = /*info:DYNAMIC_CAST*/new B().x; |
| 2813 int z = /*info:DYNAMIC_CAST*/new B().x; | 2809 int z = /*info:DYNAMIC_CAST*/new B().x; |
| 2814 } | 2810 } |
| 2815 '''); | 2811 '''); |
| 2816 } | 2812 } |
| 2817 | 2813 |
| 2818 test_inferFromVariablesInCycleLibsWhenFlagIsOn() async { | 2814 test_inferFromVariablesInCycleLibsWhenFlagIsOn() async { |
| 2819 addFile( | 2815 addFile(''' |
| 2820 ''' | |
| 2821 import 'main.dart'; | 2816 import 'main.dart'; |
| 2822 var x = 2; // ok to infer | 2817 var x = 2; // ok to infer |
| 2823 ''', | 2818 ''', name: '/a.dart'); |
| 2824 name: '/a.dart'); | |
| 2825 await checkFileElement(''' | 2819 await checkFileElement(''' |
| 2826 import 'a.dart'; | 2820 import 'a.dart'; |
| 2827 var y = x; // now ok :) | 2821 var y = x; // now ok :) |
| 2828 | 2822 |
| 2829 test1() { | 2823 test1() { |
| 2830 int t = 3; | 2824 int t = 3; |
| 2831 t = x; | 2825 t = x; |
| 2832 t = y; | 2826 t = y; |
| 2833 } | 2827 } |
| 2834 '''); | 2828 '''); |
| 2835 } | 2829 } |
| 2836 | 2830 |
| 2837 test_inferFromVariablesInCycleLibsWhenFlagIsOn2() async { | 2831 test_inferFromVariablesInCycleLibsWhenFlagIsOn2() async { |
| 2838 addFile( | 2832 addFile(''' |
| 2839 ''' | |
| 2840 import 'main.dart'; | 2833 import 'main.dart'; |
| 2841 class A { static var x = 2; } | 2834 class A { static var x = 2; } |
| 2842 ''', | 2835 ''', name: '/a.dart'); |
| 2843 name: '/a.dart'); | |
| 2844 await checkFileElement(''' | 2836 await checkFileElement(''' |
| 2845 import 'a.dart'; | 2837 import 'a.dart'; |
| 2846 class B { static var y = A.x; } | 2838 class B { static var y = A.x; } |
| 2847 | 2839 |
| 2848 test1() { | 2840 test1() { |
| 2849 int t = 3; | 2841 int t = 3; |
| 2850 t = A.x; | 2842 t = A.x; |
| 2851 t = B.y; | 2843 t = B.y; |
| 2852 } | 2844 } |
| 2853 '''); | 2845 '''); |
| 2854 } | 2846 } |
| 2855 | 2847 |
| 2856 test_inferFromVariablesInNonCycleImportsWithFlag() async { | 2848 test_inferFromVariablesInNonCycleImportsWithFlag() async { |
| 2857 addFile( | 2849 addFile(''' |
| 2858 ''' | |
| 2859 var x = 2; | 2850 var x = 2; |
| 2860 ''', | 2851 ''', name: '/a.dart'); |
| 2861 name: '/a.dart'); | |
| 2862 await checkFileElement(''' | 2852 await checkFileElement(''' |
| 2863 import 'a.dart'; | 2853 import 'a.dart'; |
| 2864 var y = x; | 2854 var y = x; |
| 2865 | 2855 |
| 2866 test1() { | 2856 test1() { |
| 2867 x = /*error:INVALID_ASSIGNMENT*/"hi"; | 2857 x = /*error:INVALID_ASSIGNMENT*/"hi"; |
| 2868 y = /*error:INVALID_ASSIGNMENT*/"hi"; | 2858 y = /*error:INVALID_ASSIGNMENT*/"hi"; |
| 2869 } | 2859 } |
| 2870 '''); | 2860 '''); |
| 2871 } | 2861 } |
| 2872 | 2862 |
| 2873 test_inferFromVariablesInNonCycleImportsWithFlag2() async { | 2863 test_inferFromVariablesInNonCycleImportsWithFlag2() async { |
| 2874 addFile( | 2864 addFile(''' |
| 2875 ''' | |
| 2876 class A { static var x = 2; } | 2865 class A { static var x = 2; } |
| 2877 ''', | 2866 ''', name: '/a.dart'); |
| 2878 name: '/a.dart'); | |
| 2879 await checkFileElement(''' | 2867 await checkFileElement(''' |
| 2880 import 'a.dart'; | 2868 import 'a.dart'; |
| 2881 class B { static var y = A.x; } | 2869 class B { static var y = A.x; } |
| 2882 | 2870 |
| 2883 test1() { | 2871 test1() { |
| 2884 A.x = /*error:INVALID_ASSIGNMENT*/"hi"; | 2872 A.x = /*error:INVALID_ASSIGNMENT*/"hi"; |
| 2885 B.y = /*error:INVALID_ASSIGNMENT*/"hi"; | 2873 B.y = /*error:INVALID_ASSIGNMENT*/"hi"; |
| 2886 } | 2874 } |
| 2887 '''); | 2875 '''); |
| 2888 } | 2876 } |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3371 List<String> strings() { | 3359 List<String> strings() { |
| 3372 var stuff = [].expand(/*info:INFERRED_TYPE_CLOSURE*/(i) { | 3360 var stuff = [].expand(/*info:INFERRED_TYPE_CLOSURE*/(i) { |
| 3373 return <String>[]; | 3361 return <String>[]; |
| 3374 }); | 3362 }); |
| 3375 return stuff.toList(); | 3363 return stuff.toList(); |
| 3376 } | 3364 } |
| 3377 '''); | 3365 '''); |
| 3378 } | 3366 } |
| 3379 | 3367 |
| 3380 test_inferStaticsTransitively() async { | 3368 test_inferStaticsTransitively() async { |
| 3381 addFile( | 3369 addFile(''' |
| 3382 ''' | |
| 3383 final b1 = 2; | 3370 final b1 = 2; |
| 3384 ''', | 3371 ''', name: '/b.dart'); |
| 3385 name: '/b.dart'); | 3372 addFile(''' |
| 3386 addFile( | |
| 3387 ''' | |
| 3388 import 'main.dart'; | 3373 import 'main.dart'; |
| 3389 import 'b.dart'; | 3374 import 'b.dart'; |
| 3390 final a1 = m2; | 3375 final a1 = m2; |
| 3391 class A { | 3376 class A { |
| 3392 static final a2 = b1; | 3377 static final a2 = b1; |
| 3393 } | 3378 } |
| 3394 ''', | 3379 ''', name: '/a.dart'); |
| 3395 name: '/a.dart'); | |
| 3396 await checkFileElement(''' | 3380 await checkFileElement(''' |
| 3397 import 'a.dart'; | 3381 import 'a.dart'; |
| 3398 final m1 = a1; | 3382 final m1 = a1; |
| 3399 final m2 = A.a2; | 3383 final m2 = A.a2; |
| 3400 | 3384 |
| 3401 foo() { | 3385 foo() { |
| 3402 int i; | 3386 int i; |
| 3403 i = m1; | 3387 i = m1; |
| 3404 } | 3388 } |
| 3405 '''); | 3389 '''); |
| 3406 } | 3390 } |
| 3407 | 3391 |
| 3408 test_inferStaticsTransitively2() async { | 3392 test_inferStaticsTransitively2() async { |
| 3409 await checkFileElement(''' | 3393 await checkFileElement(''' |
| 3410 const x1 = 1; | 3394 const x1 = 1; |
| 3411 final x2 = 1; | 3395 final x2 = 1; |
| 3412 final y1 = x1; | 3396 final y1 = x1; |
| 3413 final y2 = x2; | 3397 final y2 = x2; |
| 3414 | 3398 |
| 3415 foo() { | 3399 foo() { |
| 3416 int i; | 3400 int i; |
| 3417 i = y1; | 3401 i = y1; |
| 3418 i = y2; | 3402 i = y2; |
| 3419 } | 3403 } |
| 3420 '''); | 3404 '''); |
| 3421 } | 3405 } |
| 3422 | 3406 |
| 3423 test_inferStaticsTransitively3() async { | 3407 test_inferStaticsTransitively3() async { |
| 3424 addFile( | 3408 addFile(''' |
| 3425 ''' | |
| 3426 const a1 = 3; | 3409 const a1 = 3; |
| 3427 const a2 = 4; | 3410 const a2 = 4; |
| 3428 class A { | 3411 class A { |
| 3429 static const a3 = null; | 3412 static const a3 = null; |
| 3430 } | 3413 } |
| 3431 ''', | 3414 ''', name: '/a.dart'); |
| 3432 name: '/a.dart'); | |
| 3433 await checkFileElement(''' | 3415 await checkFileElement(''' |
| 3434 import 'a.dart' show a1, A; | 3416 import 'a.dart' show a1, A; |
| 3435 import 'a.dart' as p show a2, A; | 3417 import 'a.dart' as p show a2, A; |
| 3436 const t1 = 1; | 3418 const t1 = 1; |
| 3437 const t2 = t1; | 3419 const t2 = t1; |
| 3438 const t3 = a1; | 3420 const t3 = a1; |
| 3439 const t4 = p.a2; | 3421 const t4 = p.a2; |
| 3440 const t5 = A.a3; | 3422 const t5 = A.a3; |
| 3441 const t6 = p.A.a3; | 3423 const t6 = p.A.a3; |
| 3442 | 3424 |
| 3443 foo() { | 3425 foo() { |
| 3444 int i; | 3426 int i; |
| 3445 i = t1; | 3427 i = t1; |
| 3446 i = t2; | 3428 i = t2; |
| 3447 i = t3; | 3429 i = t3; |
| 3448 i = t4; | 3430 i = t4; |
| 3449 } | 3431 } |
| 3450 '''); | 3432 '''); |
| 3451 } | 3433 } |
| 3452 | 3434 |
| 3453 test_inferStaticsWithMethodInvocations() async { | 3435 test_inferStaticsWithMethodInvocations() async { |
| 3454 addFile( | 3436 addFile(''' |
| 3455 ''' | |
| 3456 m3(String a, String b, [a1,a2]) {} | 3437 m3(String a, String b, [a1,a2]) {} |
| 3457 ''', | 3438 ''', name: '/a.dart'); |
| 3458 name: '/a.dart'); | |
| 3459 await checkFileElement(''' | 3439 await checkFileElement(''' |
| 3460 import 'a.dart'; | 3440 import 'a.dart'; |
| 3461 class T { | 3441 class T { |
| 3462 static final T foo = m1(m2(m3('', ''))); | 3442 static final T foo = m1(m2(m3('', ''))); |
| 3463 static T m1(String m) { return null; } | 3443 static T m1(String m) { return null; } |
| 3464 static String m2(e) { return ''; } | 3444 static String m2(e) { return ''; } |
| 3465 } | 3445 } |
| 3466 '''); | 3446 '''); |
| 3467 } | 3447 } |
| 3468 | 3448 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3557 c = /*error:INVALID_ASSIGNMENT*/"hi"; | 3537 c = /*error:INVALID_ASSIGNMENT*/"hi"; |
| 3558 c = 4; | 3538 c = 4; |
| 3559 } | 3539 } |
| 3560 | 3540 |
| 3561 int y = 0; // field def after use | 3541 int y = 0; // field def after use |
| 3562 final z = 42; // should infer `int` | 3542 final z = 42; // should infer `int` |
| 3563 '''); | 3543 '''); |
| 3564 } | 3544 } |
| 3565 | 3545 |
| 3566 test_inferTypeRegardlessOfDeclarationOrderOrCycles() async { | 3546 test_inferTypeRegardlessOfDeclarationOrderOrCycles() async { |
| 3567 addFile( | 3547 addFile(''' |
| 3568 ''' | |
| 3569 import 'main.dart'; | 3548 import 'main.dart'; |
| 3570 | 3549 |
| 3571 class B extends A { } | 3550 class B extends A { } |
| 3572 ''', | 3551 ''', name: '/b.dart'); |
| 3573 name: '/b.dart'); | |
| 3574 await checkFileElement(''' | 3552 await checkFileElement(''' |
| 3575 import 'b.dart'; | 3553 import 'b.dart'; |
| 3576 class C extends B { | 3554 class C extends B { |
| 3577 get x => null; | 3555 get x => null; |
| 3578 } | 3556 } |
| 3579 class A { | 3557 class A { |
| 3580 int get x => 0; | 3558 int get x => 0; |
| 3581 } | 3559 } |
| 3582 foo() { | 3560 foo() { |
| 3583 int y = new C().x; | 3561 int y = new C().x; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3666 String y = /*info:DYNAMIC_CAST*/new B().x; | 3644 String y = /*info:DYNAMIC_CAST*/new B().x; |
| 3667 int z = /*info:DYNAMIC_CAST*/new B().x; | 3645 int z = /*info:DYNAMIC_CAST*/new B().x; |
| 3668 } | 3646 } |
| 3669 '''); | 3647 '''); |
| 3670 } | 3648 } |
| 3671 | 3649 |
| 3672 test_inferTypesOnGenericInstantiationsInLibraryCycle() async { | 3650 test_inferTypesOnGenericInstantiationsInLibraryCycle() async { |
| 3673 // Note: this is a regression test for a non-deterministic behavior we used
to | 3651 // Note: this is a regression test for a non-deterministic behavior we used
to |
| 3674 // have with inference in library cycles. If you see this test flake out, | 3652 // have with inference in library cycles. If you see this test flake out, |
| 3675 // change `test` to `skip_test` and reopen bug #48. | 3653 // change `test` to `skip_test` and reopen bug #48. |
| 3676 addFile( | 3654 addFile(''' |
| 3677 ''' | |
| 3678 import 'main.dart'; | 3655 import 'main.dart'; |
| 3679 abstract class I<E> { | 3656 abstract class I<E> { |
| 3680 A<E> m(a, String f(v, int e)); | 3657 A<E> m(a, String f(v, int e)); |
| 3681 } | 3658 } |
| 3682 ''', | 3659 ''', name: '/a.dart'); |
| 3683 name: '/a.dart'); | |
| 3684 await checkFileElement(''' | 3660 await checkFileElement(''' |
| 3685 import 'a.dart'; | 3661 import 'a.dart'; |
| 3686 | 3662 |
| 3687 abstract class A<E> implements I<E> { | 3663 abstract class A<E> implements I<E> { |
| 3688 const A(); | 3664 const A(); |
| 3689 | 3665 |
| 3690 final E value = null; | 3666 final E value = null; |
| 3691 } | 3667 } |
| 3692 | 3668 |
| 3693 abstract class M { | 3669 abstract class M { |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4846 .test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr
2(); | 4822 .test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr
2(); |
| 4847 } | 4823 } |
| 4848 | 4824 |
| 4849 @failingTest | 4825 @failingTest |
| 4850 @override | 4826 @override |
| 4851 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr2_comme
nt() async { | 4827 test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr2_comme
nt() async { |
| 4852 await super | 4828 await super |
| 4853 .test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr
2_comment(); | 4829 .test_unsafeBlockClosureInference_functionCall_explicitTypeParam_viaExpr
2_comment(); |
| 4854 } | 4830 } |
| 4855 } | 4831 } |
| OLD | NEW |