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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 } | 633 } |
634 class F_error extends E { | 634 class F_error extends E { |
635 /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0; | 635 /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0; |
636 } | 636 } |
637 class G_error extends E implements D { | 637 class G_error extends E implements D { |
638 /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0; | 638 /*error:INVALID_METHOD_OVERRIDE*/int f(double x) => 0; |
639 } | 639 } |
640 '''); | 640 '''); |
641 } | 641 } |
642 | 642 |
643 test_dynamicInvocation() async { | 643 test_dynamicInvocation() { |
644 await checkFile(''' | 644 return checkFile(r''' |
645 typedef dynamic A(dynamic x); | 645 typedef dynamic A(dynamic x); |
646 class B { | 646 class B { |
647 int call(int x) => x; | 647 int call(int x) => x; |
648 double col(double x) => x; | 648 double col(double x) => x; |
649 } | 649 } |
650 void main() { | 650 void main() { |
651 { | 651 { |
652 B f = new B(); | 652 B f = new B(); |
653 int x; | 653 int x; |
654 double y; | 654 double y; |
655 x = f(3); | 655 x = f(3); |
656 x = /*error:INVALID_ASSIGNMENT*/f.col(3.0); | 656 x = /*error:INVALID_ASSIGNMENT*/f.col(3.0); |
657 y = /*error:INVALID_ASSIGNMENT*/f(3); | 657 y = /*error:INVALID_ASSIGNMENT*/f(3); |
658 y = f.col(3.0); | 658 y = f.col(3.0); |
659 f(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3.0); | 659 f(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3.0); |
660 f.col(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3); | 660 f.col(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3); |
661 } | 661 } |
662 { | 662 { |
663 Function f = new B(); | 663 Function f = new B(); |
664 int x; | 664 int x; |
665 double y; | 665 double y; |
666 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); | 666 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
667 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0); | 667 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/co
l(3.0); |
668 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); | 668 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
669 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f.col(3.0); | 669 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/co
l(3.0); |
670 /*info:DYNAMIC_INVOKE*/f(3.0); | 670 /*info:DYNAMIC_INVOKE*/f(3.0); |
671 // Through type propagation, we know f is actually a B, hence the | 671 // Through type propagation, we know f is actually a B, hence the |
672 // hint. | 672 // hint. |
673 /*info:DYNAMIC_INVOKE*/f.col(3); | 673 /*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/col(3); |
674 } | 674 } |
675 { | 675 { |
676 A f = new B(); | 676 A f = new B(); |
677 int x; | 677 int x; |
678 double y; | 678 double y; |
679 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); | 679 x = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
680 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); | 680 y = /*info:DYNAMIC_CAST, info:DYNAMIC_INVOKE*/f(3); |
681 /*info:DYNAMIC_INVOKE*/f(3.0); | 681 /*info:DYNAMIC_INVOKE*/f(3.0); |
682 } | 682 } |
683 { | 683 { |
684 dynamic g = new B(); | 684 dynamic g = new B(); |
685 /*info:DYNAMIC_INVOKE*/g.call(32.0); | 685 /*info:DYNAMIC_INVOKE*/g.call(32.0); |
686 /*info:DYNAMIC_INVOKE*/g.col(42.0); | 686 /*info:DYNAMIC_INVOKE*/g.col(42.0); |
687 /*info:DYNAMIC_INVOKE*/g.foo(42.0); | 687 /*info:DYNAMIC_INVOKE*/g.foo(42.0); |
688 /*info:DYNAMIC_INVOKE*/g.x; | 688 /*info:DYNAMIC_INVOKE*/g.x; |
689 A f = new B(); | 689 A f = new B(); |
690 /*info:DYNAMIC_INVOKE*/f.col(42.0); | 690 /*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/col(42.0); |
691 /*info:DYNAMIC_INVOKE*/f.foo(42.0); | 691 /*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_METHOD*/foo(42.0); |
692 /*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_GETTER*/x; | 692 /*info:DYNAMIC_INVOKE*/f./*error:UNDEFINED_GETTER*/x; |
693 } | 693 } |
694 } | 694 } |
695 '''); | 695 '''); |
696 } | 696 } |
697 | 697 |
698 test_factoryConstructorDowncast() async { | 698 test_factoryConstructorDowncast() async { |
699 await checkFile(r''' | 699 await checkFile(r''' |
700 class Animal { | 700 class Animal { |
701 Animal(); | 701 Animal(); |
(...skipping 2667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3369 class Child extends helper.Base { | 3369 class Child extends helper.Base { |
3370 var f1; | 3370 var f1; |
3371 var _f2; | 3371 var _f2; |
3372 var _f4; | 3372 var _f4; |
3373 | 3373 |
3374 String _m1() => null; | 3374 String _m1() => null; |
3375 } | 3375 } |
3376 '''); | 3376 '''); |
3377 } | 3377 } |
3378 | 3378 |
3379 test_proxy() async { | 3379 test_proxy() { |
3380 await checkFile(r''' | 3380 return checkFile(r''' |
3381 @proxy class C {} | 3381 @proxy class C {} |
3382 @proxy class D { | 3382 @proxy class D { |
3383 var f; | 3383 var f; |
3384 m() => null; | 3384 m() => null; |
3385 operator -() => null; | 3385 operator -() => null; |
3386 operator +(int other) => null; | 3386 operator +(int other) => null; |
3387 operator [](int index) => null; | 3387 operator [](int index) => null; |
3388 call() => null; | 3388 call() => null; |
3389 } | 3389 } |
3390 @proxy class F implements Function { noSuchMethod(i) => 42; } | 3390 @proxy class F implements Function { noSuchMethod(i) => 42; } |
3391 | 3391 |
3392 | 3392 |
3393 m() { | 3393 m() { |
3394 D d = new D(); | 3394 D d = new D(); |
3395 d.m(); | 3395 d.m(); |
3396 d.m; | 3396 d.m; |
3397 d.f; | 3397 d.f; |
3398 -d; | 3398 -d; |
3399 d + 7; | 3399 d + 7; |
3400 d[7]; | 3400 d[7]; |
3401 d(); | 3401 d(); |
3402 | 3402 |
3403 C c = new C(); | 3403 C c = new C(); |
3404 /*info:DYNAMIC_INVOKE*/c.m(); | 3404 /*info:DYNAMIC_INVOKE*/c./*error:UNDEFINED_METHOD*/m(); |
3405 /*info:DYNAMIC_INVOKE*/c.m; | 3405 /*info:DYNAMIC_INVOKE*/c./*error:UNDEFINED_GETTER*/m; |
3406 /*info:DYNAMIC_INVOKE*/-c; | 3406 /*info:DYNAMIC_INVOKE,error:UNDEFINED_OPERATOR*/-c; |
3407 /*info:DYNAMIC_INVOKE*/c + 7; | 3407 /*info:DYNAMIC_INVOKE*/c /*error:UNDEFINED_OPERATOR*/+ 7; |
3408 /*info:DYNAMIC_INVOKE*/c[7]; | 3408 /*info:DYNAMIC_INVOKE*/c /*error:UNDEFINED_OPERATOR*/[7]; |
3409 /*error:INVOCATION_OF_NON_FUNCTION,info:DYNAMIC_INVOKE*/c(); | 3409 /*error:INVOCATION_OF_NON_FUNCTION,info:DYNAMIC_INVOKE*/c(); |
3410 | 3410 |
3411 F f = new F(); | 3411 F f = new F(); |
3412 /*info:DYNAMIC_INVOKE*/f(); | 3412 /*error:INVOCATION_OF_NON_FUNCTION,info:DYNAMIC_INVOKE*/f(); |
3413 } | 3413 } |
3414 '''); | 3414 '''); |
3415 } | 3415 } |
3416 | 3416 |
3417 test_redirectingConstructor() async { | 3417 test_redirectingConstructor() async { |
3418 await checkFile(''' | 3418 await checkFile(''' |
3419 class A { | 3419 class A { |
3420 A(A x) {} | 3420 A(A x) {} |
3421 A.two() : this(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3); | 3421 A.two() : this(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/3); |
3422 } | 3422 } |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3888 test_typePromotionFromTypeParameter() async { | 3888 test_typePromotionFromTypeParameter() async { |
3889 // Regression test for: | 3889 // Regression test for: |
3890 // https://github.com/dart-lang/sdk/issues/26965 | 3890 // https://github.com/dart-lang/sdk/issues/26965 |
3891 // https://github.com/dart-lang/sdk/issues/27040 | 3891 // https://github.com/dart-lang/sdk/issues/27040 |
3892 await checkFile(r''' | 3892 await checkFile(r''' |
3893 void f/*<T>*/(/*=T*/ object) { | 3893 void f/*<T>*/(/*=T*/ object) { |
3894 if (object is String) print(object.substring(1)); | 3894 if (object is String) print(object.substring(1)); |
3895 } | 3895 } |
3896 void g/*<T extends num>*/(/*=T*/ object) { | 3896 void g/*<T extends num>*/(/*=T*/ object) { |
3897 if (object is int) print(object.isEven); | 3897 if (object is int) print(object.isEven); |
3898 if (object is String) print(/*info:DYNAMIC_INVOKE*/object.substring(1)); | 3898 if (object is String) print(/*info:DYNAMIC_INVOKE*/object./*error:UNDEFINED_ME
THOD*/substring(1)); |
3899 } | 3899 } |
3900 class Clonable<T> {} | 3900 class Clonable<T> {} |
3901 class SubClonable<T> extends Clonable<T> { | 3901 class SubClonable<T> extends Clonable<T> { |
3902 T m(T t) => t; | 3902 T m(T t) => t; |
3903 } | 3903 } |
3904 void takesSubClonable/*<A>*/(SubClonable/*<A>*/ t) {} | 3904 void takesSubClonable/*<A>*/(SubClonable/*<A>*/ t) {} |
3905 | 3905 |
3906 void h/*<T extends Clonable<T>>*/(/*=T*/ object) { | 3906 void h/*<T extends Clonable<T>>*/(/*=T*/ object) { |
3907 if (/*info:NON_GROUND_TYPE_CHECK_INFO*/object is SubClonable/*<T>*/) { | 3907 if (/*info:NON_GROUND_TYPE_CHECK_INFO*/object is SubClonable/*<T>*/) { |
3908 print(object.m(object)); | 3908 print(object.m(object)); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4201 class CheckerTest_Driver extends CheckerTest { | 4201 class CheckerTest_Driver extends CheckerTest { |
4202 @override | 4202 @override |
4203 bool get enableNewAnalysisDriver => true; | 4203 bool get enableNewAnalysisDriver => true; |
4204 | 4204 |
4205 @failingTest | 4205 @failingTest |
4206 @override | 4206 @override |
4207 test_covariantOverride_fields() async { | 4207 test_covariantOverride_fields() async { |
4208 await super.test_covariantOverride_fields(); | 4208 await super.test_covariantOverride_fields(); |
4209 } | 4209 } |
4210 } | 4210 } |
OLD | NEW |