| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.generated.simple_resolver_test; | 5 library analyzer.test.generated.simple_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 390 } |
| 391 | 391 |
| 392 void test_class_definesCall() { | 392 void test_class_definesCall() { |
| 393 Source source = addSource(r''' | 393 Source source = addSource(r''' |
| 394 class A { | 394 class A { |
| 395 int call(int x) { return x; } | 395 int call(int x) { return x; } |
| 396 } | 396 } |
| 397 int f(A a) { | 397 int f(A a) { |
| 398 return a(0); | 398 return a(0); |
| 399 }'''); | 399 }'''); |
| 400 computeLibrarySourceErrors(source); | |
| 401 assertNoErrors(source); | 400 assertNoErrors(source); |
| 402 verify([source]); | 401 verify([source]); |
| 403 } | 402 } |
| 404 | 403 |
| 405 void test_class_extends_implements() { | 404 void test_class_extends_implements() { |
| 406 Source source = addSource(r''' | 405 Source source = addSource(r''' |
| 407 class A extends B implements C {} | 406 class A extends B implements C {} |
| 408 class B {} | 407 class B {} |
| 409 class C {}'''); | 408 class C {}'''); |
| 410 computeLibrarySourceErrors(source); | |
| 411 assertNoErrors(source); | 409 assertNoErrors(source); |
| 412 verify([source]); | 410 verify([source]); |
| 413 } | 411 } |
| 414 | 412 |
| 415 void test_commentReference_class() { | 413 void test_commentReference_class() { |
| 416 Source source = addSource(r''' | 414 Source source = addSource(r''' |
| 417 f() {} | 415 f() {} |
| 418 /** [A] [new A] [A.n] [new A.n] [m] [f] */ | 416 /** [A] [new A] [A.n] [new A.n] [m] [f] */ |
| 419 class A { | 417 class A { |
| 420 A() {} | 418 A() {} |
| 421 A.n() {} | 419 A.n() {} |
| 422 m() {} | 420 m() {} |
| 423 }'''); | 421 }'''); |
| 424 computeLibrarySourceErrors(source); | |
| 425 assertNoErrors(source); | 422 assertNoErrors(source); |
| 426 verify([source]); | 423 verify([source]); |
| 427 } | 424 } |
| 428 | 425 |
| 429 void test_commentReference_parameter() { | 426 void test_commentReference_parameter() { |
| 430 Source source = addSource(r''' | 427 Source source = addSource(r''' |
| 431 class A { | 428 class A { |
| 432 A() {} | 429 A() {} |
| 433 A.n() {} | 430 A.n() {} |
| 434 /** [e] [f] */ | 431 /** [e] [f] */ |
| 435 m(e, f()) {} | 432 m(e, f()) {} |
| 436 }'''); | 433 }'''); |
| 437 computeLibrarySourceErrors(source); | |
| 438 assertNoErrors(source); | 434 assertNoErrors(source); |
| 439 verify([source]); | 435 verify([source]); |
| 440 } | 436 } |
| 441 | 437 |
| 442 void test_commentReference_singleLine() { | 438 void test_commentReference_singleLine() { |
| 443 Source source = addSource(r''' | 439 Source source = addSource(r''' |
| 444 /// [A] | 440 /// [A] |
| 445 class A {}'''); | 441 class A {}'''); |
| 446 computeLibrarySourceErrors(source); | |
| 447 assertNoErrors(source); | 442 assertNoErrors(source); |
| 448 verify([source]); | 443 verify([source]); |
| 449 } | 444 } |
| 450 | 445 |
| 451 void test_continueTarget_labeled() { | 446 void test_continueTarget_labeled() { |
| 452 // Verify that the target of the label is correctly found and is recorded | 447 // Verify that the target of the label is correctly found and is recorded |
| 453 // as the unlabeled portion of the statement. | 448 // as the unlabeled portion of the statement. |
| 454 String text = r''' | 449 String text = r''' |
| 455 void f() { | 450 void f() { |
| 456 loop1: while (true) { | 451 loop1: while (true) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 } | 565 } |
| 571 '''; | 566 '''; |
| 572 CompilationUnit unit = resolveSource(text); | 567 CompilationUnit unit = resolveSource(text); |
| 573 ContinueStatement continueStatement = EngineTestCase.findNode( | 568 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 574 unit, text, 'continue', (n) => n is ContinueStatement); | 569 unit, text, 'continue', (n) => n is ContinueStatement); |
| 575 expect(continueStatement.target, isNull); | 570 expect(continueStatement.target, isNull); |
| 576 } | 571 } |
| 577 | 572 |
| 578 void test_empty() { | 573 void test_empty() { |
| 579 Source source = addSource(""); | 574 Source source = addSource(""); |
| 580 computeLibrarySourceErrors(source); | |
| 581 assertNoErrors(source); | 575 assertNoErrors(source); |
| 582 verify([source]); | 576 verify([source]); |
| 583 } | 577 } |
| 584 | 578 |
| 585 void test_entryPoint_exported() { | 579 void test_entryPoint_exported() { |
| 586 addNamedSource( | 580 addNamedSource( |
| 587 "/two.dart", | 581 "/two.dart", |
| 588 r''' | 582 r''' |
| 589 library two; | 583 library two; |
| 590 main() {}'''); | 584 main() {}'''); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 addNamedSource( | 624 addNamedSource( |
| 631 "/my_lib.dart", | 625 "/my_lib.dart", |
| 632 r''' | 626 r''' |
| 633 library my_lib; | 627 library my_lib; |
| 634 enum EEE {A, B, C}'''); | 628 enum EEE {A, B, C}'''); |
| 635 Source source = addSource(r''' | 629 Source source = addSource(r''' |
| 636 import 'my_lib.dart'; | 630 import 'my_lib.dart'; |
| 637 main() { | 631 main() { |
| 638 EEE e = null; | 632 EEE e = null; |
| 639 }'''); | 633 }'''); |
| 640 computeLibrarySourceErrors(source); | |
| 641 assertNoErrors(source); | 634 assertNoErrors(source); |
| 642 verify([source]); | 635 verify([source]); |
| 643 } | 636 } |
| 644 | 637 |
| 645 void test_extractedMethodAsConstant() { | 638 void test_extractedMethodAsConstant() { |
| 646 Source source = addSource(r''' | 639 Source source = addSource(r''' |
| 647 abstract class Comparable<T> { | 640 abstract class Comparable<T> { |
| 648 int compareTo(T other); | 641 int compareTo(T other); |
| 649 static int compare(Comparable a, Comparable b) => a.compareTo(b); | 642 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 650 } | 643 } |
| 651 class A { | 644 class A { |
| 652 void sort([compare = Comparable.compare]) {} | 645 void sort([compare = Comparable.compare]) {} |
| 653 }'''); | 646 }'''); |
| 654 computeLibrarySourceErrors(source); | |
| 655 assertNoErrors(source); | 647 assertNoErrors(source); |
| 656 verify([source]); | 648 verify([source]); |
| 657 } | 649 } |
| 658 | 650 |
| 659 void test_fieldFormalParameter() { | 651 void test_fieldFormalParameter() { |
| 660 Source source = addSource(r''' | 652 Source source = addSource(r''' |
| 661 class A { | 653 class A { |
| 662 int x; | 654 int x; |
| 663 int y; | 655 int y; |
| 664 A(this.x) : y = x {} | 656 A(this.x) : y = x {} |
| 665 }'''); | 657 }'''); |
| 666 CompilationUnit unit = | 658 CompilationUnit unit = |
| 667 analysisContext2.resolveCompilationUnit2(source, source); | 659 analysisContext2.resolveCompilationUnit2(source, source); |
| 668 ClassDeclaration classA = unit.declarations[0]; | 660 ClassDeclaration classA = unit.declarations[0]; |
| 669 FieldDeclaration field = classA.members[0]; | 661 FieldDeclaration field = classA.members[0]; |
| 670 ConstructorDeclaration constructor = classA.members[2]; | 662 ConstructorDeclaration constructor = classA.members[2]; |
| 671 ParameterElement paramElement = | 663 ParameterElement paramElement = |
| 672 constructor.parameters.parameters[0].element; | 664 constructor.parameters.parameters[0].element; |
| 673 expect(paramElement, new isInstanceOf<FieldFormalParameterElement>()); | 665 expect(paramElement, new isInstanceOf<FieldFormalParameterElement>()); |
| 674 expect((paramElement as FieldFormalParameterElement).field, | 666 expect((paramElement as FieldFormalParameterElement).field, |
| 675 field.fields.variables[0].element); | 667 field.fields.variables[0].element); |
| 676 ConstructorFieldInitializer initializer = constructor.initializers[0]; | 668 ConstructorFieldInitializer initializer = constructor.initializers[0]; |
| 677 SimpleIdentifier identifierX = initializer.expression; | 669 SimpleIdentifier identifierX = initializer.expression; |
| 678 expect(identifierX.staticElement, paramElement); | 670 expect(identifierX.staticElement, paramElement); |
| 679 | 671 |
| 680 computeLibrarySourceErrors(source); | |
| 681 assertNoErrors(source); | 672 assertNoErrors(source); |
| 682 verify([source]); | 673 verify([source]); |
| 683 } | 674 } |
| 684 | 675 |
| 685 void test_forEachLoops_nonConflicting() { | 676 void test_forEachLoops_nonConflicting() { |
| 686 Source source = addSource(r''' | 677 Source source = addSource(r''' |
| 687 f() { | 678 f() { |
| 688 List list = [1,2,3]; | 679 List list = [1,2,3]; |
| 689 for (int x in list) {} | 680 for (int x in list) {} |
| 690 for (int x in list) {} | 681 for (int x in list) {} |
| 691 }'''); | 682 }'''); |
| 692 computeLibrarySourceErrors(source); | |
| 693 assertNoErrors(source); | 683 assertNoErrors(source); |
| 694 verify([source]); | 684 verify([source]); |
| 695 } | 685 } |
| 696 | 686 |
| 697 void test_forLoops_nonConflicting() { | 687 void test_forLoops_nonConflicting() { |
| 698 Source source = addSource(r''' | 688 Source source = addSource(r''' |
| 699 f() { | 689 f() { |
| 700 for (int i = 0; i < 3; i++) { | 690 for (int i = 0; i < 3; i++) { |
| 701 } | 691 } |
| 702 for (int i = 0; i < 3; i++) { | 692 for (int i = 0; i < 3; i++) { |
| 703 } | 693 } |
| 704 }'''); | 694 }'''); |
| 705 computeLibrarySourceErrors(source); | |
| 706 assertNoErrors(source); | 695 assertNoErrors(source); |
| 707 verify([source]); | 696 verify([source]); |
| 708 } | 697 } |
| 709 | 698 |
| 710 void test_functionTypeAlias() { | 699 void test_functionTypeAlias() { |
| 711 Source source = addSource(r''' | 700 Source source = addSource(r''' |
| 712 typedef bool P(e); | 701 typedef bool P(e); |
| 713 class A { | 702 class A { |
| 714 P p; | 703 P p; |
| 715 m(e) { | 704 m(e) { |
| 716 if (p(e)) {} | 705 if (p(e)) {} |
| 717 } | 706 } |
| 718 }'''); | 707 }'''); |
| 719 computeLibrarySourceErrors(source); | |
| 720 assertNoErrors(source); | 708 assertNoErrors(source); |
| 721 verify([source]); | 709 verify([source]); |
| 722 } | 710 } |
| 723 | 711 |
| 724 void test_getter_and_setter_fromMixins_bare_identifier() { | 712 void test_getter_and_setter_fromMixins_bare_identifier() { |
| 725 Source source = addSource(''' | 713 Source source = addSource(''' |
| 726 class B {} | 714 class B {} |
| 727 class M1 { | 715 class M1 { |
| 728 get x => null; | 716 get x => null; |
| 729 set x(value) {} | 717 set x(value) {} |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 | 853 |
| 866 void test_getterAndSetterWithDifferentTypes() { | 854 void test_getterAndSetterWithDifferentTypes() { |
| 867 Source source = addSource(r''' | 855 Source source = addSource(r''' |
| 868 class A { | 856 class A { |
| 869 int get f => 0; | 857 int get f => 0; |
| 870 void set f(String s) {} | 858 void set f(String s) {} |
| 871 } | 859 } |
| 872 g (A a) { | 860 g (A a) { |
| 873 a.f = a.f.toString(); | 861 a.f = a.f.toString(); |
| 874 }'''); | 862 }'''); |
| 875 computeLibrarySourceErrors(source); | |
| 876 assertErrors( | 863 assertErrors( |
| 877 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); | 864 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); |
| 878 verify([source]); | 865 verify([source]); |
| 879 } | 866 } |
| 880 | 867 |
| 881 void test_hasReferenceToSuper() { | 868 void test_hasReferenceToSuper() { |
| 882 Source source = addSource(r''' | 869 Source source = addSource(r''' |
| 883 class A {} | 870 class A {} |
| 884 class B {toString() => super.toString();}'''); | 871 class B {toString() => super.toString();}'''); |
| 885 LibraryElement library = resolve2(source); | 872 LibraryElement library = resolve2(source); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 909 Source source = addNamedSource( | 896 Source source = addNamedSource( |
| 910 "/lib3.dart", | 897 "/lib3.dart", |
| 911 r''' | 898 r''' |
| 912 import 'lib1.dart' hide foo; | 899 import 'lib1.dart' hide foo; |
| 913 import 'lib2.dart'; | 900 import 'lib2.dart'; |
| 914 | 901 |
| 915 main() { | 902 main() { |
| 916 foo = 0; | 903 foo = 0; |
| 917 } | 904 } |
| 918 A a;'''); | 905 A a;'''); |
| 919 computeLibrarySourceErrors(source); | |
| 920 assertNoErrors(source); | 906 assertNoErrors(source); |
| 921 verify([source]); | 907 verify([source]); |
| 922 } | 908 } |
| 923 | 909 |
| 924 void test_import_prefix() { | 910 void test_import_prefix() { |
| 925 addNamedSource( | 911 addNamedSource( |
| 926 "/two.dart", | 912 "/two.dart", |
| 927 r''' | 913 r''' |
| 928 library two; | 914 library two; |
| 929 f(int x) { | 915 f(int x) { |
| 930 return x * x; | 916 return x * x; |
| 931 }'''); | 917 }'''); |
| 932 Source source = addNamedSource( | 918 Source source = addNamedSource( |
| 933 "/one.dart", | 919 "/one.dart", |
| 934 r''' | 920 r''' |
| 935 library one; | 921 library one; |
| 936 import 'two.dart' as _two; | 922 import 'two.dart' as _two; |
| 937 main() { | 923 main() { |
| 938 _two.f(0); | 924 _two.f(0); |
| 939 }'''); | 925 }'''); |
| 940 computeLibrarySourceErrors(source); | |
| 941 assertNoErrors(source); | 926 assertNoErrors(source); |
| 942 verify([source]); | 927 verify([source]); |
| 943 } | 928 } |
| 944 | 929 |
| 945 void test_import_prefix_doesNotExist() { | 930 void test_import_prefix_doesNotExist() { |
| 946 // | 931 // |
| 947 // The primary purpose of this test is to ensure that we are only getting a | 932 // The primary purpose of this test is to ensure that we are only getting a |
| 948 // single error generated when the only problem is that an imported file | 933 // single error generated when the only problem is that an imported file |
| 949 // does not exist. | 934 // does not exist. |
| 950 // | 935 // |
| 951 Source source = addNamedSource( | 936 Source source = addNamedSource( |
| 952 "/a.dart", | 937 "/a.dart", |
| 953 r''' | 938 r''' |
| 954 import 'missing.dart' as p; | 939 import 'missing.dart' as p; |
| 955 int a = p.q + p.r.s; | 940 int a = p.q + p.r.s; |
| 956 String b = p.t(a) + p.u(v: 0); | 941 String b = p.t(a) + p.u(v: 0); |
| 957 p.T c = new p.T(); | 942 p.T c = new p.T(); |
| 958 class D<E> extends p.T { | 943 class D<E> extends p.T { |
| 959 D(int i) : super(i); | 944 D(int i) : super(i); |
| 960 p.U f = new p.V(); | 945 p.U f = new p.V(); |
| 961 } | 946 } |
| 962 class F implements p.T { | 947 class F implements p.T { |
| 963 p.T m(p.U u) => null; | 948 p.T m(p.U u) => null; |
| 964 } | 949 } |
| 965 class G extends Object with p.V {} | 950 class G extends Object with p.V {} |
| 966 class H extends D<p.W> { | 951 class H extends D<p.W> { |
| 967 H(int i) : super(i); | 952 H(int i) : super(i); |
| 968 } | 953 } |
| 969 '''); | 954 '''); |
| 970 computeLibrarySourceErrors(source); | |
| 971 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 955 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 972 verify([source]); | 956 verify([source]); |
| 973 } | 957 } |
| 974 | 958 |
| 975 void test_import_show_doesNotExist() { | 959 void test_import_show_doesNotExist() { |
| 976 // | 960 // |
| 977 // The primary purpose of this test is to ensure that we are only getting a | 961 // The primary purpose of this test is to ensure that we are only getting a |
| 978 // single error generated when the only problem is that an imported file | 962 // single error generated when the only problem is that an imported file |
| 979 // does not exist. | 963 // does not exist. |
| 980 // | 964 // |
| 981 Source source = addNamedSource( | 965 Source source = addNamedSource( |
| 982 "/a.dart", | 966 "/a.dart", |
| 983 r''' | 967 r''' |
| 984 import 'missing.dart' show q, r, t, u, T, U, V, W; | 968 import 'missing.dart' show q, r, t, u, T, U, V, W; |
| 985 int a = q + r.s; | 969 int a = q + r.s; |
| 986 String b = t(a) + u(v: 0); | 970 String b = t(a) + u(v: 0); |
| 987 T c = new T(); | 971 T c = new T(); |
| 988 class D<E> extends T { | 972 class D<E> extends T { |
| 989 D(int i) : super(i); | 973 D(int i) : super(i); |
| 990 U f = new V(); | 974 U f = new V(); |
| 991 } | 975 } |
| 992 class F implements T { | 976 class F implements T { |
| 993 T m(U u) => null; | 977 T m(U u) => null; |
| 994 } | 978 } |
| 995 class G extends Object with V {} | 979 class G extends Object with V {} |
| 996 class H extends D<W> { | 980 class H extends D<W> { |
| 997 H(int i) : super(i); | 981 H(int i) : super(i); |
| 998 } | 982 } |
| 999 '''); | 983 '''); |
| 1000 computeLibrarySourceErrors(source); | |
| 1001 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 984 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 1002 verify([source]); | 985 verify([source]); |
| 1003 } | 986 } |
| 1004 | 987 |
| 1005 void test_import_spaceInUri() { | 988 void test_import_spaceInUri() { |
| 1006 addNamedSource( | 989 addNamedSource( |
| 1007 "/sub folder/lib.dart", | 990 "/sub folder/lib.dart", |
| 1008 r''' | 991 r''' |
| 1009 library lib; | 992 library lib; |
| 1010 foo() {}'''); | 993 foo() {}'''); |
| 1011 Source source = addNamedSource( | 994 Source source = addNamedSource( |
| 1012 "/app.dart", | 995 "/app.dart", |
| 1013 r''' | 996 r''' |
| 1014 import 'sub folder/lib.dart'; | 997 import 'sub folder/lib.dart'; |
| 1015 | 998 |
| 1016 main() { | 999 main() { |
| 1017 foo(); | 1000 foo(); |
| 1018 }'''); | 1001 }'''); |
| 1019 computeLibrarySourceErrors(source); | |
| 1020 assertNoErrors(source); | 1002 assertNoErrors(source); |
| 1021 verify([source]); | 1003 verify([source]); |
| 1022 } | 1004 } |
| 1023 | 1005 |
| 1024 void test_indexExpression_typeParameters() { | 1006 void test_indexExpression_typeParameters() { |
| 1025 Source source = addSource(r''' | 1007 Source source = addSource(r''' |
| 1026 f() { | 1008 f() { |
| 1027 List<int> a; | 1009 List<int> a; |
| 1028 a[0]; | 1010 a[0]; |
| 1029 List<List<int>> b; | 1011 List<List<int>> b; |
| 1030 b[0][0]; | 1012 b[0][0]; |
| 1031 List<List<List<int>>> c; | 1013 List<List<List<int>>> c; |
| 1032 c[0][0][0]; | 1014 c[0][0][0]; |
| 1033 }'''); | 1015 }'''); |
| 1034 computeLibrarySourceErrors(source); | |
| 1035 assertNoErrors(source); | 1016 assertNoErrors(source); |
| 1036 verify([source]); | 1017 verify([source]); |
| 1037 } | 1018 } |
| 1038 | 1019 |
| 1039 void test_indexExpression_typeParameters_invalidAssignmentWarning() { | 1020 void test_indexExpression_typeParameters_invalidAssignmentWarning() { |
| 1040 Source source = addSource(r''' | 1021 Source source = addSource(r''' |
| 1041 f() { | 1022 f() { |
| 1042 List<List<int>> b; | 1023 List<List<int>> b; |
| 1043 b[0][0] = 'hi'; | 1024 b[0][0] = 'hi'; |
| 1044 }'''); | 1025 }'''); |
| 1045 computeLibrarySourceErrors(source); | |
| 1046 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 1026 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 1047 verify([source]); | 1027 verify([source]); |
| 1048 } | 1028 } |
| 1049 | 1029 |
| 1050 void test_indirectOperatorThroughCall() { | 1030 void test_indirectOperatorThroughCall() { |
| 1051 Source source = addSource(r''' | 1031 Source source = addSource(r''' |
| 1052 class A { | 1032 class A { |
| 1053 B call() { return new B(); } | 1033 B call() { return new B(); } |
| 1054 } | 1034 } |
| 1055 | 1035 |
| 1056 class B { | 1036 class B { |
| 1057 int operator [](int i) { return i; } | 1037 int operator [](int i) { return i; } |
| 1058 } | 1038 } |
| 1059 | 1039 |
| 1060 A f = new A(); | 1040 A f = new A(); |
| 1061 | 1041 |
| 1062 g(int x) {} | 1042 g(int x) {} |
| 1063 | 1043 |
| 1064 main() { | 1044 main() { |
| 1065 g(f()[0]); | 1045 g(f()[0]); |
| 1066 }'''); | 1046 }'''); |
| 1067 computeLibrarySourceErrors(source); | |
| 1068 assertNoErrors(source); | 1047 assertNoErrors(source); |
| 1069 verify([source]); | 1048 verify([source]); |
| 1070 } | 1049 } |
| 1071 | 1050 |
| 1072 void test_invoke_dynamicThroughGetter() { | 1051 void test_invoke_dynamicThroughGetter() { |
| 1073 Source source = addSource(r''' | 1052 Source source = addSource(r''' |
| 1074 class A { | 1053 class A { |
| 1075 List get X => [() => 0]; | 1054 List get X => [() => 0]; |
| 1076 m(A a) { | 1055 m(A a) { |
| 1077 X.last; | 1056 X.last; |
| 1078 } | 1057 } |
| 1079 }'''); | 1058 }'''); |
| 1080 computeLibrarySourceErrors(source); | |
| 1081 assertNoErrors(source); | 1059 assertNoErrors(source); |
| 1082 verify([source]); | 1060 verify([source]); |
| 1083 } | 1061 } |
| 1084 | 1062 |
| 1085 void test_isValidMixin_badSuperclass() { | 1063 void test_isValidMixin_badSuperclass() { |
| 1086 Source source = addSource(r''' | 1064 Source source = addSource(r''' |
| 1087 class A extends B {} | 1065 class A extends B {} |
| 1088 class B {} | 1066 class B {} |
| 1089 class C = Object with A;'''); | 1067 class C = Object with A;'''); |
| 1090 LibraryElement library = resolve2(source); | 1068 LibraryElement library = resolve2(source); |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1515 bar() => 1; | 1493 bar() => 1; |
| 1516 } | 1494 } |
| 1517 class A { | 1495 class A { |
| 1518 foo() => 2; | 1496 foo() => 2; |
| 1519 } | 1497 } |
| 1520 | 1498 |
| 1521 class C extends B with A { | 1499 class C extends B with A { |
| 1522 bar() => super.bar(); | 1500 bar() => super.bar(); |
| 1523 foo() => super.foo(); | 1501 foo() => super.foo(); |
| 1524 }'''); | 1502 }'''); |
| 1525 computeLibrarySourceErrors(source); | |
| 1526 assertNoErrors(source); | 1503 assertNoErrors(source); |
| 1527 verify([source]); | 1504 verify([source]); |
| 1528 } | 1505 } |
| 1529 | 1506 |
| 1530 void test_method_fromMixins() { | 1507 void test_method_fromMixins() { |
| 1531 Source source = addSource(''' | 1508 Source source = addSource(''' |
| 1532 class B {} | 1509 class B {} |
| 1533 class M1 { | 1510 class M1 { |
| 1534 void f() {} | 1511 void f() {} |
| 1535 } | 1512 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 class A { | 1605 class A { |
| 1629 void m1() {} | 1606 void m1() {} |
| 1630 } | 1607 } |
| 1631 class B extends Object with A { | 1608 class B extends Object with A { |
| 1632 } | 1609 } |
| 1633 class C extends B { | 1610 class C extends B { |
| 1634 } | 1611 } |
| 1635 f(C c) { | 1612 f(C c) { |
| 1636 c.m1(); | 1613 c.m1(); |
| 1637 }'''); | 1614 }'''); |
| 1638 computeLibrarySourceErrors(source); | |
| 1639 assertNoErrors(source); | 1615 assertNoErrors(source); |
| 1640 verify([source]); | 1616 verify([source]); |
| 1641 } | 1617 } |
| 1642 | 1618 |
| 1643 void test_methodCascades() { | 1619 void test_methodCascades() { |
| 1644 Source source = addSource(r''' | 1620 Source source = addSource(r''' |
| 1645 class A { | 1621 class A { |
| 1646 void m1() {} | 1622 void m1() {} |
| 1647 void m2() {} | 1623 void m2() {} |
| 1648 void m() { | 1624 void m() { |
| 1649 A a = new A(); | 1625 A a = new A(); |
| 1650 a..m1() | 1626 a..m1() |
| 1651 ..m2(); | 1627 ..m2(); |
| 1652 } | 1628 } |
| 1653 }'''); | 1629 }'''); |
| 1654 computeLibrarySourceErrors(source); | |
| 1655 assertNoErrors(source); | 1630 assertNoErrors(source); |
| 1656 verify([source]); | 1631 verify([source]); |
| 1657 } | 1632 } |
| 1658 | 1633 |
| 1659 void test_methodCascades_withSetter() { | 1634 void test_methodCascades_withSetter() { |
| 1660 Source source = addSource(r''' | 1635 Source source = addSource(r''' |
| 1661 class A { | 1636 class A { |
| 1662 String name; | 1637 String name; |
| 1663 void m1() {} | 1638 void m1() {} |
| 1664 void m2() {} | 1639 void m2() {} |
| 1665 void m() { | 1640 void m() { |
| 1666 A a = new A(); | 1641 A a = new A(); |
| 1667 a..m1() | 1642 a..m1() |
| 1668 ..name = 'name' | 1643 ..name = 'name' |
| 1669 ..m2(); | 1644 ..m2(); |
| 1670 } | 1645 } |
| 1671 }'''); | 1646 }'''); |
| 1672 computeLibrarySourceErrors(source); | |
| 1673 // failing with error code: INVOCATION_OF_NON_FUNCTION | 1647 // failing with error code: INVOCATION_OF_NON_FUNCTION |
| 1674 assertNoErrors(source); | 1648 assertNoErrors(source); |
| 1675 verify([source]); | 1649 verify([source]); |
| 1676 } | 1650 } |
| 1677 | 1651 |
| 1678 void test_resolveAgainstNull() { | 1652 void test_resolveAgainstNull() { |
| 1679 Source source = addSource(r''' | 1653 Source source = addSource(r''' |
| 1680 f(var p) { | 1654 f(var p) { |
| 1681 return null == p; | 1655 return null == p; |
| 1682 }'''); | 1656 }'''); |
| 1683 computeLibrarySourceErrors(source); | |
| 1684 assertNoErrors(source); | 1657 assertNoErrors(source); |
| 1685 } | 1658 } |
| 1686 | 1659 |
| 1687 void test_setter_fromMixins_bare_identifier() { | 1660 void test_setter_fromMixins_bare_identifier() { |
| 1688 Source source = addSource(''' | 1661 Source source = addSource(''' |
| 1689 class B {} | 1662 class B {} |
| 1690 class M1 { | 1663 class M1 { |
| 1691 set x(value) {} | 1664 set x(value) {} |
| 1692 } | 1665 } |
| 1693 class M2 { | 1666 class M2 { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 void test_setter_inherited() { | 1727 void test_setter_inherited() { |
| 1755 Source source = addSource(r''' | 1728 Source source = addSource(r''' |
| 1756 class A { | 1729 class A { |
| 1757 int get x => 0; | 1730 int get x => 0; |
| 1758 set x(int p) {} | 1731 set x(int p) {} |
| 1759 } | 1732 } |
| 1760 class B extends A { | 1733 class B extends A { |
| 1761 int get x => super.x == null ? 0 : super.x; | 1734 int get x => super.x == null ? 0 : super.x; |
| 1762 int f() => x = 1; | 1735 int f() => x = 1; |
| 1763 }'''); | 1736 }'''); |
| 1764 computeLibrarySourceErrors(source); | |
| 1765 assertNoErrors(source); | 1737 assertNoErrors(source); |
| 1766 verify([source]); | 1738 verify([source]); |
| 1767 } | 1739 } |
| 1768 | 1740 |
| 1769 void test_setter_static() { | 1741 void test_setter_static() { |
| 1770 Source source = addSource(r''' | 1742 Source source = addSource(r''' |
| 1771 set s(x) { | 1743 set s(x) { |
| 1772 } | 1744 } |
| 1773 | 1745 |
| 1774 main() { | 1746 main() { |
| 1775 s = 123; | 1747 s = 123; |
| 1776 }'''); | 1748 }'''); |
| 1777 computeLibrarySourceErrors(source); | |
| 1778 assertNoErrors(source); | 1749 assertNoErrors(source); |
| 1779 verify([source]); | 1750 verify([source]); |
| 1780 } | 1751 } |
| 1781 | 1752 |
| 1782 @failingTest | 1753 @failingTest |
| 1783 void test_staticInvocation() { | 1754 void test_staticInvocation() { |
| 1784 Source source = addSource(r''' | 1755 Source source = addSource(r''' |
| 1785 class A { | 1756 class A { |
| 1786 static int get g => (a,b) => 0; | 1757 static int get g => (a,b) => 0; |
| 1787 } | 1758 } |
| 1788 class B { | 1759 class B { |
| 1789 f() { | 1760 f() { |
| 1790 A.g(1,0); | 1761 A.g(1,0); |
| 1791 } | 1762 } |
| 1792 }'''); | 1763 }'''); |
| 1793 computeLibrarySourceErrors(source); | |
| 1794 assertNoErrors(source); | 1764 assertNoErrors(source); |
| 1795 verify([source]); | 1765 verify([source]); |
| 1796 } | 1766 } |
| 1797 | 1767 |
| 1798 /** | 1768 /** |
| 1799 * Resolve the given source and verify that the arguments in a specific method
invocation were | 1769 * Resolve the given source and verify that the arguments in a specific method
invocation were |
| 1800 * correctly resolved. | 1770 * correctly resolved. |
| 1801 * | 1771 * |
| 1802 * The source is expected to be source for a compilation unit, the first decla
ration is expected | 1772 * The source is expected to be source for a compilation unit, the first decla
ration is expected |
| 1803 * to be a class, the first member of which is expected to be a method with a
block body, and the | 1773 * to be a class, the first member of which is expected to be a method with a
block body, and the |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1869 // check propagated type | 1839 // check propagated type |
| 1870 FunctionType propagatedType = node.propagatedType as FunctionType; | 1840 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 1871 expect(propagatedType.returnType, test.typeProvider.stringType); | 1841 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 1872 } on AnalysisException catch (e, stackTrace) { | 1842 } on AnalysisException catch (e, stackTrace) { |
| 1873 thrownException[0] = new CaughtException(e, stackTrace); | 1843 thrownException[0] = new CaughtException(e, stackTrace); |
| 1874 } | 1844 } |
| 1875 } | 1845 } |
| 1876 return null; | 1846 return null; |
| 1877 } | 1847 } |
| 1878 } | 1848 } |
| OLD | NEW |