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 'package:test_reflective_loader/test_reflective_loader.dart'; | 7 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
8 | 8 |
9 import 'strong_test_helper.dart'; | 9 import 'strong_test_helper.dart'; |
10 | 10 |
(...skipping 2733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2744 f = /*info:UNNECESSARY_CAST*/bar as DD2D; | 2744 f = /*info:UNNECESSARY_CAST*/bar as DD2D; |
2745 } | 2745 } |
2746 '''); | 2746 '''); |
2747 } | 2747 } |
2748 | 2748 |
2749 void test_leastUpperBounds() { | 2749 void test_leastUpperBounds() { |
2750 checkFile(''' | 2750 checkFile(''' |
2751 typedef T Returns<T>(); | 2751 typedef T Returns<T>(); |
2752 | 2752 |
2753 // regression test for https://github.com/dart-lang/sdk/issues/26094 | 2753 // regression test for https://github.com/dart-lang/sdk/issues/26094 |
2754 class A <S extends Returns<S>, T extends Returns<T>> { | 2754 class A <S extends Returns<S>, T extends Returns<T>> { |
2755 int test(bool b) { | 2755 int test(bool b) { |
2756 S s; | 2756 S s; |
2757 T t; | 2757 T t; |
2758 if (b) { | 2758 if (b) { |
2759 return /*error:RETURN_OF_INVALID_TYPE*/b ? s : t; | 2759 return /*error:RETURN_OF_INVALID_TYPE*/b ? s : t; |
2760 } else { | 2760 } else { |
2761 return /*error:RETURN_OF_INVALID_TYPE*/s ?? t; | 2761 return /*error:RETURN_OF_INVALID_TYPE*/s ?? t; |
2762 } | 2762 } |
2763 } | 2763 } |
2764 } | 2764 } |
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3714 Object x; | 3714 Object x; |
3715 if (x is int) { | 3715 if (x is int) { |
3716 int y = x; | 3716 int y = x; |
3717 String z = /*error:INVALID_ASSIGNMENT*/x; | 3717 String z = /*error:INVALID_ASSIGNMENT*/x; |
3718 } | 3718 } |
3719 } | 3719 } |
3720 '''); | 3720 '''); |
3721 } | 3721 } |
3722 | 3722 |
3723 void test_typePromotionFromTypeParameter() { | 3723 void test_typePromotionFromTypeParameter() { |
3724 // Regression test for https://github.com/dart-lang/sdk/issues/26965 | 3724 // Regression test for: |
3725 // https://github.com/dart-lang/sdk/issues/26965 | |
3726 // https://github.com/dart-lang/sdk/issues/27040 | |
3725 checkFile(r''' | 3727 checkFile(r''' |
3726 void f/*<T>*/(/*=T*/ object) { | 3728 void f/*<T>*/(/*=T*/ object) { |
3727 if (object is String) print(object.substring(1)); | 3729 if (object is String) print(object.substring(1)); |
3728 } | 3730 } |
3729 void g/*<T extends num>*/(/*=T*/ object) { | 3731 void g/*<T extends num>*/(/*=T*/ object) { |
3730 if (object is int) print(object.isEven); | 3732 if (object is int) print(object.isEven); |
3731 if (object is String) print(/*info:DYNAMIC_INVOKE*/object.substring(1)); | 3733 if (object is String) print(/*info:DYNAMIC_INVOKE*/object.substring(1)); |
3732 } | 3734 } |
3733 class Clonable<T> {} | 3735 class Clonable<T> {} |
3734 class SubClonable<T> extends Clonable<T> { | 3736 class SubClonable<T> extends Clonable<T> { |
3735 T m(T t) => t; | 3737 T m(T t) => t; |
3736 } | 3738 } |
3739 void takesSubClonable/*<A>*/(SubClonable/*<A>*/ t) {} | |
3740 | |
3737 void h/*<T extends Clonable<T>>*/(/*=T*/ object) { | 3741 void h/*<T extends Clonable<T>>*/(/*=T*/ object) { |
3738 if (/*info:NON_GROUND_TYPE_CHECK_INFO*/object is SubClonable/*<T>*/) { | 3742 if (/*info:NON_GROUND_TYPE_CHECK_INFO*/object is SubClonable/*<T>*/) { |
3739 // Note we need to cast back to T, because promotion lost that type info. | 3743 print(object.m(object)); |
3740 print(object.m(object as dynamic/*=T*/)); | 3744 |
3745 SubClonable/*<T>*/ s = object; | |
3746 takesSubClonable/*<T>*/(object); | |
3747 h(object); | |
3741 } | 3748 } |
3742 } | 3749 } |
3743 '''); | 3750 '''); |
3744 } | 3751 } |
3745 | 3752 |
3753 void test_typePromotionFromTypeParameterAndInference() { | |
3754 // Regression test for: | |
3755 // https://github.com/dart-lang/sdk/issues/27040 | |
3756 checkFile(r''' | |
3757 void f/*<T extends num>*/(T x, T y) { | |
3758 var z = x; | |
3759 var f = () => x; | |
3760 f = () => y; | |
3761 if (x is int) { | |
3762 /*info:DYNAMIC_INVOKE*/z./*error:UNDEFINED_GETTER*/isEven; | |
3763 var q = x; | |
3764 q = /*warning:DOWN_CAST_COMPOSITE*/z; | |
3765 /*info:DYNAMIC_INVOKE*/f()./*error:UNDEFINED_GETTER*/isEven; | |
3766 | |
3767 // This does not capture the type `T extends int`. Instead the return type | |
3768 // is `T extends num`. What happens is we substitute {T/T} on the function | |
3769 // type, and the way it is implemented, this leads back to `T extends num`. | |
Leaf
2016/11/01 17:54:52
This is kind of a bug. Maybe file an issue and add
Jennifer Messerly
2016/11/02 01:17:08
done: https://github.com/dart-lang/sdk/issues/2772
| |
3770 var g = () => x; | |
3771 g = f; | |
3772 /*info:DYNAMIC_INVOKE*/g()./*error:UNDEFINED_GETTER*/isEven; | |
3773 q = /*warning:DOWN_CAST_COMPOSITE*/g(); | |
3774 int r = x; | |
3775 } | |
3776 } | |
3777 '''); | |
3778 } | |
3779 | |
3746 void test_typeSubtyping_assigningClass() { | 3780 void test_typeSubtyping_assigningClass() { |
3747 checkFile(''' | 3781 checkFile(''' |
3748 class A {} | 3782 class A {} |
3749 class B extends A {} | 3783 class B extends A {} |
3750 | 3784 |
3751 void main() { | 3785 void main() { |
3752 dynamic y; | 3786 dynamic y; |
3753 Object o; | 3787 Object o; |
3754 int i = 0; | 3788 int i = 0; |
3755 double d = 0.0; | 3789 double d = 0.0; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3960 // Regression test for https://github.com/dart-lang/sdk/issues/25069 | 3994 // Regression test for https://github.com/dart-lang/sdk/issues/25069 |
3961 checkFile(''' | 3995 checkFile(''' |
3962 typedef int Foo(); | 3996 typedef int Foo(); |
3963 void foo() {} | 3997 void foo() {} |
3964 void main () { | 3998 void main () { |
3965 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); | 3999 Foo x = /*error:INVALID_ASSIGNMENT,info:USE_OF_VOID_RESULT*/foo(); |
3966 } | 4000 } |
3967 '''); | 4001 '''); |
3968 } | 4002 } |
3969 } | 4003 } |
OLD | NEW |