| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver_test; | 5 library engine.resolver_test; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/context.dart' as newContext; | 9 import 'package:analyzer/src/context/context.dart' as newContext; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 const A(); | 588 const A(); |
| 589 } | 589 } |
| 590 class B extends A { | 590 class B extends A { |
| 591 const B(); | 591 const B(); |
| 592 } | 592 } |
| 593 class C { | 593 class C { |
| 594 final A a; | 594 final A a; |
| 595 const C(this.a); | 595 const C(this.a); |
| 596 } | 596 } |
| 597 var v = const C(const B());'''); | 597 var v = const C(const B());'''); |
| 598 resolve(source); | 598 computeLibrarySourceErrors(source); |
| 599 assertNoErrors(source); | 599 assertNoErrors(source); |
| 600 verify([source]); | 600 verify([source]); |
| 601 } | 601 } |
| 602 | 602 |
| 603 void test_fieldFormalParameterAssignableToField_fieldType_unresolved_null() { | 603 void test_fieldFormalParameterAssignableToField_fieldType_unresolved_null() { |
| 604 // Null always passes runtime type checks, even when the type is | 604 // Null always passes runtime type checks, even when the type is |
| 605 // unresolved. | 605 // unresolved. |
| 606 Source source = addSource(r''' | 606 Source source = addSource(r''' |
| 607 class A { | 607 class A { |
| 608 final Unresolved x; | 608 final Unresolved x; |
| 609 const A(String this.x); | 609 const A(String this.x); |
| 610 } | 610 } |
| 611 var v = const A(null);'''); | 611 var v = const A(null);'''); |
| 612 resolve(source); | 612 computeLibrarySourceErrors(source); |
| 613 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); | 613 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); |
| 614 verify([source]); | 614 verify([source]); |
| 615 } | 615 } |
| 616 | 616 |
| 617 void test_fieldFormalParameterAssignableToField_implements() { | 617 void test_fieldFormalParameterAssignableToField_implements() { |
| 618 // According to checked-mode type checking rules, a value of type B is | 618 // According to checked-mode type checking rules, a value of type B is |
| 619 // assignable to a field of type A, because B implements A (and hence is a | 619 // assignable to a field of type A, because B implements A (and hence is a |
| 620 // subtype of A). | 620 // subtype of A). |
| 621 Source source = addSource(r''' | 621 Source source = addSource(r''' |
| 622 class A {} | 622 class A {} |
| 623 class B implements A { | 623 class B implements A { |
| 624 const B(); | 624 const B(); |
| 625 } | 625 } |
| 626 class C { | 626 class C { |
| 627 final A a; | 627 final A a; |
| 628 const C(this.a); | 628 const C(this.a); |
| 629 } | 629 } |
| 630 var v = const C(const B());'''); | 630 var v = const C(const B());'''); |
| 631 resolve(source); | 631 computeLibrarySourceErrors(source); |
| 632 assertNoErrors(source); | 632 assertNoErrors(source); |
| 633 verify([source]); | 633 verify([source]); |
| 634 } | 634 } |
| 635 | 635 |
| 636 void test_fieldFormalParameterAssignableToField_list_dynamic() { | 636 void test_fieldFormalParameterAssignableToField_list_dynamic() { |
| 637 // [1, 2, 3] has type List<dynamic>, which is a subtype of List<int>. | 637 // [1, 2, 3] has type List<dynamic>, which is a subtype of List<int>. |
| 638 Source source = addSource(r''' | 638 Source source = addSource(r''' |
| 639 class A { | 639 class A { |
| 640 const A(List<int> x); | 640 const A(List<int> x); |
| 641 } | 641 } |
| 642 var x = const A(const [1, 2, 3]);'''); | 642 var x = const A(const [1, 2, 3]);'''); |
| 643 resolve(source); | 643 computeLibrarySourceErrors(source); |
| 644 assertNoErrors(source); | 644 assertNoErrors(source); |
| 645 verify([source]); | 645 verify([source]); |
| 646 } | 646 } |
| 647 | 647 |
| 648 void test_fieldFormalParameterAssignableToField_list_nonDynamic() { | 648 void test_fieldFormalParameterAssignableToField_list_nonDynamic() { |
| 649 // <int>[1, 2, 3] has type List<int>, which is a subtype of List<num>. | 649 // <int>[1, 2, 3] has type List<int>, which is a subtype of List<num>. |
| 650 Source source = addSource(r''' | 650 Source source = addSource(r''' |
| 651 class A { | 651 class A { |
| 652 const A(List<num> x); | 652 const A(List<num> x); |
| 653 } | 653 } |
| 654 var x = const A(const <int>[1, 2, 3]);'''); | 654 var x = const A(const <int>[1, 2, 3]);'''); |
| 655 resolve(source); | 655 computeLibrarySourceErrors(source); |
| 656 assertNoErrors(source); | 656 assertNoErrors(source); |
| 657 verify([source]); | 657 verify([source]); |
| 658 } | 658 } |
| 659 | 659 |
| 660 void test_fieldFormalParameterAssignableToField_map_dynamic() { | 660 void test_fieldFormalParameterAssignableToField_map_dynamic() { |
| 661 // {1: 2} has type Map<dynamic, dynamic>, which is a subtype of | 661 // {1: 2} has type Map<dynamic, dynamic>, which is a subtype of |
| 662 // Map<int, int>. | 662 // Map<int, int>. |
| 663 Source source = addSource(r''' | 663 Source source = addSource(r''' |
| 664 class A { | 664 class A { |
| 665 const A(Map<int, int> x); | 665 const A(Map<int, int> x); |
| 666 } | 666 } |
| 667 var x = const A(const {1: 2});'''); | 667 var x = const A(const {1: 2});'''); |
| 668 resolve(source); | 668 computeLibrarySourceErrors(source); |
| 669 assertNoErrors(source); | 669 assertNoErrors(source); |
| 670 verify([source]); | 670 verify([source]); |
| 671 } | 671 } |
| 672 | 672 |
| 673 void test_fieldFormalParameterAssignableToField_map_keyDifferent() { | 673 void test_fieldFormalParameterAssignableToField_map_keyDifferent() { |
| 674 // <int, int>{1: 2} has type Map<int, int>, which is a subtype of | 674 // <int, int>{1: 2} has type Map<int, int>, which is a subtype of |
| 675 // Map<num, int>. | 675 // Map<num, int>. |
| 676 Source source = addSource(r''' | 676 Source source = addSource(r''' |
| 677 class A { | 677 class A { |
| 678 const A(Map<num, int> x); | 678 const A(Map<num, int> x); |
| 679 } | 679 } |
| 680 var x = const A(const <int, int>{1: 2});'''); | 680 var x = const A(const <int, int>{1: 2});'''); |
| 681 resolve(source); | 681 computeLibrarySourceErrors(source); |
| 682 assertNoErrors(source); | 682 assertNoErrors(source); |
| 683 verify([source]); | 683 verify([source]); |
| 684 } | 684 } |
| 685 | 685 |
| 686 void test_fieldFormalParameterAssignableToField_map_valueDifferent() { | 686 void test_fieldFormalParameterAssignableToField_map_valueDifferent() { |
| 687 // <int, int>{1: 2} has type Map<int, int>, which is a subtype of | 687 // <int, int>{1: 2} has type Map<int, int>, which is a subtype of |
| 688 // Map<int, num>. | 688 // Map<int, num>. |
| 689 Source source = addSource(r''' | 689 Source source = addSource(r''' |
| 690 class A { | 690 class A { |
| 691 const A(Map<int, num> x); | 691 const A(Map<int, num> x); |
| 692 } | 692 } |
| 693 var x = const A(const <int, int>{1: 2});'''); | 693 var x = const A(const <int, int>{1: 2});'''); |
| 694 resolve(source); | 694 computeLibrarySourceErrors(source); |
| 695 assertNoErrors(source); | 695 assertNoErrors(source); |
| 696 verify([source]); | 696 verify([source]); |
| 697 } | 697 } |
| 698 | 698 |
| 699 void test_fieldFormalParameterAssignableToField_notype() { | 699 void test_fieldFormalParameterAssignableToField_notype() { |
| 700 // If a field is declared without a type, then any value may be assigned to | 700 // If a field is declared without a type, then any value may be assigned to |
| 701 // it. | 701 // it. |
| 702 Source source = addSource(r''' | 702 Source source = addSource(r''' |
| 703 class A { | 703 class A { |
| 704 final x; | 704 final x; |
| 705 const A(this.x); | 705 const A(this.x); |
| 706 } | 706 } |
| 707 var v = const A(5);'''); | 707 var v = const A(5);'''); |
| 708 resolve(source); | 708 computeLibrarySourceErrors(source); |
| 709 assertNoErrors(source); | 709 assertNoErrors(source); |
| 710 verify([source]); | 710 verify([source]); |
| 711 } | 711 } |
| 712 | 712 |
| 713 void test_fieldFormalParameterAssignableToField_null() { | 713 void test_fieldFormalParameterAssignableToField_null() { |
| 714 // Null is assignable to anything. | 714 // Null is assignable to anything. |
| 715 Source source = addSource(r''' | 715 Source source = addSource(r''' |
| 716 class A { | 716 class A { |
| 717 final int x; | 717 final int x; |
| 718 const A(this.x); | 718 const A(this.x); |
| 719 } | 719 } |
| 720 var v = const A(null);'''); | 720 var v = const A(null);'''); |
| 721 resolve(source); | 721 computeLibrarySourceErrors(source); |
| 722 assertNoErrors(source); | 722 assertNoErrors(source); |
| 723 verify([source]); | 723 verify([source]); |
| 724 } | 724 } |
| 725 | 725 |
| 726 void test_fieldFormalParameterAssignableToField_typedef() { | 726 void test_fieldFormalParameterAssignableToField_typedef() { |
| 727 // foo has the runtime type dynamic -> dynamic, so it should be assignable | 727 // foo has the runtime type dynamic -> dynamic, so it should be assignable |
| 728 // to A.f. | 728 // to A.f. |
| 729 Source source = addSource(r''' | 729 Source source = addSource(r''' |
| 730 typedef String Int2String(int x); | 730 typedef String Int2String(int x); |
| 731 class A { | 731 class A { |
| 732 final Int2String f; | 732 final Int2String f; |
| 733 const A(this.f); | 733 const A(this.f); |
| 734 } | 734 } |
| 735 foo(x) => 1; | 735 foo(x) => 1; |
| 736 var v = const A(foo);'''); | 736 var v = const A(foo);'''); |
| 737 resolve(source); | 737 computeLibrarySourceErrors(source); |
| 738 assertNoErrors(source); | 738 assertNoErrors(source); |
| 739 verify([source]); | 739 verify([source]); |
| 740 } | 740 } |
| 741 | 741 |
| 742 void test_fieldFormalParameterAssignableToField_typeSubstitution() { | 742 void test_fieldFormalParameterAssignableToField_typeSubstitution() { |
| 743 // foo has the runtime type dynamic -> dynamic, so it should be assignable | 743 // foo has the runtime type dynamic -> dynamic, so it should be assignable |
| 744 // to A.f. | 744 // to A.f. |
| 745 Source source = addSource(r''' | 745 Source source = addSource(r''' |
| 746 class A<T> { | 746 class A<T> { |
| 747 final T x; | 747 final T x; |
| 748 const A(this.x); | 748 const A(this.x); |
| 749 } | 749 } |
| 750 var v = const A<int>(3);'''); | 750 var v = const A<int>(3);'''); |
| 751 resolve(source); | 751 computeLibrarySourceErrors(source); |
| 752 assertNoErrors(source); | 752 assertNoErrors(source); |
| 753 verify([source]); | 753 verify([source]); |
| 754 } | 754 } |
| 755 | 755 |
| 756 void test_fieldFormalParameterNotAssignableToField() { | 756 void test_fieldFormalParameterNotAssignableToField() { |
| 757 Source source = addSource(r''' | 757 Source source = addSource(r''' |
| 758 class A { | 758 class A { |
| 759 final int x; | 759 final int x; |
| 760 const A(this.x); | 760 const A(this.x); |
| 761 } | 761 } |
| 762 var v = const A('foo');'''); | 762 var v = const A('foo');'''); |
| 763 resolve(source); | 763 computeLibrarySourceErrors(source); |
| 764 assertErrors(source, [ | 764 assertErrors(source, [ |
| 765 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 765 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 766 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 766 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 767 ]); | 767 ]); |
| 768 verify([source]); | 768 verify([source]); |
| 769 } | 769 } |
| 770 | 770 |
| 771 void test_fieldFormalParameterNotAssignableToField_extends() { | 771 void test_fieldFormalParameterNotAssignableToField_extends() { |
| 772 // According to checked-mode type checking rules, a value of type A is not | 772 // According to checked-mode type checking rules, a value of type A is not |
| 773 // assignable to a field of type B, because B extends A (the subtyping | 773 // assignable to a field of type B, because B extends A (the subtyping |
| 774 // relationship is in the wrong direction). | 774 // relationship is in the wrong direction). |
| 775 Source source = addSource(r''' | 775 Source source = addSource(r''' |
| 776 class A { | 776 class A { |
| 777 const A(); | 777 const A(); |
| 778 } | 778 } |
| 779 class B extends A { | 779 class B extends A { |
| 780 const B(); | 780 const B(); |
| 781 } | 781 } |
| 782 class C { | 782 class C { |
| 783 final B b; | 783 final B b; |
| 784 const C(this.b); | 784 const C(this.b); |
| 785 } | 785 } |
| 786 var v = const C(const A());'''); | 786 var v = const C(const A());'''); |
| 787 resolve(source); | 787 computeLibrarySourceErrors(source); |
| 788 assertErrors(source, [ | 788 assertErrors(source, [ |
| 789 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH | 789 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH |
| 790 ]); | 790 ]); |
| 791 verify([source]); | 791 verify([source]); |
| 792 } | 792 } |
| 793 | 793 |
| 794 void test_fieldFormalParameterNotAssignableToField_fieldType() { | 794 void test_fieldFormalParameterNotAssignableToField_fieldType() { |
| 795 Source source = addSource(r''' | 795 Source source = addSource(r''' |
| 796 class A { | 796 class A { |
| 797 final int x; | 797 final int x; |
| 798 const A(String this.x); | 798 const A(String this.x); |
| 799 } | 799 } |
| 800 var v = const A('foo');'''); | 800 var v = const A('foo');'''); |
| 801 resolve(source); | 801 computeLibrarySourceErrors(source); |
| 802 assertErrors(source, [ | 802 assertErrors(source, [ |
| 803 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 803 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 804 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE | 804 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE |
| 805 ]); | 805 ]); |
| 806 verify([source]); | 806 verify([source]); |
| 807 } | 807 } |
| 808 | 808 |
| 809 void test_fieldFormalParameterNotAssignableToField_fieldType_unresolved() { | 809 void test_fieldFormalParameterNotAssignableToField_fieldType_unresolved() { |
| 810 Source source = addSource(r''' | 810 Source source = addSource(r''' |
| 811 class A { | 811 class A { |
| 812 final Unresolved x; | 812 final Unresolved x; |
| 813 const A(String this.x); | 813 const A(String this.x); |
| 814 } | 814 } |
| 815 var v = const A('foo');'''); | 815 var v = const A('foo');'''); |
| 816 resolve(source); | 816 computeLibrarySourceErrors(source); |
| 817 assertErrors(source, [ | 817 assertErrors(source, [ |
| 818 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 818 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 819 StaticWarningCode.UNDEFINED_CLASS | 819 StaticWarningCode.UNDEFINED_CLASS |
| 820 ]); | 820 ]); |
| 821 verify([source]); | 821 verify([source]); |
| 822 } | 822 } |
| 823 | 823 |
| 824 void test_fieldFormalParameterNotAssignableToField_implements() { | 824 void test_fieldFormalParameterNotAssignableToField_implements() { |
| 825 // According to checked-mode type checking rules, a value of type A is not | 825 // According to checked-mode type checking rules, a value of type A is not |
| 826 // assignable to a field of type B, because B implements A (the subtyping | 826 // assignable to a field of type B, because B implements A (the subtyping |
| 827 // relationship is in the wrong direction). | 827 // relationship is in the wrong direction). |
| 828 Source source = addSource(r''' | 828 Source source = addSource(r''' |
| 829 class A { | 829 class A { |
| 830 const A(); | 830 const A(); |
| 831 } | 831 } |
| 832 class B implements A {} | 832 class B implements A {} |
| 833 class C { | 833 class C { |
| 834 final B b; | 834 final B b; |
| 835 const C(this.b); | 835 const C(this.b); |
| 836 } | 836 } |
| 837 var v = const C(const A());'''); | 837 var v = const C(const A());'''); |
| 838 resolve(source); | 838 computeLibrarySourceErrors(source); |
| 839 assertErrors(source, [ | 839 assertErrors(source, [ |
| 840 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH | 840 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH |
| 841 ]); | 841 ]); |
| 842 verify([source]); | 842 verify([source]); |
| 843 } | 843 } |
| 844 | 844 |
| 845 void test_fieldFormalParameterNotAssignableToField_list() { | 845 void test_fieldFormalParameterNotAssignableToField_list() { |
| 846 // <num>[1, 2, 3] has type List<num>, which is not a subtype of List<int>. | 846 // <num>[1, 2, 3] has type List<num>, which is not a subtype of List<int>. |
| 847 Source source = addSource(r''' | 847 Source source = addSource(r''' |
| 848 class A { | 848 class A { |
| 849 const A(List<int> x); | 849 const A(List<int> x); |
| 850 } | 850 } |
| 851 var x = const A(const <num>[1, 2, 3]);'''); | 851 var x = const A(const <num>[1, 2, 3]);'''); |
| 852 resolve(source); | 852 computeLibrarySourceErrors(source); |
| 853 assertErrors(source, [ | 853 assertErrors(source, [ |
| 854 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH | 854 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH |
| 855 ]); | 855 ]); |
| 856 verify([source]); | 856 verify([source]); |
| 857 } | 857 } |
| 858 | 858 |
| 859 void test_fieldFormalParameterNotAssignableToField_map_keyMismatch() { | 859 void test_fieldFormalParameterNotAssignableToField_map_keyMismatch() { |
| 860 // <num, int>{1: 2} has type Map<num, int>, which is not a subtype of | 860 // <num, int>{1: 2} has type Map<num, int>, which is not a subtype of |
| 861 // Map<int, int>. | 861 // Map<int, int>. |
| 862 Source source = addSource(r''' | 862 Source source = addSource(r''' |
| 863 class A { | 863 class A { |
| 864 const A(Map<int, int> x); | 864 const A(Map<int, int> x); |
| 865 } | 865 } |
| 866 var x = const A(const <num, int>{1: 2});'''); | 866 var x = const A(const <num, int>{1: 2});'''); |
| 867 resolve(source); | 867 computeLibrarySourceErrors(source); |
| 868 assertErrors(source, [ | 868 assertErrors(source, [ |
| 869 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH | 869 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH |
| 870 ]); | 870 ]); |
| 871 verify([source]); | 871 verify([source]); |
| 872 } | 872 } |
| 873 | 873 |
| 874 void test_fieldFormalParameterNotAssignableToField_map_valueMismatch() { | 874 void test_fieldFormalParameterNotAssignableToField_map_valueMismatch() { |
| 875 // <int, num>{1: 2} has type Map<int, num>, which is not a subtype of | 875 // <int, num>{1: 2} has type Map<int, num>, which is not a subtype of |
| 876 // Map<int, int>. | 876 // Map<int, int>. |
| 877 Source source = addSource(r''' | 877 Source source = addSource(r''' |
| 878 class A { | 878 class A { |
| 879 const A(Map<int, int> x); | 879 const A(Map<int, int> x); |
| 880 } | 880 } |
| 881 var x = const A(const <int, num>{1: 2});'''); | 881 var x = const A(const <int, num>{1: 2});'''); |
| 882 resolve(source); | 882 computeLibrarySourceErrors(source); |
| 883 assertErrors(source, [ | 883 assertErrors(source, [ |
| 884 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH | 884 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH |
| 885 ]); | 885 ]); |
| 886 verify([source]); | 886 verify([source]); |
| 887 } | 887 } |
| 888 | 888 |
| 889 void test_fieldFormalParameterNotAssignableToField_optional() { | 889 void test_fieldFormalParameterNotAssignableToField_optional() { |
| 890 Source source = addSource(r''' | 890 Source source = addSource(r''' |
| 891 class A { | 891 class A { |
| 892 final int x; | 892 final int x; |
| 893 const A([this.x = 'foo']); | 893 const A([this.x = 'foo']); |
| 894 } | 894 } |
| 895 var v = const A();'''); | 895 var v = const A();'''); |
| 896 resolve(source); | 896 computeLibrarySourceErrors(source); |
| 897 assertErrors(source, [ | 897 assertErrors(source, [ |
| 898 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 898 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 899 StaticTypeWarningCode.INVALID_ASSIGNMENT | 899 StaticTypeWarningCode.INVALID_ASSIGNMENT |
| 900 ]); | 900 ]); |
| 901 verify([source]); | 901 verify([source]); |
| 902 } | 902 } |
| 903 | 903 |
| 904 void test_fieldFormalParameterNotAssignableToField_typedef() { | 904 void test_fieldFormalParameterNotAssignableToField_typedef() { |
| 905 // foo has the runtime type String -> int, so it should not be assignable | 905 // foo has the runtime type String -> int, so it should not be assignable |
| 906 // to A.f (A.f requires it to be int -> String). | 906 // to A.f (A.f requires it to be int -> String). |
| 907 Source source = addSource(r''' | 907 Source source = addSource(r''' |
| 908 typedef String Int2String(int x); | 908 typedef String Int2String(int x); |
| 909 class A { | 909 class A { |
| 910 final Int2String f; | 910 final Int2String f; |
| 911 const A(this.f); | 911 const A(this.f); |
| 912 } | 912 } |
| 913 int foo(String x) => 1; | 913 int foo(String x) => 1; |
| 914 var v = const A(foo);'''); | 914 var v = const A(foo);'''); |
| 915 resolve(source); | 915 computeLibrarySourceErrors(source); |
| 916 assertErrors(source, [ | 916 assertErrors(source, [ |
| 917 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 917 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 918 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 918 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 919 ]); | 919 ]); |
| 920 verify([source]); | 920 verify([source]); |
| 921 } | 921 } |
| 922 | 922 |
| 923 void test_fieldInitializerNotAssignable() { | 923 void test_fieldInitializerNotAssignable() { |
| 924 Source source = addSource(r''' | 924 Source source = addSource(r''' |
| 925 class A { | 925 class A { |
| 926 final int x; | 926 final int x; |
| 927 const A() : x = ''; | 927 const A() : x = ''; |
| 928 }'''); | 928 }'''); |
| 929 resolve(source); | 929 computeLibrarySourceErrors(source); |
| 930 assertErrors(source, [ | 930 assertErrors(source, [ |
| 931 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE, | 931 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE, |
| 932 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE | 932 StaticWarningCode.FIELD_INITIALIZER_NOT_ASSIGNABLE |
| 933 ]); | 933 ]); |
| 934 verify([source]); | 934 verify([source]); |
| 935 } | 935 } |
| 936 | 936 |
| 937 void test_fieldTypeMismatch() { | 937 void test_fieldTypeMismatch() { |
| 938 Source source = addSource(r''' | 938 Source source = addSource(r''' |
| 939 class A { | 939 class A { |
| 940 const A(x) : y = x; | 940 const A(x) : y = x; |
| 941 final int y; | 941 final int y; |
| 942 } | 942 } |
| 943 var v = const A('foo');'''); | 943 var v = const A('foo');'''); |
| 944 resolve(source); | 944 computeLibrarySourceErrors(source); |
| 945 assertErrors(source, [ | 945 assertErrors(source, [ |
| 946 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH | 946 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH |
| 947 ]); | 947 ]); |
| 948 verify([source]); | 948 verify([source]); |
| 949 } | 949 } |
| 950 | 950 |
| 951 void test_fieldTypeMismatch_generic() { | 951 void test_fieldTypeMismatch_generic() { |
| 952 Source source = addSource(r''' | 952 Source source = addSource(r''' |
| 953 class C<T> { | 953 class C<T> { |
| 954 final T x = y; | 954 final T x = y; |
| 955 const C(); | 955 const C(); |
| 956 } | 956 } |
| 957 const y = 1; | 957 const y = 1; |
| 958 var v = const C<String>(); | 958 var v = const C<String>(); |
| 959 '''); | 959 '''); |
| 960 resolve(source); | 960 computeLibrarySourceErrors(source); |
| 961 assertErrors(source, [ | 961 assertErrors(source, [ |
| 962 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, | 962 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, |
| 963 HintCode.INVALID_ASSIGNMENT | 963 HintCode.INVALID_ASSIGNMENT |
| 964 ]); | 964 ]); |
| 965 verify([source]); | 965 verify([source]); |
| 966 } | 966 } |
| 967 | 967 |
| 968 void test_fieldTypeMismatch_unresolved() { | 968 void test_fieldTypeMismatch_unresolved() { |
| 969 Source source = addSource(r''' | 969 Source source = addSource(r''' |
| 970 class A { | 970 class A { |
| 971 const A(x) : y = x; | 971 const A(x) : y = x; |
| 972 final Unresolved y; | 972 final Unresolved y; |
| 973 } | 973 } |
| 974 var v = const A('foo');'''); | 974 var v = const A('foo');'''); |
| 975 resolve(source); | 975 computeLibrarySourceErrors(source); |
| 976 assertErrors(source, [ | 976 assertErrors(source, [ |
| 977 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, | 977 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, |
| 978 StaticWarningCode.UNDEFINED_CLASS | 978 StaticWarningCode.UNDEFINED_CLASS |
| 979 ]); | 979 ]); |
| 980 verify([source]); | 980 verify([source]); |
| 981 } | 981 } |
| 982 | 982 |
| 983 void test_fieldTypeOk_generic() { | 983 void test_fieldTypeOk_generic() { |
| 984 Source source = addSource(r''' | 984 Source source = addSource(r''' |
| 985 class C<T> { | 985 class C<T> { |
| 986 final T x = y; | 986 final T x = y; |
| 987 const C(); | 987 const C(); |
| 988 } | 988 } |
| 989 const y = 1; | 989 const y = 1; |
| 990 var v = const C<int>(); | 990 var v = const C<int>(); |
| 991 '''); | 991 '''); |
| 992 resolve(source); | 992 computeLibrarySourceErrors(source); |
| 993 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 993 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 994 verify([source]); | 994 verify([source]); |
| 995 } | 995 } |
| 996 | 996 |
| 997 void test_fieldTypeOk_null() { | 997 void test_fieldTypeOk_null() { |
| 998 Source source = addSource(r''' | 998 Source source = addSource(r''' |
| 999 class A { | 999 class A { |
| 1000 const A(x) : y = x; | 1000 const A(x) : y = x; |
| 1001 final int y; | 1001 final int y; |
| 1002 } | 1002 } |
| 1003 var v = const A(null);'''); | 1003 var v = const A(null);'''); |
| 1004 resolve(source); | 1004 computeLibrarySourceErrors(source); |
| 1005 assertNoErrors(source); | 1005 assertNoErrors(source); |
| 1006 verify([source]); | 1006 verify([source]); |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 void test_fieldTypeOk_unresolved_null() { | 1009 void test_fieldTypeOk_unresolved_null() { |
| 1010 // Null always passes runtime type checks, even when the type is | 1010 // Null always passes runtime type checks, even when the type is |
| 1011 // unresolved. | 1011 // unresolved. |
| 1012 Source source = addSource(r''' | 1012 Source source = addSource(r''' |
| 1013 class A { | 1013 class A { |
| 1014 const A(x) : y = x; | 1014 const A(x) : y = x; |
| 1015 final Unresolved y; | 1015 final Unresolved y; |
| 1016 } | 1016 } |
| 1017 var v = const A(null);'''); | 1017 var v = const A(null);'''); |
| 1018 resolve(source); | 1018 computeLibrarySourceErrors(source); |
| 1019 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); | 1019 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); |
| 1020 verify([source]); | 1020 verify([source]); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 void test_listElementTypeNotAssignable() { | 1023 void test_listElementTypeNotAssignable() { |
| 1024 Source source = addSource("var v = const <String> [42];"); | 1024 Source source = addSource("var v = const <String> [42];"); |
| 1025 resolve(source); | 1025 computeLibrarySourceErrors(source); |
| 1026 assertErrors(source, [ | 1026 assertErrors(source, [ |
| 1027 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, | 1027 CheckedModeCompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, |
| 1028 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE | 1028 StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE |
| 1029 ]); | 1029 ]); |
| 1030 verify([source]); | 1030 verify([source]); |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 void test_mapKeyTypeNotAssignable() { | 1033 void test_mapKeyTypeNotAssignable() { |
| 1034 Source source = addSource("var v = const <String, int > {1 : 2};"); | 1034 Source source = addSource("var v = const <String, int > {1 : 2};"); |
| 1035 resolve(source); | 1035 computeLibrarySourceErrors(source); |
| 1036 assertErrors(source, [ | 1036 assertErrors(source, [ |
| 1037 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, | 1037 CheckedModeCompileTimeErrorCode.MAP_KEY_TYPE_NOT_ASSIGNABLE, |
| 1038 StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE | 1038 StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE |
| 1039 ]); | 1039 ]); |
| 1040 verify([source]); | 1040 verify([source]); |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 void test_mapValueTypeNotAssignable() { | 1043 void test_mapValueTypeNotAssignable() { |
| 1044 Source source = addSource("var v = const <String, String> {'a' : 2};"); | 1044 Source source = addSource("var v = const <String, String> {'a' : 2};"); |
| 1045 resolve(source); | 1045 computeLibrarySourceErrors(source); |
| 1046 assertErrors(source, [ | 1046 assertErrors(source, [ |
| 1047 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, | 1047 CheckedModeCompileTimeErrorCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE, |
| 1048 StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE | 1048 StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE |
| 1049 ]); | 1049 ]); |
| 1050 verify([source]); | 1050 verify([source]); |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 void test_parameterAssignable_null() { | 1053 void test_parameterAssignable_null() { |
| 1054 // Null is assignable to anything. | 1054 // Null is assignable to anything. |
| 1055 Source source = addSource(r''' | 1055 Source source = addSource(r''' |
| 1056 class A { | 1056 class A { |
| 1057 const A(int x); | 1057 const A(int x); |
| 1058 } | 1058 } |
| 1059 var v = const A(null);'''); | 1059 var v = const A(null);'''); |
| 1060 resolve(source); | 1060 computeLibrarySourceErrors(source); |
| 1061 assertNoErrors(source); | 1061 assertNoErrors(source); |
| 1062 verify([source]); | 1062 verify([source]); |
| 1063 } | 1063 } |
| 1064 | 1064 |
| 1065 void test_parameterAssignable_typeSubstitution() { | 1065 void test_parameterAssignable_typeSubstitution() { |
| 1066 Source source = addSource(r''' | 1066 Source source = addSource(r''' |
| 1067 class A<T> { | 1067 class A<T> { |
| 1068 const A(T x); | 1068 const A(T x); |
| 1069 } | 1069 } |
| 1070 var v = const A<int>(3);'''); | 1070 var v = const A<int>(3);'''); |
| 1071 resolve(source); | 1071 computeLibrarySourceErrors(source); |
| 1072 assertNoErrors(source); | 1072 assertNoErrors(source); |
| 1073 verify([source]); | 1073 verify([source]); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 void test_parameterAssignable_undefined_null() { | 1076 void test_parameterAssignable_undefined_null() { |
| 1077 // Null always passes runtime type checks, even when the type is | 1077 // Null always passes runtime type checks, even when the type is |
| 1078 // unresolved. | 1078 // unresolved. |
| 1079 Source source = addSource(r''' | 1079 Source source = addSource(r''' |
| 1080 class A { | 1080 class A { |
| 1081 const A(Unresolved x); | 1081 const A(Unresolved x); |
| 1082 } | 1082 } |
| 1083 var v = const A(null);'''); | 1083 var v = const A(null);'''); |
| 1084 resolve(source); | 1084 computeLibrarySourceErrors(source); |
| 1085 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); | 1085 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); |
| 1086 verify([source]); | 1086 verify([source]); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 void test_parameterNotAssignable() { | 1089 void test_parameterNotAssignable() { |
| 1090 Source source = addSource(r''' | 1090 Source source = addSource(r''' |
| 1091 class A { | 1091 class A { |
| 1092 const A(int x); | 1092 const A(int x); |
| 1093 } | 1093 } |
| 1094 var v = const A('foo');'''); | 1094 var v = const A('foo');'''); |
| 1095 resolve(source); | 1095 computeLibrarySourceErrors(source); |
| 1096 assertErrors(source, [ | 1096 assertErrors(source, [ |
| 1097 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 1097 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 1098 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 1098 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 1099 ]); | 1099 ]); |
| 1100 verify([source]); | 1100 verify([source]); |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 void test_parameterNotAssignable_typeSubstitution() { | 1103 void test_parameterNotAssignable_typeSubstitution() { |
| 1104 Source source = addSource(r''' | 1104 Source source = addSource(r''' |
| 1105 class A<T> { | 1105 class A<T> { |
| 1106 const A(T x); | 1106 const A(T x); |
| 1107 } | 1107 } |
| 1108 var v = const A<int>('foo');'''); | 1108 var v = const A<int>('foo');'''); |
| 1109 resolve(source); | 1109 computeLibrarySourceErrors(source); |
| 1110 assertErrors(source, [ | 1110 assertErrors(source, [ |
| 1111 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 1111 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 1112 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE | 1112 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 1113 ]); | 1113 ]); |
| 1114 verify([source]); | 1114 verify([source]); |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 void test_parameterNotAssignable_undefined() { | 1117 void test_parameterNotAssignable_undefined() { |
| 1118 Source source = addSource(r''' | 1118 Source source = addSource(r''' |
| 1119 class A { | 1119 class A { |
| 1120 const A(Unresolved x); | 1120 const A(Unresolved x); |
| 1121 } | 1121 } |
| 1122 var v = const A('foo');'''); | 1122 var v = const A('foo');'''); |
| 1123 resolve(source); | 1123 computeLibrarySourceErrors(source); |
| 1124 assertErrors(source, [ | 1124 assertErrors(source, [ |
| 1125 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, | 1125 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH, |
| 1126 StaticWarningCode.UNDEFINED_CLASS | 1126 StaticWarningCode.UNDEFINED_CLASS |
| 1127 ]); | 1127 ]); |
| 1128 verify([source]); | 1128 verify([source]); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 void test_redirectingConstructor_paramTypeMismatch() { | 1131 void test_redirectingConstructor_paramTypeMismatch() { |
| 1132 Source source = addSource(r''' | 1132 Source source = addSource(r''' |
| 1133 class A { | 1133 class A { |
| 1134 const A.a1(x) : this.a2(x); | 1134 const A.a1(x) : this.a2(x); |
| 1135 const A.a2(String x); | 1135 const A.a2(String x); |
| 1136 } | 1136 } |
| 1137 var v = const A.a1(0);'''); | 1137 var v = const A.a1(0);'''); |
| 1138 resolve(source); | 1138 computeLibrarySourceErrors(source); |
| 1139 assertErrors(source, [ | 1139 assertErrors(source, [ |
| 1140 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH | 1140 CheckedModeCompileTimeErrorCode.CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH |
| 1141 ]); | 1141 ]); |
| 1142 verify([source]); | 1142 verify([source]); |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 void test_topLevelVarAssignable_null() { | 1145 void test_topLevelVarAssignable_null() { |
| 1146 Source source = addSource("const int x = null;"); | 1146 Source source = addSource("const int x = null;"); |
| 1147 resolve(source); | 1147 computeLibrarySourceErrors(source); |
| 1148 assertNoErrors(source); | 1148 assertNoErrors(source); |
| 1149 verify([source]); | 1149 verify([source]); |
| 1150 } | 1150 } |
| 1151 | 1151 |
| 1152 void test_topLevelVarAssignable_undefined_null() { | 1152 void test_topLevelVarAssignable_undefined_null() { |
| 1153 // Null always passes runtime type checks, even when the type is | 1153 // Null always passes runtime type checks, even when the type is |
| 1154 // unresolved. | 1154 // unresolved. |
| 1155 Source source = addSource("const Unresolved x = null;"); | 1155 Source source = addSource("const Unresolved x = null;"); |
| 1156 resolve(source); | 1156 computeLibrarySourceErrors(source); |
| 1157 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); | 1157 assertErrors(source, [StaticWarningCode.UNDEFINED_CLASS]); |
| 1158 verify([source]); | 1158 verify([source]); |
| 1159 } | 1159 } |
| 1160 | 1160 |
| 1161 void test_topLevelVarNotAssignable() { | 1161 void test_topLevelVarNotAssignable() { |
| 1162 Source source = addSource("const int x = 'foo';"); | 1162 Source source = addSource("const int x = 'foo';"); |
| 1163 resolve(source); | 1163 computeLibrarySourceErrors(source); |
| 1164 assertErrors(source, [ | 1164 assertErrors(source, [ |
| 1165 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, | 1165 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, |
| 1166 StaticTypeWarningCode.INVALID_ASSIGNMENT | 1166 StaticTypeWarningCode.INVALID_ASSIGNMENT |
| 1167 ]); | 1167 ]); |
| 1168 verify([source]); | 1168 verify([source]); |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 void test_topLevelVarNotAssignable_undefined() { | 1171 void test_topLevelVarNotAssignable_undefined() { |
| 1172 Source source = addSource("const Unresolved x = 'foo';"); | 1172 Source source = addSource("const Unresolved x = 'foo';"); |
| 1173 resolve(source); | 1173 computeLibrarySourceErrors(source); |
| 1174 assertErrors(source, [ | 1174 assertErrors(source, [ |
| 1175 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, | 1175 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, |
| 1176 StaticWarningCode.UNDEFINED_CLASS | 1176 StaticWarningCode.UNDEFINED_CLASS |
| 1177 ]); | 1177 ]); |
| 1178 verify([source]); | 1178 verify([source]); |
| 1179 } | 1179 } |
| 1180 } | 1180 } |
| 1181 | 1181 |
| 1182 @reflectiveTest | 1182 @reflectiveTest |
| 1183 class ElementResolverTest extends EngineTestCase { | 1183 class ElementResolverTest extends EngineTestCase { |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2124 class A { | 2124 class A { |
| 2125 void m(int i) { | 2125 void m(int i) { |
| 2126 switch (i) { | 2126 switch (i) { |
| 2127 l: case 0: | 2127 l: case 0: |
| 2128 break; | 2128 break; |
| 2129 case 1: | 2129 case 1: |
| 2130 break l; | 2130 break l; |
| 2131 } | 2131 } |
| 2132 } | 2132 } |
| 2133 }'''); | 2133 }'''); |
| 2134 resolve(source); | 2134 computeLibrarySourceErrors(source); |
| 2135 assertErrors(source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]); | 2135 assertErrors(source, [ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]); |
| 2136 verify([source]); | 2136 verify([source]); |
| 2137 } | 2137 } |
| 2138 | 2138 |
| 2139 void test_continueLabelOnSwitch() { | 2139 void test_continueLabelOnSwitch() { |
| 2140 Source source = addSource(r''' | 2140 Source source = addSource(r''' |
| 2141 class A { | 2141 class A { |
| 2142 void m(int i) { | 2142 void m(int i) { |
| 2143 l: switch (i) { | 2143 l: switch (i) { |
| 2144 case 0: | 2144 case 0: |
| 2145 continue l; | 2145 continue l; |
| 2146 } | 2146 } |
| 2147 } | 2147 } |
| 2148 }'''); | 2148 }'''); |
| 2149 resolve(source); | 2149 computeLibrarySourceErrors(source); |
| 2150 assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]); | 2150 assertErrors(source, [ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]); |
| 2151 verify([source]); | 2151 verify([source]); |
| 2152 } | 2152 } |
| 2153 | 2153 |
| 2154 void test_enclosingElement_invalidLocalFunction() { | 2154 void test_enclosingElement_invalidLocalFunction() { |
| 2155 Source source = addSource(r''' | 2155 Source source = addSource(r''' |
| 2156 class C { | 2156 class C { |
| 2157 C() { | 2157 C() { |
| 2158 int get x => 0; | 2158 int get x => 0; |
| 2159 } | 2159 } |
| 2160 }'''); | 2160 }'''); |
| 2161 LibraryElement library = resolve(source); | 2161 LibraryElement library = resolve2(source); |
| 2162 expect(library, isNotNull); | 2162 expect(library, isNotNull); |
| 2163 var unit = library.definingCompilationUnit; | 2163 var unit = library.definingCompilationUnit; |
| 2164 expect(unit, isNotNull); | 2164 expect(unit, isNotNull); |
| 2165 var types = unit.types; | 2165 var types = unit.types; |
| 2166 expect(types, isNotNull); | 2166 expect(types, isNotNull); |
| 2167 expect(types, hasLength(1)); | 2167 expect(types, hasLength(1)); |
| 2168 var type = types[0]; | 2168 var type = types[0]; |
| 2169 expect(type, isNotNull); | 2169 expect(type, isNotNull); |
| 2170 var constructors = type.constructors; | 2170 var constructors = type.constructors; |
| 2171 expect(constructors, isNotNull); | 2171 expect(constructors, isNotNull); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2185 void fail_deadCode_statementAfterRehrow() { | 2185 void fail_deadCode_statementAfterRehrow() { |
| 2186 Source source = addSource(r''' | 2186 Source source = addSource(r''' |
| 2187 f() { | 2187 f() { |
| 2188 try { | 2188 try { |
| 2189 var one = 1; | 2189 var one = 1; |
| 2190 } catch (e) { | 2190 } catch (e) { |
| 2191 rethrow; | 2191 rethrow; |
| 2192 var two = 2; | 2192 var two = 2; |
| 2193 } | 2193 } |
| 2194 }'''); | 2194 }'''); |
| 2195 resolve(source); | 2195 computeLibrarySourceErrors(source); |
| 2196 assertErrors(source, [HintCode.DEAD_CODE]); | 2196 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2197 verify([source]); | 2197 verify([source]); |
| 2198 } | 2198 } |
| 2199 | 2199 |
| 2200 void fail_deadCode_statementAfterThrow() { | 2200 void fail_deadCode_statementAfterThrow() { |
| 2201 Source source = addSource(r''' | 2201 Source source = addSource(r''' |
| 2202 f() { | 2202 f() { |
| 2203 var one = 1; | 2203 var one = 1; |
| 2204 throw 'Stop here'; | 2204 throw 'Stop here'; |
| 2205 var two = 2; | 2205 var two = 2; |
| 2206 }'''); | 2206 }'''); |
| 2207 resolve(source); | 2207 computeLibrarySourceErrors(source); |
| 2208 assertErrors(source, [HintCode.DEAD_CODE]); | 2208 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2209 verify([source]); | 2209 verify([source]); |
| 2210 } | 2210 } |
| 2211 | 2211 |
| 2212 void fail_isInt() { | 2212 void fail_isInt() { |
| 2213 Source source = addSource("var v = 1 is int;"); | 2213 Source source = addSource("var v = 1 is int;"); |
| 2214 resolve(source); | 2214 computeLibrarySourceErrors(source); |
| 2215 assertErrors(source, [HintCode.IS_INT]); | 2215 assertErrors(source, [HintCode.IS_INT]); |
| 2216 verify([source]); | 2216 verify([source]); |
| 2217 } | 2217 } |
| 2218 | 2218 |
| 2219 void fail_isNotInt() { | 2219 void fail_isNotInt() { |
| 2220 Source source = addSource("var v = 1 is! int;"); | 2220 Source source = addSource("var v = 1 is! int;"); |
| 2221 resolve(source); | 2221 computeLibrarySourceErrors(source); |
| 2222 assertErrors(source, [HintCode.IS_NOT_INT]); | 2222 assertErrors(source, [HintCode.IS_NOT_INT]); |
| 2223 verify([source]); | 2223 verify([source]); |
| 2224 } | 2224 } |
| 2225 | 2225 |
| 2226 void fail_overrideEqualsButNotHashCode() { | 2226 void fail_overrideEqualsButNotHashCode() { |
| 2227 Source source = addSource(r''' | 2227 Source source = addSource(r''' |
| 2228 class A { | 2228 class A { |
| 2229 bool operator ==(x) {} | 2229 bool operator ==(x) {} |
| 2230 }'''); | 2230 }'''); |
| 2231 resolve(source); | 2231 computeLibrarySourceErrors(source); |
| 2232 assertErrors(source, [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]); | 2232 assertErrors(source, [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]); |
| 2233 verify([source]); | 2233 verify([source]); |
| 2234 } | 2234 } |
| 2235 | 2235 |
| 2236 void fail_unusedImport_as_equalPrefixes() { | 2236 void fail_unusedImport_as_equalPrefixes() { |
| 2237 // See todo at ImportsVerifier.prefixElementMap. | 2237 // See todo at ImportsVerifier.prefixElementMap. |
| 2238 Source source = addSource(r''' | 2238 Source source = addSource(r''' |
| 2239 library L; | 2239 library L; |
| 2240 import 'lib1.dart' as one; | 2240 import 'lib1.dart' as one; |
| 2241 import 'lib2.dart' as one; | 2241 import 'lib2.dart' as one; |
| 2242 one.A a;'''); | 2242 one.A a;'''); |
| 2243 Source source2 = addNamedSource("/lib1.dart", r''' | 2243 Source source2 = addNamedSource("/lib1.dart", r''' |
| 2244 library lib1; | 2244 library lib1; |
| 2245 class A {}'''); | 2245 class A {}'''); |
| 2246 Source source3 = addNamedSource("/lib2.dart", r''' | 2246 Source source3 = addNamedSource("/lib2.dart", r''' |
| 2247 library lib2; | 2247 library lib2; |
| 2248 class B {}'''); | 2248 class B {}'''); |
| 2249 resolve(source); | 2249 computeLibrarySourceErrors(source); |
| 2250 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 2250 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 2251 assertNoErrors(source2); | 2251 assertNoErrors(source2); |
| 2252 assertNoErrors(source3); | 2252 assertNoErrors(source3); |
| 2253 verify([source, source2, source3]); | 2253 verify([source, source2, source3]); |
| 2254 } | 2254 } |
| 2255 | 2255 |
| 2256 void test_argumentTypeNotAssignable_functionType() { | 2256 void test_argumentTypeNotAssignable_functionType() { |
| 2257 Source source = addSource(r''' | 2257 Source source = addSource(r''' |
| 2258 m() { | 2258 m() { |
| 2259 var a = new A(); | 2259 var a = new A(); |
| 2260 a.n(() => 0); | 2260 a.n(() => 0); |
| 2261 } | 2261 } |
| 2262 class A { | 2262 class A { |
| 2263 n(void f(int i)) {} | 2263 n(void f(int i)) {} |
| 2264 }'''); | 2264 }'''); |
| 2265 resolve(source); | 2265 computeLibrarySourceErrors(source); |
| 2266 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 2266 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 2267 verify([source]); | 2267 verify([source]); |
| 2268 } | 2268 } |
| 2269 | 2269 |
| 2270 void test_argumentTypeNotAssignable_message() { | 2270 void test_argumentTypeNotAssignable_message() { |
| 2271 // The implementation of HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE assumes that | 2271 // The implementation of HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE assumes that |
| 2272 // StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE has the same message. | 2272 // StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE has the same message. |
| 2273 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message, | 2273 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message, |
| 2274 HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message); | 2274 HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message); |
| 2275 } | 2275 } |
| 2276 | 2276 |
| 2277 void test_argumentTypeNotAssignable_type() { | 2277 void test_argumentTypeNotAssignable_type() { |
| 2278 Source source = addSource(r''' | 2278 Source source = addSource(r''' |
| 2279 m() { | 2279 m() { |
| 2280 var i = ''; | 2280 var i = ''; |
| 2281 n(i); | 2281 n(i); |
| 2282 } | 2282 } |
| 2283 n(int i) {}'''); | 2283 n(int i) {}'''); |
| 2284 resolve(source); | 2284 computeLibrarySourceErrors(source); |
| 2285 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 2285 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 2286 verify([source]); | 2286 verify([source]); |
| 2287 } | 2287 } |
| 2288 | 2288 |
| 2289 void test_deadCode_deadBlock_conditionalElse() { | 2289 void test_deadCode_deadBlock_conditionalElse() { |
| 2290 Source source = addSource(r''' | 2290 Source source = addSource(r''' |
| 2291 f() { | 2291 f() { |
| 2292 true ? 1 : 2; | 2292 true ? 1 : 2; |
| 2293 }'''); | 2293 }'''); |
| 2294 resolve(source); | 2294 computeLibrarySourceErrors(source); |
| 2295 assertErrors(source, [HintCode.DEAD_CODE]); | 2295 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2296 verify([source]); | 2296 verify([source]); |
| 2297 } | 2297 } |
| 2298 | 2298 |
| 2299 void test_deadCode_deadBlock_conditionalElse_nested() { | 2299 void test_deadCode_deadBlock_conditionalElse_nested() { |
| 2300 // test that a dead else-statement can't generate additional violations | 2300 // test that a dead else-statement can't generate additional violations |
| 2301 Source source = addSource(r''' | 2301 Source source = addSource(r''' |
| 2302 f() { | 2302 f() { |
| 2303 true ? true : false && false; | 2303 true ? true : false && false; |
| 2304 }'''); | 2304 }'''); |
| 2305 resolve(source); | 2305 computeLibrarySourceErrors(source); |
| 2306 assertErrors(source, [HintCode.DEAD_CODE]); | 2306 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2307 verify([source]); | 2307 verify([source]); |
| 2308 } | 2308 } |
| 2309 | 2309 |
| 2310 void test_deadCode_deadBlock_conditionalIf() { | 2310 void test_deadCode_deadBlock_conditionalIf() { |
| 2311 Source source = addSource(r''' | 2311 Source source = addSource(r''' |
| 2312 f() { | 2312 f() { |
| 2313 false ? 1 : 2; | 2313 false ? 1 : 2; |
| 2314 }'''); | 2314 }'''); |
| 2315 resolve(source); | 2315 computeLibrarySourceErrors(source); |
| 2316 assertErrors(source, [HintCode.DEAD_CODE]); | 2316 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2317 verify([source]); | 2317 verify([source]); |
| 2318 } | 2318 } |
| 2319 | 2319 |
| 2320 void test_deadCode_deadBlock_conditionalIf_nested() { | 2320 void test_deadCode_deadBlock_conditionalIf_nested() { |
| 2321 // test that a dead then-statement can't generate additional violations | 2321 // test that a dead then-statement can't generate additional violations |
| 2322 Source source = addSource(r''' | 2322 Source source = addSource(r''' |
| 2323 f() { | 2323 f() { |
| 2324 false ? false && false : true; | 2324 false ? false && false : true; |
| 2325 }'''); | 2325 }'''); |
| 2326 resolve(source); | 2326 computeLibrarySourceErrors(source); |
| 2327 assertErrors(source, [HintCode.DEAD_CODE]); | 2327 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2328 verify([source]); | 2328 verify([source]); |
| 2329 } | 2329 } |
| 2330 | 2330 |
| 2331 void test_deadCode_deadBlock_else() { | 2331 void test_deadCode_deadBlock_else() { |
| 2332 Source source = addSource(r''' | 2332 Source source = addSource(r''' |
| 2333 f() { | 2333 f() { |
| 2334 if(true) {} else {} | 2334 if(true) {} else {} |
| 2335 }'''); | 2335 }'''); |
| 2336 resolve(source); | 2336 computeLibrarySourceErrors(source); |
| 2337 assertErrors(source, [HintCode.DEAD_CODE]); | 2337 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2338 verify([source]); | 2338 verify([source]); |
| 2339 } | 2339 } |
| 2340 | 2340 |
| 2341 void test_deadCode_deadBlock_else_nested() { | 2341 void test_deadCode_deadBlock_else_nested() { |
| 2342 // test that a dead else-statement can't generate additional violations | 2342 // test that a dead else-statement can't generate additional violations |
| 2343 Source source = addSource(r''' | 2343 Source source = addSource(r''' |
| 2344 f() { | 2344 f() { |
| 2345 if(true) {} else {if (false) {}} | 2345 if(true) {} else {if (false) {}} |
| 2346 }'''); | 2346 }'''); |
| 2347 resolve(source); | 2347 computeLibrarySourceErrors(source); |
| 2348 assertErrors(source, [HintCode.DEAD_CODE]); | 2348 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2349 verify([source]); | 2349 verify([source]); |
| 2350 } | 2350 } |
| 2351 | 2351 |
| 2352 void test_deadCode_deadBlock_if() { | 2352 void test_deadCode_deadBlock_if() { |
| 2353 Source source = addSource(r''' | 2353 Source source = addSource(r''' |
| 2354 f() { | 2354 f() { |
| 2355 if(false) {} | 2355 if(false) {} |
| 2356 }'''); | 2356 }'''); |
| 2357 resolve(source); | 2357 computeLibrarySourceErrors(source); |
| 2358 assertErrors(source, [HintCode.DEAD_CODE]); | 2358 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2359 verify([source]); | 2359 verify([source]); |
| 2360 } | 2360 } |
| 2361 | 2361 |
| 2362 void test_deadCode_deadBlock_if_nested() { | 2362 void test_deadCode_deadBlock_if_nested() { |
| 2363 // test that a dead then-statement can't generate additional violations | 2363 // test that a dead then-statement can't generate additional violations |
| 2364 Source source = addSource(r''' | 2364 Source source = addSource(r''' |
| 2365 f() { | 2365 f() { |
| 2366 if(false) {if(false) {}} | 2366 if(false) {if(false) {}} |
| 2367 }'''); | 2367 }'''); |
| 2368 resolve(source); | 2368 computeLibrarySourceErrors(source); |
| 2369 assertErrors(source, [HintCode.DEAD_CODE]); | 2369 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2370 verify([source]); | 2370 verify([source]); |
| 2371 } | 2371 } |
| 2372 | 2372 |
| 2373 void test_deadCode_deadBlock_while() { | 2373 void test_deadCode_deadBlock_while() { |
| 2374 Source source = addSource(r''' | 2374 Source source = addSource(r''' |
| 2375 f() { | 2375 f() { |
| 2376 while(false) {} | 2376 while(false) {} |
| 2377 }'''); | 2377 }'''); |
| 2378 resolve(source); | 2378 computeLibrarySourceErrors(source); |
| 2379 assertErrors(source, [HintCode.DEAD_CODE]); | 2379 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2380 verify([source]); | 2380 verify([source]); |
| 2381 } | 2381 } |
| 2382 | 2382 |
| 2383 void test_deadCode_deadBlock_while_nested() { | 2383 void test_deadCode_deadBlock_while_nested() { |
| 2384 // test that a dead while body can't generate additional violations | 2384 // test that a dead while body can't generate additional violations |
| 2385 Source source = addSource(r''' | 2385 Source source = addSource(r''' |
| 2386 f() { | 2386 f() { |
| 2387 while(false) {if(false) {}} | 2387 while(false) {if(false) {}} |
| 2388 }'''); | 2388 }'''); |
| 2389 resolve(source); | 2389 computeLibrarySourceErrors(source); |
| 2390 assertErrors(source, [HintCode.DEAD_CODE]); | 2390 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2391 verify([source]); | 2391 verify([source]); |
| 2392 } | 2392 } |
| 2393 | 2393 |
| 2394 void test_deadCode_deadCatch_catchFollowingCatch() { | 2394 void test_deadCode_deadCatch_catchFollowingCatch() { |
| 2395 Source source = addSource(r''' | 2395 Source source = addSource(r''' |
| 2396 class A {} | 2396 class A {} |
| 2397 f() { | 2397 f() { |
| 2398 try {} catch (e) {} catch (e) {} | 2398 try {} catch (e) {} catch (e) {} |
| 2399 }'''); | 2399 }'''); |
| 2400 resolve(source); | 2400 computeLibrarySourceErrors(source); |
| 2401 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 2401 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 2402 verify([source]); | 2402 verify([source]); |
| 2403 } | 2403 } |
| 2404 | 2404 |
| 2405 void test_deadCode_deadCatch_catchFollowingCatch_nested() { | 2405 void test_deadCode_deadCatch_catchFollowingCatch_nested() { |
| 2406 // test that a dead catch clause can't generate additional violations | 2406 // test that a dead catch clause can't generate additional violations |
| 2407 Source source = addSource(r''' | 2407 Source source = addSource(r''' |
| 2408 class A {} | 2408 class A {} |
| 2409 f() { | 2409 f() { |
| 2410 try {} catch (e) {} catch (e) {if(false) {}} | 2410 try {} catch (e) {} catch (e) {if(false) {}} |
| 2411 }'''); | 2411 }'''); |
| 2412 resolve(source); | 2412 computeLibrarySourceErrors(source); |
| 2413 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 2413 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 2414 verify([source]); | 2414 verify([source]); |
| 2415 } | 2415 } |
| 2416 | 2416 |
| 2417 void test_deadCode_deadCatch_catchFollowingCatch_object() { | 2417 void test_deadCode_deadCatch_catchFollowingCatch_object() { |
| 2418 Source source = addSource(r''' | 2418 Source source = addSource(r''' |
| 2419 f() { | 2419 f() { |
| 2420 try {} on Object catch (e) {} catch (e) {} | 2420 try {} on Object catch (e) {} catch (e) {} |
| 2421 }'''); | 2421 }'''); |
| 2422 resolve(source); | 2422 computeLibrarySourceErrors(source); |
| 2423 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 2423 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 2424 verify([source]); | 2424 verify([source]); |
| 2425 } | 2425 } |
| 2426 | 2426 |
| 2427 void test_deadCode_deadCatch_catchFollowingCatch_object_nested() { | 2427 void test_deadCode_deadCatch_catchFollowingCatch_object_nested() { |
| 2428 // test that a dead catch clause can't generate additional violations | 2428 // test that a dead catch clause can't generate additional violations |
| 2429 Source source = addSource(r''' | 2429 Source source = addSource(r''' |
| 2430 f() { | 2430 f() { |
| 2431 try {} on Object catch (e) {} catch (e) {if(false) {}} | 2431 try {} on Object catch (e) {} catch (e) {if(false) {}} |
| 2432 }'''); | 2432 }'''); |
| 2433 resolve(source); | 2433 computeLibrarySourceErrors(source); |
| 2434 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); | 2434 assertErrors(source, [HintCode.DEAD_CODE_CATCH_FOLLOWING_CATCH]); |
| 2435 verify([source]); | 2435 verify([source]); |
| 2436 } | 2436 } |
| 2437 | 2437 |
| 2438 void test_deadCode_deadCatch_onCatchSubtype() { | 2438 void test_deadCode_deadCatch_onCatchSubtype() { |
| 2439 Source source = addSource(r''' | 2439 Source source = addSource(r''' |
| 2440 class A {} | 2440 class A {} |
| 2441 class B extends A {} | 2441 class B extends A {} |
| 2442 f() { | 2442 f() { |
| 2443 try {} on A catch (e) {} on B catch (e) {} | 2443 try {} on A catch (e) {} on B catch (e) {} |
| 2444 }'''); | 2444 }'''); |
| 2445 resolve(source); | 2445 computeLibrarySourceErrors(source); |
| 2446 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); | 2446 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); |
| 2447 verify([source]); | 2447 verify([source]); |
| 2448 } | 2448 } |
| 2449 | 2449 |
| 2450 void test_deadCode_deadCatch_onCatchSubtype_nested() { | 2450 void test_deadCode_deadCatch_onCatchSubtype_nested() { |
| 2451 // test that a dead catch clause can't generate additional violations | 2451 // test that a dead catch clause can't generate additional violations |
| 2452 Source source = addSource(r''' | 2452 Source source = addSource(r''' |
| 2453 class A {} | 2453 class A {} |
| 2454 class B extends A {} | 2454 class B extends A {} |
| 2455 f() { | 2455 f() { |
| 2456 try {} on A catch (e) {} on B catch (e) {if(false) {}} | 2456 try {} on A catch (e) {} on B catch (e) {if(false) {}} |
| 2457 }'''); | 2457 }'''); |
| 2458 resolve(source); | 2458 computeLibrarySourceErrors(source); |
| 2459 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); | 2459 assertErrors(source, [HintCode.DEAD_CODE_ON_CATCH_SUBTYPE]); |
| 2460 verify([source]); | 2460 verify([source]); |
| 2461 } | 2461 } |
| 2462 | 2462 |
| 2463 void test_deadCode_deadOperandLHS_and() { | 2463 void test_deadCode_deadOperandLHS_and() { |
| 2464 Source source = addSource(r''' | 2464 Source source = addSource(r''' |
| 2465 f() { | 2465 f() { |
| 2466 bool b = false && false; | 2466 bool b = false && false; |
| 2467 }'''); | 2467 }'''); |
| 2468 resolve(source); | 2468 computeLibrarySourceErrors(source); |
| 2469 assertErrors(source, [HintCode.DEAD_CODE]); | 2469 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2470 verify([source]); | 2470 verify([source]); |
| 2471 } | 2471 } |
| 2472 | 2472 |
| 2473 void test_deadCode_deadOperandLHS_and_nested() { | 2473 void test_deadCode_deadOperandLHS_and_nested() { |
| 2474 Source source = addSource(r''' | 2474 Source source = addSource(r''' |
| 2475 f() { | 2475 f() { |
| 2476 bool b = false && (false && false); | 2476 bool b = false && (false && false); |
| 2477 }'''); | 2477 }'''); |
| 2478 resolve(source); | 2478 computeLibrarySourceErrors(source); |
| 2479 assertErrors(source, [HintCode.DEAD_CODE]); | 2479 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2480 verify([source]); | 2480 verify([source]); |
| 2481 } | 2481 } |
| 2482 | 2482 |
| 2483 void test_deadCode_deadOperandLHS_or() { | 2483 void test_deadCode_deadOperandLHS_or() { |
| 2484 Source source = addSource(r''' | 2484 Source source = addSource(r''' |
| 2485 f() { | 2485 f() { |
| 2486 bool b = true || true; | 2486 bool b = true || true; |
| 2487 }'''); | 2487 }'''); |
| 2488 resolve(source); | 2488 computeLibrarySourceErrors(source); |
| 2489 assertErrors(source, [HintCode.DEAD_CODE]); | 2489 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2490 verify([source]); | 2490 verify([source]); |
| 2491 } | 2491 } |
| 2492 | 2492 |
| 2493 void test_deadCode_deadOperandLHS_or_nested() { | 2493 void test_deadCode_deadOperandLHS_or_nested() { |
| 2494 Source source = addSource(r''' | 2494 Source source = addSource(r''' |
| 2495 f() { | 2495 f() { |
| 2496 bool b = true || (false && false); | 2496 bool b = true || (false && false); |
| 2497 }'''); | 2497 }'''); |
| 2498 resolve(source); | 2498 computeLibrarySourceErrors(source); |
| 2499 assertErrors(source, [HintCode.DEAD_CODE]); | 2499 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2500 verify([source]); | 2500 verify([source]); |
| 2501 } | 2501 } |
| 2502 | 2502 |
| 2503 void test_deadCode_statementAfterBreak_inDefaultCase() { | 2503 void test_deadCode_statementAfterBreak_inDefaultCase() { |
| 2504 Source source = addSource(r''' | 2504 Source source = addSource(r''' |
| 2505 f(v) { | 2505 f(v) { |
| 2506 switch(v) { | 2506 switch(v) { |
| 2507 case 1: | 2507 case 1: |
| 2508 default: | 2508 default: |
| 2509 break; | 2509 break; |
| 2510 var a; | 2510 var a; |
| 2511 } | 2511 } |
| 2512 }'''); | 2512 }'''); |
| 2513 resolve(source); | 2513 computeLibrarySourceErrors(source); |
| 2514 assertErrors(source, [HintCode.DEAD_CODE]); | 2514 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2515 verify([source]); | 2515 verify([source]); |
| 2516 } | 2516 } |
| 2517 | 2517 |
| 2518 void test_deadCode_statementAfterBreak_inForEachStatement() { | 2518 void test_deadCode_statementAfterBreak_inForEachStatement() { |
| 2519 Source source = addSource(r''' | 2519 Source source = addSource(r''' |
| 2520 f() { | 2520 f() { |
| 2521 var list; | 2521 var list; |
| 2522 for(var l in list) { | 2522 for(var l in list) { |
| 2523 break; | 2523 break; |
| 2524 var a; | 2524 var a; |
| 2525 } | 2525 } |
| 2526 }'''); | 2526 }'''); |
| 2527 resolve(source); | 2527 computeLibrarySourceErrors(source); |
| 2528 assertErrors(source, [HintCode.DEAD_CODE]); | 2528 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2529 verify([source]); | 2529 verify([source]); |
| 2530 } | 2530 } |
| 2531 | 2531 |
| 2532 void test_deadCode_statementAfterBreak_inForStatement() { | 2532 void test_deadCode_statementAfterBreak_inForStatement() { |
| 2533 Source source = addSource(r''' | 2533 Source source = addSource(r''' |
| 2534 f() { | 2534 f() { |
| 2535 for(;;) { | 2535 for(;;) { |
| 2536 break; | 2536 break; |
| 2537 var a; | 2537 var a; |
| 2538 } | 2538 } |
| 2539 }'''); | 2539 }'''); |
| 2540 resolve(source); | 2540 computeLibrarySourceErrors(source); |
| 2541 assertErrors(source, [HintCode.DEAD_CODE]); | 2541 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2542 verify([source]); | 2542 verify([source]); |
| 2543 } | 2543 } |
| 2544 | 2544 |
| 2545 void test_deadCode_statementAfterBreak_inSwitchCase() { | 2545 void test_deadCode_statementAfterBreak_inSwitchCase() { |
| 2546 Source source = addSource(r''' | 2546 Source source = addSource(r''' |
| 2547 f(v) { | 2547 f(v) { |
| 2548 switch(v) { | 2548 switch(v) { |
| 2549 case 1: | 2549 case 1: |
| 2550 break; | 2550 break; |
| 2551 var a; | 2551 var a; |
| 2552 } | 2552 } |
| 2553 }'''); | 2553 }'''); |
| 2554 resolve(source); | 2554 computeLibrarySourceErrors(source); |
| 2555 assertErrors(source, [HintCode.DEAD_CODE]); | 2555 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2556 verify([source]); | 2556 verify([source]); |
| 2557 } | 2557 } |
| 2558 | 2558 |
| 2559 void test_deadCode_statementAfterBreak_inWhileStatement() { | 2559 void test_deadCode_statementAfterBreak_inWhileStatement() { |
| 2560 Source source = addSource(r''' | 2560 Source source = addSource(r''' |
| 2561 f(v) { | 2561 f(v) { |
| 2562 while(v) { | 2562 while(v) { |
| 2563 break; | 2563 break; |
| 2564 var a; | 2564 var a; |
| 2565 } | 2565 } |
| 2566 }'''); | 2566 }'''); |
| 2567 resolve(source); | 2567 computeLibrarySourceErrors(source); |
| 2568 assertErrors(source, [HintCode.DEAD_CODE]); | 2568 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2569 verify([source]); | 2569 verify([source]); |
| 2570 } | 2570 } |
| 2571 | 2571 |
| 2572 void test_deadCode_statementAfterContinue_inForEachStatement() { | 2572 void test_deadCode_statementAfterContinue_inForEachStatement() { |
| 2573 Source source = addSource(r''' | 2573 Source source = addSource(r''' |
| 2574 f() { | 2574 f() { |
| 2575 var list; | 2575 var list; |
| 2576 for(var l in list) { | 2576 for(var l in list) { |
| 2577 continue; | 2577 continue; |
| 2578 var a; | 2578 var a; |
| 2579 } | 2579 } |
| 2580 }'''); | 2580 }'''); |
| 2581 resolve(source); | 2581 computeLibrarySourceErrors(source); |
| 2582 assertErrors(source, [HintCode.DEAD_CODE]); | 2582 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2583 verify([source]); | 2583 verify([source]); |
| 2584 } | 2584 } |
| 2585 | 2585 |
| 2586 void test_deadCode_statementAfterContinue_inForStatement() { | 2586 void test_deadCode_statementAfterContinue_inForStatement() { |
| 2587 Source source = addSource(r''' | 2587 Source source = addSource(r''' |
| 2588 f() { | 2588 f() { |
| 2589 for(;;) { | 2589 for(;;) { |
| 2590 continue; | 2590 continue; |
| 2591 var a; | 2591 var a; |
| 2592 } | 2592 } |
| 2593 }'''); | 2593 }'''); |
| 2594 resolve(source); | 2594 computeLibrarySourceErrors(source); |
| 2595 assertErrors(source, [HintCode.DEAD_CODE]); | 2595 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2596 verify([source]); | 2596 verify([source]); |
| 2597 } | 2597 } |
| 2598 | 2598 |
| 2599 void test_deadCode_statementAfterContinue_inWhileStatement() { | 2599 void test_deadCode_statementAfterContinue_inWhileStatement() { |
| 2600 Source source = addSource(r''' | 2600 Source source = addSource(r''' |
| 2601 f(v) { | 2601 f(v) { |
| 2602 while(v) { | 2602 while(v) { |
| 2603 continue; | 2603 continue; |
| 2604 var a; | 2604 var a; |
| 2605 } | 2605 } |
| 2606 }'''); | 2606 }'''); |
| 2607 resolve(source); | 2607 computeLibrarySourceErrors(source); |
| 2608 assertErrors(source, [HintCode.DEAD_CODE]); | 2608 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2609 verify([source]); | 2609 verify([source]); |
| 2610 } | 2610 } |
| 2611 | 2611 |
| 2612 void test_deadCode_statementAfterReturn_function() { | 2612 void test_deadCode_statementAfterReturn_function() { |
| 2613 Source source = addSource(r''' | 2613 Source source = addSource(r''' |
| 2614 f() { | 2614 f() { |
| 2615 var one = 1; | 2615 var one = 1; |
| 2616 return; | 2616 return; |
| 2617 var two = 2; | 2617 var two = 2; |
| 2618 }'''); | 2618 }'''); |
| 2619 resolve(source); | 2619 computeLibrarySourceErrors(source); |
| 2620 assertErrors(source, [HintCode.DEAD_CODE]); | 2620 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2621 verify([source]); | 2621 verify([source]); |
| 2622 } | 2622 } |
| 2623 | 2623 |
| 2624 void test_deadCode_statementAfterReturn_ifStatement() { | 2624 void test_deadCode_statementAfterReturn_ifStatement() { |
| 2625 Source source = addSource(r''' | 2625 Source source = addSource(r''' |
| 2626 f(bool b) { | 2626 f(bool b) { |
| 2627 if(b) { | 2627 if(b) { |
| 2628 var one = 1; | 2628 var one = 1; |
| 2629 return; | 2629 return; |
| 2630 var two = 2; | 2630 var two = 2; |
| 2631 } | 2631 } |
| 2632 }'''); | 2632 }'''); |
| 2633 resolve(source); | 2633 computeLibrarySourceErrors(source); |
| 2634 assertErrors(source, [HintCode.DEAD_CODE]); | 2634 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2635 verify([source]); | 2635 verify([source]); |
| 2636 } | 2636 } |
| 2637 | 2637 |
| 2638 void test_deadCode_statementAfterReturn_method() { | 2638 void test_deadCode_statementAfterReturn_method() { |
| 2639 Source source = addSource(r''' | 2639 Source source = addSource(r''' |
| 2640 class A { | 2640 class A { |
| 2641 m() { | 2641 m() { |
| 2642 var one = 1; | 2642 var one = 1; |
| 2643 return; | 2643 return; |
| 2644 var two = 2; | 2644 var two = 2; |
| 2645 } | 2645 } |
| 2646 }'''); | 2646 }'''); |
| 2647 resolve(source); | 2647 computeLibrarySourceErrors(source); |
| 2648 assertErrors(source, [HintCode.DEAD_CODE]); | 2648 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2649 verify([source]); | 2649 verify([source]); |
| 2650 } | 2650 } |
| 2651 | 2651 |
| 2652 void test_deadCode_statementAfterReturn_nested() { | 2652 void test_deadCode_statementAfterReturn_nested() { |
| 2653 Source source = addSource(r''' | 2653 Source source = addSource(r''' |
| 2654 f() { | 2654 f() { |
| 2655 var one = 1; | 2655 var one = 1; |
| 2656 return; | 2656 return; |
| 2657 if(false) {} | 2657 if(false) {} |
| 2658 }'''); | 2658 }'''); |
| 2659 resolve(source); | 2659 computeLibrarySourceErrors(source); |
| 2660 assertErrors(source, [HintCode.DEAD_CODE]); | 2660 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2661 verify([source]); | 2661 verify([source]); |
| 2662 } | 2662 } |
| 2663 | 2663 |
| 2664 void test_deadCode_statementAfterReturn_twoReturns() { | 2664 void test_deadCode_statementAfterReturn_twoReturns() { |
| 2665 Source source = addSource(r''' | 2665 Source source = addSource(r''' |
| 2666 f() { | 2666 f() { |
| 2667 var one = 1; | 2667 var one = 1; |
| 2668 return; | 2668 return; |
| 2669 var two = 2; | 2669 var two = 2; |
| 2670 return; | 2670 return; |
| 2671 var three = 3; | 2671 var three = 3; |
| 2672 }'''); | 2672 }'''); |
| 2673 resolve(source); | 2673 computeLibrarySourceErrors(source); |
| 2674 assertErrors(source, [HintCode.DEAD_CODE]); | 2674 assertErrors(source, [HintCode.DEAD_CODE]); |
| 2675 verify([source]); | 2675 verify([source]); |
| 2676 } | 2676 } |
| 2677 | 2677 |
| 2678 void test_deprecatedAnnotationUse_assignment() { | 2678 void test_deprecatedAnnotationUse_assignment() { |
| 2679 Source source = addSource(r''' | 2679 Source source = addSource(r''' |
| 2680 class A { | 2680 class A { |
| 2681 @deprecated | 2681 @deprecated |
| 2682 A operator+(A a) { return a; } | 2682 A operator+(A a) { return a; } |
| 2683 } | 2683 } |
| 2684 f(A a) { | 2684 f(A a) { |
| 2685 A b; | 2685 A b; |
| 2686 a += b; | 2686 a += b; |
| 2687 }'''); | 2687 }'''); |
| 2688 resolve(source); | 2688 computeLibrarySourceErrors(source); |
| 2689 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2689 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2690 verify([source]); | 2690 verify([source]); |
| 2691 } | 2691 } |
| 2692 | 2692 |
| 2693 void test_deprecatedAnnotationUse_Deprecated() { | 2693 void test_deprecatedAnnotationUse_Deprecated() { |
| 2694 Source source = addSource(r''' | 2694 Source source = addSource(r''' |
| 2695 class A { | 2695 class A { |
| 2696 @Deprecated('0.9') | 2696 @Deprecated('0.9') |
| 2697 m() {} | 2697 m() {} |
| 2698 n() {m();} | 2698 n() {m();} |
| 2699 }'''); | 2699 }'''); |
| 2700 resolve(source); | 2700 computeLibrarySourceErrors(source); |
| 2701 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2701 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2702 verify([source]); | 2702 verify([source]); |
| 2703 } | 2703 } |
| 2704 | 2704 |
| 2705 void test_deprecatedAnnotationUse_deprecated() { | 2705 void test_deprecatedAnnotationUse_deprecated() { |
| 2706 Source source = addSource(r''' | 2706 Source source = addSource(r''' |
| 2707 class A { | 2707 class A { |
| 2708 @deprecated | 2708 @deprecated |
| 2709 m() {} | 2709 m() {} |
| 2710 n() {m();} | 2710 n() {m();} |
| 2711 }'''); | 2711 }'''); |
| 2712 resolve(source); | 2712 computeLibrarySourceErrors(source); |
| 2713 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2713 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2714 verify([source]); | 2714 verify([source]); |
| 2715 } | 2715 } |
| 2716 | 2716 |
| 2717 void test_deprecatedAnnotationUse_export() { | 2717 void test_deprecatedAnnotationUse_export() { |
| 2718 Source source = addSource("export 'deprecated_library.dart';"); | 2718 Source source = addSource("export 'deprecated_library.dart';"); |
| 2719 addNamedSource("/deprecated_library.dart", r''' | 2719 addNamedSource("/deprecated_library.dart", r''' |
| 2720 @deprecated | 2720 @deprecated |
| 2721 library deprecated_library; | 2721 library deprecated_library; |
| 2722 class A {}'''); | 2722 class A {}'''); |
| 2723 resolve(source); | 2723 computeLibrarySourceErrors(source); |
| 2724 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2724 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2725 verify([source]); | 2725 verify([source]); |
| 2726 } | 2726 } |
| 2727 | 2727 |
| 2728 void test_deprecatedAnnotationUse_getter() { | 2728 void test_deprecatedAnnotationUse_getter() { |
| 2729 Source source = addSource(r''' | 2729 Source source = addSource(r''' |
| 2730 class A { | 2730 class A { |
| 2731 @deprecated | 2731 @deprecated |
| 2732 get m => 1; | 2732 get m => 1; |
| 2733 } | 2733 } |
| 2734 f(A a) { | 2734 f(A a) { |
| 2735 return a.m; | 2735 return a.m; |
| 2736 }'''); | 2736 }'''); |
| 2737 resolve(source); | 2737 computeLibrarySourceErrors(source); |
| 2738 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2738 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2739 verify([source]); | 2739 verify([source]); |
| 2740 } | 2740 } |
| 2741 | 2741 |
| 2742 void test_deprecatedAnnotationUse_import() { | 2742 void test_deprecatedAnnotationUse_import() { |
| 2743 Source source = addSource(r''' | 2743 Source source = addSource(r''' |
| 2744 import 'deprecated_library.dart'; | 2744 import 'deprecated_library.dart'; |
| 2745 f(A a) {}'''); | 2745 f(A a) {}'''); |
| 2746 addNamedSource("/deprecated_library.dart", r''' | 2746 addNamedSource("/deprecated_library.dart", r''' |
| 2747 @deprecated | 2747 @deprecated |
| 2748 library deprecated_library; | 2748 library deprecated_library; |
| 2749 class A {}'''); | 2749 class A {}'''); |
| 2750 resolve(source); | 2750 computeLibrarySourceErrors(source); |
| 2751 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2751 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2752 verify([source]); | 2752 verify([source]); |
| 2753 } | 2753 } |
| 2754 | 2754 |
| 2755 void test_deprecatedAnnotationUse_indexExpression() { | 2755 void test_deprecatedAnnotationUse_indexExpression() { |
| 2756 Source source = addSource(r''' | 2756 Source source = addSource(r''' |
| 2757 class A { | 2757 class A { |
| 2758 @deprecated | 2758 @deprecated |
| 2759 operator[](int i) {} | 2759 operator[](int i) {} |
| 2760 } | 2760 } |
| 2761 f(A a) { | 2761 f(A a) { |
| 2762 return a[1]; | 2762 return a[1]; |
| 2763 }'''); | 2763 }'''); |
| 2764 resolve(source); | 2764 computeLibrarySourceErrors(source); |
| 2765 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2765 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2766 verify([source]); | 2766 verify([source]); |
| 2767 } | 2767 } |
| 2768 | 2768 |
| 2769 void test_deprecatedAnnotationUse_instanceCreation() { | 2769 void test_deprecatedAnnotationUse_instanceCreation() { |
| 2770 Source source = addSource(r''' | 2770 Source source = addSource(r''' |
| 2771 class A { | 2771 class A { |
| 2772 @deprecated | 2772 @deprecated |
| 2773 A(int i) {} | 2773 A(int i) {} |
| 2774 } | 2774 } |
| 2775 f() { | 2775 f() { |
| 2776 A a = new A(1); | 2776 A a = new A(1); |
| 2777 }'''); | 2777 }'''); |
| 2778 resolve(source); | 2778 computeLibrarySourceErrors(source); |
| 2779 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2779 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2780 verify([source]); | 2780 verify([source]); |
| 2781 } | 2781 } |
| 2782 | 2782 |
| 2783 void test_deprecatedAnnotationUse_instanceCreation_namedConstructor() { | 2783 void test_deprecatedAnnotationUse_instanceCreation_namedConstructor() { |
| 2784 Source source = addSource(r''' | 2784 Source source = addSource(r''' |
| 2785 class A { | 2785 class A { |
| 2786 @deprecated | 2786 @deprecated |
| 2787 A.named(int i) {} | 2787 A.named(int i) {} |
| 2788 } | 2788 } |
| 2789 f() { | 2789 f() { |
| 2790 A a = new A.named(1); | 2790 A a = new A.named(1); |
| 2791 }'''); | 2791 }'''); |
| 2792 resolve(source); | 2792 computeLibrarySourceErrors(source); |
| 2793 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2793 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2794 verify([source]); | 2794 verify([source]); |
| 2795 } | 2795 } |
| 2796 | 2796 |
| 2797 void test_deprecatedAnnotationUse_operator() { | 2797 void test_deprecatedAnnotationUse_operator() { |
| 2798 Source source = addSource(r''' | 2798 Source source = addSource(r''' |
| 2799 class A { | 2799 class A { |
| 2800 @deprecated | 2800 @deprecated |
| 2801 operator+(A a) {} | 2801 operator+(A a) {} |
| 2802 } | 2802 } |
| 2803 f(A a) { | 2803 f(A a) { |
| 2804 A b; | 2804 A b; |
| 2805 return a + b; | 2805 return a + b; |
| 2806 }'''); | 2806 }'''); |
| 2807 resolve(source); | 2807 computeLibrarySourceErrors(source); |
| 2808 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2808 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2809 verify([source]); | 2809 verify([source]); |
| 2810 } | 2810 } |
| 2811 | 2811 |
| 2812 void test_deprecatedAnnotationUse_setter() { | 2812 void test_deprecatedAnnotationUse_setter() { |
| 2813 Source source = addSource(r''' | 2813 Source source = addSource(r''' |
| 2814 class A { | 2814 class A { |
| 2815 @deprecated | 2815 @deprecated |
| 2816 set s(v) {} | 2816 set s(v) {} |
| 2817 } | 2817 } |
| 2818 f(A a) { | 2818 f(A a) { |
| 2819 return a.s = 1; | 2819 return a.s = 1; |
| 2820 }'''); | 2820 }'''); |
| 2821 resolve(source); | 2821 computeLibrarySourceErrors(source); |
| 2822 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2822 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2823 verify([source]); | 2823 verify([source]); |
| 2824 } | 2824 } |
| 2825 | 2825 |
| 2826 void test_deprecatedAnnotationUse_superConstructor() { | 2826 void test_deprecatedAnnotationUse_superConstructor() { |
| 2827 Source source = addSource(r''' | 2827 Source source = addSource(r''' |
| 2828 class A { | 2828 class A { |
| 2829 @deprecated | 2829 @deprecated |
| 2830 A() {} | 2830 A() {} |
| 2831 } | 2831 } |
| 2832 class B extends A { | 2832 class B extends A { |
| 2833 B() : super() {} | 2833 B() : super() {} |
| 2834 }'''); | 2834 }'''); |
| 2835 resolve(source); | 2835 computeLibrarySourceErrors(source); |
| 2836 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2836 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2837 verify([source]); | 2837 verify([source]); |
| 2838 } | 2838 } |
| 2839 | 2839 |
| 2840 void test_deprecatedAnnotationUse_superConstructor_namedConstructor() { | 2840 void test_deprecatedAnnotationUse_superConstructor_namedConstructor() { |
| 2841 Source source = addSource(r''' | 2841 Source source = addSource(r''' |
| 2842 class A { | 2842 class A { |
| 2843 @deprecated | 2843 @deprecated |
| 2844 A.named() {} | 2844 A.named() {} |
| 2845 } | 2845 } |
| 2846 class B extends A { | 2846 class B extends A { |
| 2847 B() : super.named() {} | 2847 B() : super.named() {} |
| 2848 }'''); | 2848 }'''); |
| 2849 resolve(source); | 2849 computeLibrarySourceErrors(source); |
| 2850 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); | 2850 assertErrors(source, [HintCode.DEPRECATED_MEMBER_USE]); |
| 2851 verify([source]); | 2851 verify([source]); |
| 2852 } | 2852 } |
| 2853 | 2853 |
| 2854 void test_divisionOptimization_double() { | 2854 void test_divisionOptimization_double() { |
| 2855 Source source = addSource(r''' | 2855 Source source = addSource(r''' |
| 2856 f(double x, double y) { | 2856 f(double x, double y) { |
| 2857 var v = (x / y).toInt(); | 2857 var v = (x / y).toInt(); |
| 2858 }'''); | 2858 }'''); |
| 2859 resolve(source); | 2859 computeLibrarySourceErrors(source); |
| 2860 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 2860 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 2861 verify([source]); | 2861 verify([source]); |
| 2862 } | 2862 } |
| 2863 | 2863 |
| 2864 void test_divisionOptimization_int() { | 2864 void test_divisionOptimization_int() { |
| 2865 Source source = addSource(r''' | 2865 Source source = addSource(r''' |
| 2866 f(int x, int y) { | 2866 f(int x, int y) { |
| 2867 var v = (x / y).toInt(); | 2867 var v = (x / y).toInt(); |
| 2868 }'''); | 2868 }'''); |
| 2869 resolve(source); | 2869 computeLibrarySourceErrors(source); |
| 2870 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 2870 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 2871 verify([source]); | 2871 verify([source]); |
| 2872 } | 2872 } |
| 2873 | 2873 |
| 2874 void test_divisionOptimization_propagatedType() { | 2874 void test_divisionOptimization_propagatedType() { |
| 2875 // Tests the propagated type information of the '/' method | 2875 // Tests the propagated type information of the '/' method |
| 2876 Source source = addSource(r''' | 2876 Source source = addSource(r''' |
| 2877 f(x, y) { | 2877 f(x, y) { |
| 2878 x = 1; | 2878 x = 1; |
| 2879 y = 1; | 2879 y = 1; |
| 2880 var v = (x / y).toInt(); | 2880 var v = (x / y).toInt(); |
| 2881 }'''); | 2881 }'''); |
| 2882 resolve(source); | 2882 computeLibrarySourceErrors(source); |
| 2883 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 2883 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 2884 verify([source]); | 2884 verify([source]); |
| 2885 } | 2885 } |
| 2886 | 2886 |
| 2887 void test_divisionOptimization_wrappedBinaryExpression() { | 2887 void test_divisionOptimization_wrappedBinaryExpression() { |
| 2888 Source source = addSource(r''' | 2888 Source source = addSource(r''' |
| 2889 f(int x, int y) { | 2889 f(int x, int y) { |
| 2890 var v = (((x / y))).toInt(); | 2890 var v = (((x / y))).toInt(); |
| 2891 }'''); | 2891 }'''); |
| 2892 resolve(source); | 2892 computeLibrarySourceErrors(source); |
| 2893 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); | 2893 assertErrors(source, [HintCode.DIVISION_OPTIMIZATION]); |
| 2894 verify([source]); | 2894 verify([source]); |
| 2895 } | 2895 } |
| 2896 | 2896 |
| 2897 void test_duplicateImport() { | 2897 void test_duplicateImport() { |
| 2898 Source source = addSource(r''' | 2898 Source source = addSource(r''' |
| 2899 library L; | 2899 library L; |
| 2900 import 'lib1.dart'; | 2900 import 'lib1.dart'; |
| 2901 import 'lib1.dart'; | 2901 import 'lib1.dart'; |
| 2902 A a;'''); | 2902 A a;'''); |
| 2903 addNamedSource("/lib1.dart", r''' | 2903 addNamedSource("/lib1.dart", r''' |
| 2904 library lib1; | 2904 library lib1; |
| 2905 class A {}'''); | 2905 class A {}'''); |
| 2906 resolve(source); | 2906 computeLibrarySourceErrors(source); |
| 2907 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); | 2907 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); |
| 2908 verify([source]); | 2908 verify([source]); |
| 2909 } | 2909 } |
| 2910 | 2910 |
| 2911 void test_duplicateImport2() { | 2911 void test_duplicateImport2() { |
| 2912 Source source = addSource(r''' | 2912 Source source = addSource(r''' |
| 2913 library L; | 2913 library L; |
| 2914 import 'lib1.dart'; | 2914 import 'lib1.dart'; |
| 2915 import 'lib1.dart'; | 2915 import 'lib1.dart'; |
| 2916 import 'lib1.dart'; | 2916 import 'lib1.dart'; |
| 2917 A a;'''); | 2917 A a;'''); |
| 2918 addNamedSource("/lib1.dart", r''' | 2918 addNamedSource("/lib1.dart", r''' |
| 2919 library lib1; | 2919 library lib1; |
| 2920 class A {}'''); | 2920 class A {}'''); |
| 2921 resolve(source); | 2921 computeLibrarySourceErrors(source); |
| 2922 assertErrors( | 2922 assertErrors( |
| 2923 source, [HintCode.DUPLICATE_IMPORT, HintCode.DUPLICATE_IMPORT]); | 2923 source, [HintCode.DUPLICATE_IMPORT, HintCode.DUPLICATE_IMPORT]); |
| 2924 verify([source]); | 2924 verify([source]); |
| 2925 } | 2925 } |
| 2926 | 2926 |
| 2927 void test_duplicateImport3() { | 2927 void test_duplicateImport3() { |
| 2928 Source source = addSource(r''' | 2928 Source source = addSource(r''' |
| 2929 library L; | 2929 library L; |
| 2930 import 'lib1.dart' as M show A hide B; | 2930 import 'lib1.dart' as M show A hide B; |
| 2931 import 'lib1.dart' as M show A hide B; | 2931 import 'lib1.dart' as M show A hide B; |
| 2932 M.A a;'''); | 2932 M.A a;'''); |
| 2933 addNamedSource("/lib1.dart", r''' | 2933 addNamedSource("/lib1.dart", r''' |
| 2934 library lib1; | 2934 library lib1; |
| 2935 class A {} | 2935 class A {} |
| 2936 class B {}'''); | 2936 class B {}'''); |
| 2937 resolve(source); | 2937 computeLibrarySourceErrors(source); |
| 2938 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); | 2938 assertErrors(source, [HintCode.DUPLICATE_IMPORT]); |
| 2939 verify([source]); | 2939 verify([source]); |
| 2940 } | 2940 } |
| 2941 | 2941 |
| 2942 void test_importDeferredLibraryWithLoadFunction() { | 2942 void test_importDeferredLibraryWithLoadFunction() { |
| 2943 resolveWithErrors(<String>[ | 2943 resolveWithErrors(<String>[ |
| 2944 r''' | 2944 r''' |
| 2945 library lib1; | 2945 library lib1; |
| 2946 loadLibrary() {} | 2946 loadLibrary() {} |
| 2947 f() {}''', | 2947 f() {}''', |
| 2948 r''' | 2948 r''' |
| 2949 library root; | 2949 library root; |
| 2950 import 'lib1.dart' deferred as lib1; | 2950 import 'lib1.dart' deferred as lib1; |
| 2951 main() { lib1.f(); }''' | 2951 main() { lib1.f(); }''' |
| 2952 ], <ErrorCode>[HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]); | 2952 ], <ErrorCode>[HintCode.IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION]); |
| 2953 } | 2953 } |
| 2954 | 2954 |
| 2955 void test_invalidAssignment_instanceVariable() { | 2955 void test_invalidAssignment_instanceVariable() { |
| 2956 Source source = addSource(r''' | 2956 Source source = addSource(r''' |
| 2957 class A { | 2957 class A { |
| 2958 int x; | 2958 int x; |
| 2959 } | 2959 } |
| 2960 f(var y) { | 2960 f(var y) { |
| 2961 A a; | 2961 A a; |
| 2962 if(y is String) { | 2962 if(y is String) { |
| 2963 a.x = y; | 2963 a.x = y; |
| 2964 } | 2964 } |
| 2965 }'''); | 2965 }'''); |
| 2966 resolve(source); | 2966 computeLibrarySourceErrors(source); |
| 2967 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 2967 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 2968 verify([source]); | 2968 verify([source]); |
| 2969 } | 2969 } |
| 2970 | 2970 |
| 2971 void test_invalidAssignment_localVariable() { | 2971 void test_invalidAssignment_localVariable() { |
| 2972 Source source = addSource(r''' | 2972 Source source = addSource(r''' |
| 2973 f(var y) { | 2973 f(var y) { |
| 2974 if(y is String) { | 2974 if(y is String) { |
| 2975 int x = y; | 2975 int x = y; |
| 2976 } | 2976 } |
| 2977 }'''); | 2977 }'''); |
| 2978 resolve(source); | 2978 computeLibrarySourceErrors(source); |
| 2979 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 2979 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 2980 verify([source]); | 2980 verify([source]); |
| 2981 } | 2981 } |
| 2982 | 2982 |
| 2983 void test_invalidAssignment_message() { | 2983 void test_invalidAssignment_message() { |
| 2984 // The implementation of HintCode.INVALID_ASSIGNMENT assumes that | 2984 // The implementation of HintCode.INVALID_ASSIGNMENT assumes that |
| 2985 // StaticTypeWarningCode.INVALID_ASSIGNMENT has the same message. | 2985 // StaticTypeWarningCode.INVALID_ASSIGNMENT has the same message. |
| 2986 expect(StaticTypeWarningCode.INVALID_ASSIGNMENT.message, | 2986 expect(StaticTypeWarningCode.INVALID_ASSIGNMENT.message, |
| 2987 HintCode.INVALID_ASSIGNMENT.message); | 2987 HintCode.INVALID_ASSIGNMENT.message); |
| 2988 } | 2988 } |
| 2989 | 2989 |
| 2990 void test_invalidAssignment_staticVariable() { | 2990 void test_invalidAssignment_staticVariable() { |
| 2991 Source source = addSource(r''' | 2991 Source source = addSource(r''' |
| 2992 class A { | 2992 class A { |
| 2993 static int x; | 2993 static int x; |
| 2994 } | 2994 } |
| 2995 f(var y) { | 2995 f(var y) { |
| 2996 if(y is String) { | 2996 if(y is String) { |
| 2997 A.x = y; | 2997 A.x = y; |
| 2998 } | 2998 } |
| 2999 }'''); | 2999 }'''); |
| 3000 resolve(source); | 3000 computeLibrarySourceErrors(source); |
| 3001 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 3001 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 3002 verify([source]); | 3002 verify([source]); |
| 3003 } | 3003 } |
| 3004 | 3004 |
| 3005 void test_invalidAssignment_variableDeclaration() { | 3005 void test_invalidAssignment_variableDeclaration() { |
| 3006 // 17971 | 3006 // 17971 |
| 3007 Source source = addSource(r''' | 3007 Source source = addSource(r''' |
| 3008 class Point { | 3008 class Point { |
| 3009 final num x, y; | 3009 final num x, y; |
| 3010 Point(this.x, this.y); | 3010 Point(this.x, this.y); |
| 3011 Point operator +(Point other) { | 3011 Point operator +(Point other) { |
| 3012 return new Point(x+other.x, y+other.y); | 3012 return new Point(x+other.x, y+other.y); |
| 3013 } | 3013 } |
| 3014 } | 3014 } |
| 3015 main() { | 3015 main() { |
| 3016 var p1 = new Point(0, 0); | 3016 var p1 = new Point(0, 0); |
| 3017 var p2 = new Point(10, 10); | 3017 var p2 = new Point(10, 10); |
| 3018 int n = p1 + p2; | 3018 int n = p1 + p2; |
| 3019 }'''); | 3019 }'''); |
| 3020 resolve(source); | 3020 computeLibrarySourceErrors(source); |
| 3021 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 3021 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 3022 verify([source]); | 3022 verify([source]); |
| 3023 } | 3023 } |
| 3024 | 3024 |
| 3025 void test_isDouble() { | 3025 void test_isDouble() { |
| 3026 Source source = addSource("var v = 1 is double;"); | 3026 Source source = addSource("var v = 1 is double;"); |
| 3027 resolve(source); | 3027 computeLibrarySourceErrors(source); |
| 3028 assertErrors(source, [HintCode.IS_DOUBLE]); | 3028 assertErrors(source, [HintCode.IS_DOUBLE]); |
| 3029 verify([source]); | 3029 verify([source]); |
| 3030 } | 3030 } |
| 3031 | 3031 |
| 3032 void test_isNotDouble() { | 3032 void test_isNotDouble() { |
| 3033 Source source = addSource("var v = 1 is! double;"); | 3033 Source source = addSource("var v = 1 is! double;"); |
| 3034 resolve(source); | 3034 computeLibrarySourceErrors(source); |
| 3035 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); | 3035 assertErrors(source, [HintCode.IS_NOT_DOUBLE]); |
| 3036 verify([source]); | 3036 verify([source]); |
| 3037 } | 3037 } |
| 3038 | 3038 |
| 3039 void test_missingReturn_async() { | 3039 void test_missingReturn_async() { |
| 3040 Source source = addSource(''' | 3040 Source source = addSource(''' |
| 3041 import 'dart:async'; | 3041 import 'dart:async'; |
| 3042 Future<int> f() async {} | 3042 Future<int> f() async {} |
| 3043 '''); | 3043 '''); |
| 3044 resolve(source); | 3044 computeLibrarySourceErrors(source); |
| 3045 assertErrors(source, [HintCode.MISSING_RETURN]); | 3045 assertErrors(source, [HintCode.MISSING_RETURN]); |
| 3046 verify([source]); | 3046 verify([source]); |
| 3047 } | 3047 } |
| 3048 | 3048 |
| 3049 void test_missingReturn_function() { | 3049 void test_missingReturn_function() { |
| 3050 Source source = addSource("int f() {}"); | 3050 Source source = addSource("int f() {}"); |
| 3051 resolve(source); | 3051 computeLibrarySourceErrors(source); |
| 3052 assertErrors(source, [HintCode.MISSING_RETURN]); | 3052 assertErrors(source, [HintCode.MISSING_RETURN]); |
| 3053 verify([source]); | 3053 verify([source]); |
| 3054 } | 3054 } |
| 3055 | 3055 |
| 3056 void test_missingReturn_method() { | 3056 void test_missingReturn_method() { |
| 3057 Source source = addSource(r''' | 3057 Source source = addSource(r''' |
| 3058 class A { | 3058 class A { |
| 3059 int m() {} | 3059 int m() {} |
| 3060 }'''); | 3060 }'''); |
| 3061 resolve(source); | 3061 computeLibrarySourceErrors(source); |
| 3062 assertErrors(source, [HintCode.MISSING_RETURN]); | 3062 assertErrors(source, [HintCode.MISSING_RETURN]); |
| 3063 verify([source]); | 3063 verify([source]); |
| 3064 } | 3064 } |
| 3065 | 3065 |
| 3066 void test_overrideOnNonOverridingGetter_invalid() { | 3066 void test_overrideOnNonOverridingGetter_invalid() { |
| 3067 Source source = addSource(r''' | 3067 Source source = addSource(r''' |
| 3068 library dart.core; | 3068 library dart.core; |
| 3069 const override = null; | 3069 const override = null; |
| 3070 class A { | 3070 class A { |
| 3071 } | 3071 } |
| 3072 class B extends A { | 3072 class B extends A { |
| 3073 @override | 3073 @override |
| 3074 int get m => 1; | 3074 int get m => 1; |
| 3075 }'''); | 3075 }'''); |
| 3076 resolve(source); | 3076 computeLibrarySourceErrors(source); |
| 3077 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER]); | 3077 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_GETTER]); |
| 3078 verify([source]); | 3078 verify([source]); |
| 3079 } | 3079 } |
| 3080 | 3080 |
| 3081 void test_overrideOnNonOverridingMethod_invalid() { | 3081 void test_overrideOnNonOverridingMethod_invalid() { |
| 3082 Source source = addSource(r''' | 3082 Source source = addSource(r''' |
| 3083 library dart.core; | 3083 library dart.core; |
| 3084 const override = null; | 3084 const override = null; |
| 3085 class A { | 3085 class A { |
| 3086 } | 3086 } |
| 3087 class B extends A { | 3087 class B extends A { |
| 3088 @override | 3088 @override |
| 3089 int m() => 1; | 3089 int m() => 1; |
| 3090 }'''); | 3090 }'''); |
| 3091 resolve(source); | 3091 computeLibrarySourceErrors(source); |
| 3092 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); | 3092 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); |
| 3093 verify([source]); | 3093 verify([source]); |
| 3094 } | 3094 } |
| 3095 | 3095 |
| 3096 void test_overrideOnNonOverridingSetter_invalid() { | 3096 void test_overrideOnNonOverridingSetter_invalid() { |
| 3097 Source source = addSource(r''' | 3097 Source source = addSource(r''' |
| 3098 library dart.core; | 3098 library dart.core; |
| 3099 const override = null; | 3099 const override = null; |
| 3100 class A { | 3100 class A { |
| 3101 } | 3101 } |
| 3102 class B extends A { | 3102 class B extends A { |
| 3103 @override | 3103 @override |
| 3104 set m(int x) {} | 3104 set m(int x) {} |
| 3105 }'''); | 3105 }'''); |
| 3106 resolve(source); | 3106 computeLibrarySourceErrors(source); |
| 3107 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]); | 3107 assertErrors(source, [HintCode.OVERRIDE_ON_NON_OVERRIDING_SETTER]); |
| 3108 verify([source]); | 3108 verify([source]); |
| 3109 } | 3109 } |
| 3110 | 3110 |
| 3111 void test_typeCheck_type_is_Null() { | 3111 void test_typeCheck_type_is_Null() { |
| 3112 Source source = addSource(r''' | 3112 Source source = addSource(r''' |
| 3113 m(i) { | 3113 m(i) { |
| 3114 bool b = i is Null; | 3114 bool b = i is Null; |
| 3115 }'''); | 3115 }'''); |
| 3116 resolve(source); | 3116 computeLibrarySourceErrors(source); |
| 3117 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); | 3117 assertErrors(source, [HintCode.TYPE_CHECK_IS_NULL]); |
| 3118 verify([source]); | 3118 verify([source]); |
| 3119 } | 3119 } |
| 3120 | 3120 |
| 3121 void test_typeCheck_type_not_Null() { | 3121 void test_typeCheck_type_not_Null() { |
| 3122 Source source = addSource(r''' | 3122 Source source = addSource(r''' |
| 3123 m(i) { | 3123 m(i) { |
| 3124 bool b = i is! Null; | 3124 bool b = i is! Null; |
| 3125 }'''); | 3125 }'''); |
| 3126 resolve(source); | 3126 computeLibrarySourceErrors(source); |
| 3127 assertErrors(source, [HintCode.TYPE_CHECK_IS_NOT_NULL]); | 3127 assertErrors(source, [HintCode.TYPE_CHECK_IS_NOT_NULL]); |
| 3128 verify([source]); | 3128 verify([source]); |
| 3129 } | 3129 } |
| 3130 | 3130 |
| 3131 void test_undefinedGetter() { | 3131 void test_undefinedGetter() { |
| 3132 Source source = addSource(r''' | 3132 Source source = addSource(r''' |
| 3133 class A {} | 3133 class A {} |
| 3134 f(var a) { | 3134 f(var a) { |
| 3135 if(a is A) { | 3135 if(a is A) { |
| 3136 return a.m; | 3136 return a.m; |
| 3137 } | 3137 } |
| 3138 }'''); | 3138 }'''); |
| 3139 resolve(source); | 3139 computeLibrarySourceErrors(source); |
| 3140 assertErrors(source, [HintCode.UNDEFINED_GETTER]); | 3140 assertErrors(source, [HintCode.UNDEFINED_GETTER]); |
| 3141 } | 3141 } |
| 3142 | 3142 |
| 3143 void test_undefinedGetter_message() { | 3143 void test_undefinedGetter_message() { |
| 3144 // The implementation of HintCode.UNDEFINED_SETTER assumes that | 3144 // The implementation of HintCode.UNDEFINED_SETTER assumes that |
| 3145 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the | 3145 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the |
| 3146 // same, this verifies that assumption. | 3146 // same, this verifies that assumption. |
| 3147 expect(StaticWarningCode.UNDEFINED_GETTER.message, | 3147 expect(StaticWarningCode.UNDEFINED_GETTER.message, |
| 3148 StaticTypeWarningCode.UNDEFINED_GETTER.message); | 3148 StaticTypeWarningCode.UNDEFINED_GETTER.message); |
| 3149 } | 3149 } |
| 3150 | 3150 |
| 3151 void test_undefinedMethod() { | 3151 void test_undefinedMethod() { |
| 3152 Source source = addSource(r''' | 3152 Source source = addSource(r''' |
| 3153 f() { | 3153 f() { |
| 3154 var a = 'str'; | 3154 var a = 'str'; |
| 3155 a.notAMethodOnString(); | 3155 a.notAMethodOnString(); |
| 3156 }'''); | 3156 }'''); |
| 3157 resolve(source); | 3157 computeLibrarySourceErrors(source); |
| 3158 assertErrors(source, [HintCode.UNDEFINED_METHOD]); | 3158 assertErrors(source, [HintCode.UNDEFINED_METHOD]); |
| 3159 } | 3159 } |
| 3160 | 3160 |
| 3161 void test_undefinedMethod_assignmentExpression() { | 3161 void test_undefinedMethod_assignmentExpression() { |
| 3162 Source source = addSource(r''' | 3162 Source source = addSource(r''' |
| 3163 class A {} | 3163 class A {} |
| 3164 class B { | 3164 class B { |
| 3165 f(var a, var a2) { | 3165 f(var a, var a2) { |
| 3166 a = new A(); | 3166 a = new A(); |
| 3167 a2 = new A(); | 3167 a2 = new A(); |
| 3168 a += a2; | 3168 a += a2; |
| 3169 } | 3169 } |
| 3170 }'''); | 3170 }'''); |
| 3171 resolve(source); | 3171 computeLibrarySourceErrors(source); |
| 3172 assertErrors(source, [HintCode.UNDEFINED_METHOD]); | 3172 assertErrors(source, [HintCode.UNDEFINED_METHOD]); |
| 3173 } | 3173 } |
| 3174 | 3174 |
| 3175 void test_undefinedOperator_binaryExpression() { | 3175 void test_undefinedOperator_binaryExpression() { |
| 3176 Source source = addSource(r''' | 3176 Source source = addSource(r''' |
| 3177 class A {} | 3177 class A {} |
| 3178 f(var a) { | 3178 f(var a) { |
| 3179 if(a is A) { | 3179 if(a is A) { |
| 3180 a + 1; | 3180 a + 1; |
| 3181 } | 3181 } |
| 3182 }'''); | 3182 }'''); |
| 3183 resolve(source); | 3183 computeLibrarySourceErrors(source); |
| 3184 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3184 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 3185 } | 3185 } |
| 3186 | 3186 |
| 3187 void test_undefinedOperator_indexBoth() { | 3187 void test_undefinedOperator_indexBoth() { |
| 3188 Source source = addSource(r''' | 3188 Source source = addSource(r''' |
| 3189 class A {} | 3189 class A {} |
| 3190 f(var a) { | 3190 f(var a) { |
| 3191 if(a is A) { | 3191 if(a is A) { |
| 3192 a[0]++; | 3192 a[0]++; |
| 3193 } | 3193 } |
| 3194 }'''); | 3194 }'''); |
| 3195 resolve(source); | 3195 computeLibrarySourceErrors(source); |
| 3196 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3196 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 3197 } | 3197 } |
| 3198 | 3198 |
| 3199 void test_undefinedOperator_indexGetter() { | 3199 void test_undefinedOperator_indexGetter() { |
| 3200 Source source = addSource(r''' | 3200 Source source = addSource(r''' |
| 3201 class A {} | 3201 class A {} |
| 3202 f(var a) { | 3202 f(var a) { |
| 3203 if(a is A) { | 3203 if(a is A) { |
| 3204 a[0]; | 3204 a[0]; |
| 3205 } | 3205 } |
| 3206 }'''); | 3206 }'''); |
| 3207 resolve(source); | 3207 computeLibrarySourceErrors(source); |
| 3208 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3208 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 3209 } | 3209 } |
| 3210 | 3210 |
| 3211 void test_undefinedOperator_indexSetter() { | 3211 void test_undefinedOperator_indexSetter() { |
| 3212 Source source = addSource(r''' | 3212 Source source = addSource(r''' |
| 3213 class A {} | 3213 class A {} |
| 3214 f(var a) { | 3214 f(var a) { |
| 3215 if(a is A) { | 3215 if(a is A) { |
| 3216 a[0] = 1; | 3216 a[0] = 1; |
| 3217 } | 3217 } |
| 3218 }'''); | 3218 }'''); |
| 3219 resolve(source); | 3219 computeLibrarySourceErrors(source); |
| 3220 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3220 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 3221 } | 3221 } |
| 3222 | 3222 |
| 3223 void test_undefinedOperator_postfixExpression() { | 3223 void test_undefinedOperator_postfixExpression() { |
| 3224 Source source = addSource(r''' | 3224 Source source = addSource(r''' |
| 3225 class A {} | 3225 class A {} |
| 3226 f(var a) { | 3226 f(var a) { |
| 3227 if(a is A) { | 3227 if(a is A) { |
| 3228 a++; | 3228 a++; |
| 3229 } | 3229 } |
| 3230 }'''); | 3230 }'''); |
| 3231 resolve(source); | 3231 computeLibrarySourceErrors(source); |
| 3232 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3232 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 3233 } | 3233 } |
| 3234 | 3234 |
| 3235 void test_undefinedOperator_prefixExpression() { | 3235 void test_undefinedOperator_prefixExpression() { |
| 3236 Source source = addSource(r''' | 3236 Source source = addSource(r''' |
| 3237 class A {} | 3237 class A {} |
| 3238 f(var a) { | 3238 f(var a) { |
| 3239 if(a is A) { | 3239 if(a is A) { |
| 3240 ++a; | 3240 ++a; |
| 3241 } | 3241 } |
| 3242 }'''); | 3242 }'''); |
| 3243 resolve(source); | 3243 computeLibrarySourceErrors(source); |
| 3244 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); | 3244 assertErrors(source, [HintCode.UNDEFINED_OPERATOR]); |
| 3245 } | 3245 } |
| 3246 | 3246 |
| 3247 void test_undefinedSetter() { | 3247 void test_undefinedSetter() { |
| 3248 Source source = addSource(r''' | 3248 Source source = addSource(r''' |
| 3249 class A {} | 3249 class A {} |
| 3250 f(var a) { | 3250 f(var a) { |
| 3251 if(a is A) { | 3251 if(a is A) { |
| 3252 a.m = 0; | 3252 a.m = 0; |
| 3253 } | 3253 } |
| 3254 }'''); | 3254 }'''); |
| 3255 resolve(source); | 3255 computeLibrarySourceErrors(source); |
| 3256 assertErrors(source, [HintCode.UNDEFINED_SETTER]); | 3256 assertErrors(source, [HintCode.UNDEFINED_SETTER]); |
| 3257 } | 3257 } |
| 3258 | 3258 |
| 3259 void test_undefinedSetter_message() { | 3259 void test_undefinedSetter_message() { |
| 3260 // The implementation of HintCode.UNDEFINED_SETTER assumes that | 3260 // The implementation of HintCode.UNDEFINED_SETTER assumes that |
| 3261 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the | 3261 // UNDEFINED_SETTER in StaticTypeWarningCode and StaticWarningCode are the |
| 3262 // same, this verifies that assumption. | 3262 // same, this verifies that assumption. |
| 3263 expect(StaticWarningCode.UNDEFINED_SETTER.message, | 3263 expect(StaticWarningCode.UNDEFINED_SETTER.message, |
| 3264 StaticTypeWarningCode.UNDEFINED_SETTER.message); | 3264 StaticTypeWarningCode.UNDEFINED_SETTER.message); |
| 3265 } | 3265 } |
| 3266 | 3266 |
| 3267 void test_unnecessaryCast_type_supertype() { | 3267 void test_unnecessaryCast_type_supertype() { |
| 3268 Source source = addSource(r''' | 3268 Source source = addSource(r''' |
| 3269 m(int i) { | 3269 m(int i) { |
| 3270 var b = i as Object; | 3270 var b = i as Object; |
| 3271 }'''); | 3271 }'''); |
| 3272 resolve(source); | 3272 computeLibrarySourceErrors(source); |
| 3273 assertErrors(source, [HintCode.UNNECESSARY_CAST]); | 3273 assertErrors(source, [HintCode.UNNECESSARY_CAST]); |
| 3274 verify([source]); | 3274 verify([source]); |
| 3275 } | 3275 } |
| 3276 | 3276 |
| 3277 void test_unnecessaryCast_type_type() { | 3277 void test_unnecessaryCast_type_type() { |
| 3278 Source source = addSource(r''' | 3278 Source source = addSource(r''' |
| 3279 m(num i) { | 3279 m(num i) { |
| 3280 var b = i as num; | 3280 var b = i as num; |
| 3281 }'''); | 3281 }'''); |
| 3282 resolve(source); | 3282 computeLibrarySourceErrors(source); |
| 3283 assertErrors(source, [HintCode.UNNECESSARY_CAST]); | 3283 assertErrors(source, [HintCode.UNNECESSARY_CAST]); |
| 3284 verify([source]); | 3284 verify([source]); |
| 3285 } | 3285 } |
| 3286 | 3286 |
| 3287 void test_unnecessaryTypeCheck_null_is_Null() { | 3287 void test_unnecessaryTypeCheck_null_is_Null() { |
| 3288 Source source = addSource("bool b = null is Null;"); | 3288 Source source = addSource("bool b = null is Null;"); |
| 3289 resolve(source); | 3289 computeLibrarySourceErrors(source); |
| 3290 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); | 3290 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); |
| 3291 verify([source]); | 3291 verify([source]); |
| 3292 } | 3292 } |
| 3293 | 3293 |
| 3294 void test_unnecessaryTypeCheck_null_not_Null() { | 3294 void test_unnecessaryTypeCheck_null_not_Null() { |
| 3295 Source source = addSource("bool b = null is! Null;"); | 3295 Source source = addSource("bool b = null is! Null;"); |
| 3296 resolve(source); | 3296 computeLibrarySourceErrors(source); |
| 3297 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); | 3297 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); |
| 3298 verify([source]); | 3298 verify([source]); |
| 3299 } | 3299 } |
| 3300 | 3300 |
| 3301 void test_unnecessaryTypeCheck_type_is_dynamic() { | 3301 void test_unnecessaryTypeCheck_type_is_dynamic() { |
| 3302 Source source = addSource(r''' | 3302 Source source = addSource(r''' |
| 3303 m(i) { | 3303 m(i) { |
| 3304 bool b = i is dynamic; | 3304 bool b = i is dynamic; |
| 3305 }'''); | 3305 }'''); |
| 3306 resolve(source); | 3306 computeLibrarySourceErrors(source); |
| 3307 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); | 3307 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); |
| 3308 verify([source]); | 3308 verify([source]); |
| 3309 } | 3309 } |
| 3310 | 3310 |
| 3311 void test_unnecessaryTypeCheck_type_is_object() { | 3311 void test_unnecessaryTypeCheck_type_is_object() { |
| 3312 Source source = addSource(r''' | 3312 Source source = addSource(r''' |
| 3313 m(i) { | 3313 m(i) { |
| 3314 bool b = i is Object; | 3314 bool b = i is Object; |
| 3315 }'''); | 3315 }'''); |
| 3316 resolve(source); | 3316 computeLibrarySourceErrors(source); |
| 3317 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); | 3317 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_TRUE]); |
| 3318 verify([source]); | 3318 verify([source]); |
| 3319 } | 3319 } |
| 3320 | 3320 |
| 3321 void test_unnecessaryTypeCheck_type_not_dynamic() { | 3321 void test_unnecessaryTypeCheck_type_not_dynamic() { |
| 3322 Source source = addSource(r''' | 3322 Source source = addSource(r''' |
| 3323 m(i) { | 3323 m(i) { |
| 3324 bool b = i is! dynamic; | 3324 bool b = i is! dynamic; |
| 3325 }'''); | 3325 }'''); |
| 3326 resolve(source); | 3326 computeLibrarySourceErrors(source); |
| 3327 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); | 3327 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); |
| 3328 verify([source]); | 3328 verify([source]); |
| 3329 } | 3329 } |
| 3330 | 3330 |
| 3331 void test_unnecessaryTypeCheck_type_not_object() { | 3331 void test_unnecessaryTypeCheck_type_not_object() { |
| 3332 Source source = addSource(r''' | 3332 Source source = addSource(r''' |
| 3333 m(i) { | 3333 m(i) { |
| 3334 bool b = i is! Object; | 3334 bool b = i is! Object; |
| 3335 }'''); | 3335 }'''); |
| 3336 resolve(source); | 3336 computeLibrarySourceErrors(source); |
| 3337 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); | 3337 assertErrors(source, [HintCode.UNNECESSARY_TYPE_CHECK_FALSE]); |
| 3338 verify([source]); | 3338 verify([source]); |
| 3339 } | 3339 } |
| 3340 | 3340 |
| 3341 void test_unusedElement_class_isUsed_extends() { | 3341 void test_unusedElement_class_isUsed_extends() { |
| 3342 enableUnusedElement = true; | 3342 enableUnusedElement = true; |
| 3343 Source source = addSource(r''' | 3343 Source source = addSource(r''' |
| 3344 class _A {} | 3344 class _A {} |
| 3345 class B extends _A {} | 3345 class B extends _A {} |
| 3346 '''); | 3346 '''); |
| 3347 resolve(source); | 3347 computeLibrarySourceErrors(source); |
| 3348 assertNoErrors(source); | 3348 assertNoErrors(source); |
| 3349 verify([source]); | 3349 verify([source]); |
| 3350 } | 3350 } |
| 3351 | 3351 |
| 3352 void test_unusedElement_class_isUsed_implements() { | 3352 void test_unusedElement_class_isUsed_implements() { |
| 3353 enableUnusedElement = true; | 3353 enableUnusedElement = true; |
| 3354 Source source = addSource(r''' | 3354 Source source = addSource(r''' |
| 3355 class _A {} | 3355 class _A {} |
| 3356 class B implements _A {} | 3356 class B implements _A {} |
| 3357 '''); | 3357 '''); |
| 3358 resolve(source); | 3358 computeLibrarySourceErrors(source); |
| 3359 assertNoErrors(source); | 3359 assertNoErrors(source); |
| 3360 verify([source]); | 3360 verify([source]); |
| 3361 } | 3361 } |
| 3362 | 3362 |
| 3363 void test_unusedElement_class_isUsed_instanceCreation() { | 3363 void test_unusedElement_class_isUsed_instanceCreation() { |
| 3364 enableUnusedElement = true; | 3364 enableUnusedElement = true; |
| 3365 Source source = addSource(r''' | 3365 Source source = addSource(r''' |
| 3366 class _A {} | 3366 class _A {} |
| 3367 main() { | 3367 main() { |
| 3368 new _A(); | 3368 new _A(); |
| 3369 }'''); | 3369 }'''); |
| 3370 resolve(source); | 3370 computeLibrarySourceErrors(source); |
| 3371 assertNoErrors(source); | 3371 assertNoErrors(source); |
| 3372 verify([source]); | 3372 verify([source]); |
| 3373 } | 3373 } |
| 3374 | 3374 |
| 3375 void test_unusedElement_class_isUsed_staticFieldAccess() { | 3375 void test_unusedElement_class_isUsed_staticFieldAccess() { |
| 3376 enableUnusedElement = true; | 3376 enableUnusedElement = true; |
| 3377 Source source = addSource(r''' | 3377 Source source = addSource(r''' |
| 3378 class _A { | 3378 class _A { |
| 3379 static const F = 42; | 3379 static const F = 42; |
| 3380 } | 3380 } |
| 3381 main() { | 3381 main() { |
| 3382 _A.F; | 3382 _A.F; |
| 3383 }'''); | 3383 }'''); |
| 3384 resolve(source); | 3384 computeLibrarySourceErrors(source); |
| 3385 assertNoErrors(source); | 3385 assertNoErrors(source); |
| 3386 verify([source]); | 3386 verify([source]); |
| 3387 } | 3387 } |
| 3388 | 3388 |
| 3389 void test_unusedElement_class_isUsed_staticMethodInvocation() { | 3389 void test_unusedElement_class_isUsed_staticMethodInvocation() { |
| 3390 enableUnusedElement = true; | 3390 enableUnusedElement = true; |
| 3391 Source source = addSource(r''' | 3391 Source source = addSource(r''' |
| 3392 class _A { | 3392 class _A { |
| 3393 static m() {} | 3393 static m() {} |
| 3394 } | 3394 } |
| 3395 main() { | 3395 main() { |
| 3396 _A.m(); | 3396 _A.m(); |
| 3397 }'''); | 3397 }'''); |
| 3398 resolve(source); | 3398 computeLibrarySourceErrors(source); |
| 3399 assertNoErrors(source); | 3399 assertNoErrors(source); |
| 3400 verify([source]); | 3400 verify([source]); |
| 3401 } | 3401 } |
| 3402 | 3402 |
| 3403 void test_unusedElement_class_isUsed_typeArgument() { | 3403 void test_unusedElement_class_isUsed_typeArgument() { |
| 3404 enableUnusedElement = true; | 3404 enableUnusedElement = true; |
| 3405 Source source = addSource(r''' | 3405 Source source = addSource(r''' |
| 3406 class _A {} | 3406 class _A {} |
| 3407 main() { | 3407 main() { |
| 3408 var v = new List<_A>(); | 3408 var v = new List<_A>(); |
| 3409 print(v); | 3409 print(v); |
| 3410 }'''); | 3410 }'''); |
| 3411 resolve(source); | 3411 computeLibrarySourceErrors(source); |
| 3412 assertNoErrors(source); | 3412 assertNoErrors(source); |
| 3413 verify([source]); | 3413 verify([source]); |
| 3414 } | 3414 } |
| 3415 | 3415 |
| 3416 void test_unusedElement_class_notUsed_inClassMember() { | 3416 void test_unusedElement_class_notUsed_inClassMember() { |
| 3417 enableUnusedElement = true; | 3417 enableUnusedElement = true; |
| 3418 Source source = addSource(r''' | 3418 Source source = addSource(r''' |
| 3419 class _A { | 3419 class _A { |
| 3420 static staticMethod() { | 3420 static staticMethod() { |
| 3421 new _A(); | 3421 new _A(); |
| 3422 } | 3422 } |
| 3423 instanceMethod() { | 3423 instanceMethod() { |
| 3424 new _A(); | 3424 new _A(); |
| 3425 } | 3425 } |
| 3426 } | 3426 } |
| 3427 '''); | 3427 '''); |
| 3428 resolve(source); | 3428 computeLibrarySourceErrors(source); |
| 3429 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3429 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3430 verify([source]); | 3430 verify([source]); |
| 3431 } | 3431 } |
| 3432 | 3432 |
| 3433 void test_unusedElement_class_notUsed_inConstructorName() { | 3433 void test_unusedElement_class_notUsed_inConstructorName() { |
| 3434 enableUnusedElement = true; | 3434 enableUnusedElement = true; |
| 3435 Source source = addSource(r''' | 3435 Source source = addSource(r''' |
| 3436 class _A { | 3436 class _A { |
| 3437 _A() {} | 3437 _A() {} |
| 3438 _A.named() {} | 3438 _A.named() {} |
| 3439 } | 3439 } |
| 3440 '''); | 3440 '''); |
| 3441 resolve(source); | 3441 computeLibrarySourceErrors(source); |
| 3442 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3442 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3443 verify([source]); | 3443 verify([source]); |
| 3444 } | 3444 } |
| 3445 | 3445 |
| 3446 void test_unusedElement_class_notUsed_isExpression() { | 3446 void test_unusedElement_class_notUsed_isExpression() { |
| 3447 enableUnusedElement = true; | 3447 enableUnusedElement = true; |
| 3448 Source source = addSource(r''' | 3448 Source source = addSource(r''' |
| 3449 class _A {} | 3449 class _A {} |
| 3450 main(p) { | 3450 main(p) { |
| 3451 if (p is _A) { | 3451 if (p is _A) { |
| 3452 } | 3452 } |
| 3453 } | 3453 } |
| 3454 '''); | 3454 '''); |
| 3455 resolve(source); | 3455 computeLibrarySourceErrors(source); |
| 3456 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3456 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3457 verify([source]); | 3457 verify([source]); |
| 3458 } | 3458 } |
| 3459 | 3459 |
| 3460 void test_unusedElement_class_notUsed_noReference() { | 3460 void test_unusedElement_class_notUsed_noReference() { |
| 3461 enableUnusedElement = true; | 3461 enableUnusedElement = true; |
| 3462 Source source = addSource(r''' | 3462 Source source = addSource(r''' |
| 3463 class _A {} | 3463 class _A {} |
| 3464 main() { | 3464 main() { |
| 3465 }'''); | 3465 }'''); |
| 3466 resolve(source); | 3466 computeLibrarySourceErrors(source); |
| 3467 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3467 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3468 verify([source]); | 3468 verify([source]); |
| 3469 } | 3469 } |
| 3470 | 3470 |
| 3471 void test_unusedElement_class_notUsed_variableDeclaration() { | 3471 void test_unusedElement_class_notUsed_variableDeclaration() { |
| 3472 enableUnusedElement = true; | 3472 enableUnusedElement = true; |
| 3473 Source source = addSource(r''' | 3473 Source source = addSource(r''' |
| 3474 class _A {} | 3474 class _A {} |
| 3475 main() { | 3475 main() { |
| 3476 _A v; | 3476 _A v; |
| 3477 print(v); | 3477 print(v); |
| 3478 } | 3478 } |
| 3479 print(x) {} | 3479 print(x) {} |
| 3480 '''); | 3480 '''); |
| 3481 resolve(source); | 3481 computeLibrarySourceErrors(source); |
| 3482 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3482 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3483 verify([source]); | 3483 verify([source]); |
| 3484 } | 3484 } |
| 3485 | 3485 |
| 3486 void test_unusedElement_enum_isUsed_fieldReference() { | 3486 void test_unusedElement_enum_isUsed_fieldReference() { |
| 3487 enableUnusedElement = true; | 3487 enableUnusedElement = true; |
| 3488 Source source = addSource(r''' | 3488 Source source = addSource(r''' |
| 3489 enum _MyEnum {A, B, C} | 3489 enum _MyEnum {A, B, C} |
| 3490 main() { | 3490 main() { |
| 3491 print(_MyEnum.B); | 3491 print(_MyEnum.B); |
| 3492 }'''); | 3492 }'''); |
| 3493 resolve(source); | 3493 computeLibrarySourceErrors(source); |
| 3494 assertNoErrors(source); | 3494 assertNoErrors(source); |
| 3495 verify([source]); | 3495 verify([source]); |
| 3496 } | 3496 } |
| 3497 | 3497 |
| 3498 void test_unusedElement_enum_notUsed_noReference() { | 3498 void test_unusedElement_enum_notUsed_noReference() { |
| 3499 enableUnusedElement = true; | 3499 enableUnusedElement = true; |
| 3500 Source source = addSource(r''' | 3500 Source source = addSource(r''' |
| 3501 enum _MyEnum {A, B, C} | 3501 enum _MyEnum {A, B, C} |
| 3502 main() { | 3502 main() { |
| 3503 }'''); | 3503 }'''); |
| 3504 resolve(source); | 3504 computeLibrarySourceErrors(source); |
| 3505 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3505 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3506 verify([source]); | 3506 verify([source]); |
| 3507 } | 3507 } |
| 3508 | 3508 |
| 3509 void test_unusedElement_functionLocal_isUsed_closure() { | 3509 void test_unusedElement_functionLocal_isUsed_closure() { |
| 3510 enableUnusedElement = true; | 3510 enableUnusedElement = true; |
| 3511 Source source = addSource(r''' | 3511 Source source = addSource(r''' |
| 3512 main() { | 3512 main() { |
| 3513 print(() {}); | 3513 print(() {}); |
| 3514 } | 3514 } |
| 3515 print(x) {} | 3515 print(x) {} |
| 3516 '''); | 3516 '''); |
| 3517 resolve(source); | 3517 computeLibrarySourceErrors(source); |
| 3518 assertNoErrors(source); | 3518 assertNoErrors(source); |
| 3519 verify([source]); | 3519 verify([source]); |
| 3520 } | 3520 } |
| 3521 | 3521 |
| 3522 void test_unusedElement_functionLocal_isUsed_invocation() { | 3522 void test_unusedElement_functionLocal_isUsed_invocation() { |
| 3523 enableUnusedElement = true; | 3523 enableUnusedElement = true; |
| 3524 Source source = addSource(r''' | 3524 Source source = addSource(r''' |
| 3525 main() { | 3525 main() { |
| 3526 f() {} | 3526 f() {} |
| 3527 f(); | 3527 f(); |
| 3528 }'''); | 3528 }'''); |
| 3529 resolve(source); | 3529 computeLibrarySourceErrors(source); |
| 3530 assertNoErrors(source); | 3530 assertNoErrors(source); |
| 3531 verify([source]); | 3531 verify([source]); |
| 3532 } | 3532 } |
| 3533 | 3533 |
| 3534 void test_unusedElement_functionLocal_isUsed_reference() { | 3534 void test_unusedElement_functionLocal_isUsed_reference() { |
| 3535 enableUnusedElement = true; | 3535 enableUnusedElement = true; |
| 3536 Source source = addSource(r''' | 3536 Source source = addSource(r''' |
| 3537 main() { | 3537 main() { |
| 3538 f() {} | 3538 f() {} |
| 3539 print(f); | 3539 print(f); |
| 3540 } | 3540 } |
| 3541 print(x) {} | 3541 print(x) {} |
| 3542 '''); | 3542 '''); |
| 3543 resolve(source); | 3543 computeLibrarySourceErrors(source); |
| 3544 assertNoErrors(source); | 3544 assertNoErrors(source); |
| 3545 verify([source]); | 3545 verify([source]); |
| 3546 } | 3546 } |
| 3547 | 3547 |
| 3548 void test_unusedElement_functionLocal_notUsed_noReference() { | 3548 void test_unusedElement_functionLocal_notUsed_noReference() { |
| 3549 enableUnusedElement = true; | 3549 enableUnusedElement = true; |
| 3550 Source source = addSource(r''' | 3550 Source source = addSource(r''' |
| 3551 main() { | 3551 main() { |
| 3552 f() {} | 3552 f() {} |
| 3553 }'''); | 3553 }'''); |
| 3554 resolve(source); | 3554 computeLibrarySourceErrors(source); |
| 3555 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3555 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3556 verify([source]); | 3556 verify([source]); |
| 3557 } | 3557 } |
| 3558 | 3558 |
| 3559 void test_unusedElement_functionLocal_notUsed_referenceFromItself() { | 3559 void test_unusedElement_functionLocal_notUsed_referenceFromItself() { |
| 3560 enableUnusedElement = true; | 3560 enableUnusedElement = true; |
| 3561 Source source = addSource(r''' | 3561 Source source = addSource(r''' |
| 3562 main() { | 3562 main() { |
| 3563 _f(int p) { | 3563 _f(int p) { |
| 3564 _f(p - 1); | 3564 _f(p - 1); |
| 3565 } | 3565 } |
| 3566 }'''); | 3566 }'''); |
| 3567 resolve(source); | 3567 computeLibrarySourceErrors(source); |
| 3568 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3568 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3569 verify([source]); | 3569 verify([source]); |
| 3570 } | 3570 } |
| 3571 | 3571 |
| 3572 void test_unusedElement_functionTop_isUsed_invocation() { | 3572 void test_unusedElement_functionTop_isUsed_invocation() { |
| 3573 enableUnusedElement = true; | 3573 enableUnusedElement = true; |
| 3574 Source source = addSource(r''' | 3574 Source source = addSource(r''' |
| 3575 _f() {} | 3575 _f() {} |
| 3576 main() { | 3576 main() { |
| 3577 _f(); | 3577 _f(); |
| 3578 }'''); | 3578 }'''); |
| 3579 resolve(source); | 3579 computeLibrarySourceErrors(source); |
| 3580 assertNoErrors(source); | 3580 assertNoErrors(source); |
| 3581 verify([source]); | 3581 verify([source]); |
| 3582 } | 3582 } |
| 3583 | 3583 |
| 3584 void test_unusedElement_functionTop_isUsed_reference() { | 3584 void test_unusedElement_functionTop_isUsed_reference() { |
| 3585 enableUnusedElement = true; | 3585 enableUnusedElement = true; |
| 3586 Source source = addSource(r''' | 3586 Source source = addSource(r''' |
| 3587 _f() {} | 3587 _f() {} |
| 3588 main() { | 3588 main() { |
| 3589 print(_f); | 3589 print(_f); |
| 3590 } | 3590 } |
| 3591 print(x) {} | 3591 print(x) {} |
| 3592 '''); | 3592 '''); |
| 3593 resolve(source); | 3593 computeLibrarySourceErrors(source); |
| 3594 assertNoErrors(source); | 3594 assertNoErrors(source); |
| 3595 verify([source]); | 3595 verify([source]); |
| 3596 } | 3596 } |
| 3597 | 3597 |
| 3598 void test_unusedElement_functionTop_notUsed_noReference() { | 3598 void test_unusedElement_functionTop_notUsed_noReference() { |
| 3599 enableUnusedElement = true; | 3599 enableUnusedElement = true; |
| 3600 Source source = addSource(r''' | 3600 Source source = addSource(r''' |
| 3601 _f() {} | 3601 _f() {} |
| 3602 main() { | 3602 main() { |
| 3603 }'''); | 3603 }'''); |
| 3604 resolve(source); | 3604 computeLibrarySourceErrors(source); |
| 3605 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3605 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3606 verify([source]); | 3606 verify([source]); |
| 3607 } | 3607 } |
| 3608 | 3608 |
| 3609 void test_unusedElement_functionTop_notUsed_referenceFromItself() { | 3609 void test_unusedElement_functionTop_notUsed_referenceFromItself() { |
| 3610 enableUnusedElement = true; | 3610 enableUnusedElement = true; |
| 3611 Source source = addSource(r''' | 3611 Source source = addSource(r''' |
| 3612 _f(int p) { | 3612 _f(int p) { |
| 3613 _f(p - 1); | 3613 _f(p - 1); |
| 3614 } | 3614 } |
| 3615 main() { | 3615 main() { |
| 3616 }'''); | 3616 }'''); |
| 3617 resolve(source); | 3617 computeLibrarySourceErrors(source); |
| 3618 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3618 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3619 verify([source]); | 3619 verify([source]); |
| 3620 } | 3620 } |
| 3621 | 3621 |
| 3622 void test_unusedElement_functionTypeAlias_isUsed_isExpression() { | 3622 void test_unusedElement_functionTypeAlias_isUsed_isExpression() { |
| 3623 enableUnusedElement = true; | 3623 enableUnusedElement = true; |
| 3624 Source source = addSource(r''' | 3624 Source source = addSource(r''' |
| 3625 typedef _F(a, b); | 3625 typedef _F(a, b); |
| 3626 main(f) { | 3626 main(f) { |
| 3627 if (f is _F) { | 3627 if (f is _F) { |
| 3628 print('F'); | 3628 print('F'); |
| 3629 } | 3629 } |
| 3630 }'''); | 3630 }'''); |
| 3631 resolve(source); | 3631 computeLibrarySourceErrors(source); |
| 3632 assertNoErrors(source); | 3632 assertNoErrors(source); |
| 3633 verify([source]); | 3633 verify([source]); |
| 3634 } | 3634 } |
| 3635 | 3635 |
| 3636 void test_unusedElement_functionTypeAlias_isUsed_reference() { | 3636 void test_unusedElement_functionTypeAlias_isUsed_reference() { |
| 3637 enableUnusedElement = true; | 3637 enableUnusedElement = true; |
| 3638 Source source = addSource(r''' | 3638 Source source = addSource(r''' |
| 3639 typedef _F(a, b); | 3639 typedef _F(a, b); |
| 3640 main(_F f) { | 3640 main(_F f) { |
| 3641 }'''); | 3641 }'''); |
| 3642 resolve(source); | 3642 computeLibrarySourceErrors(source); |
| 3643 assertNoErrors(source); | 3643 assertNoErrors(source); |
| 3644 verify([source]); | 3644 verify([source]); |
| 3645 } | 3645 } |
| 3646 | 3646 |
| 3647 void test_unusedElement_functionTypeAlias_isUsed_typeArgument() { | 3647 void test_unusedElement_functionTypeAlias_isUsed_typeArgument() { |
| 3648 enableUnusedElement = true; | 3648 enableUnusedElement = true; |
| 3649 Source source = addSource(r''' | 3649 Source source = addSource(r''' |
| 3650 typedef _F(a, b); | 3650 typedef _F(a, b); |
| 3651 main() { | 3651 main() { |
| 3652 var v = new List<_F>(); | 3652 var v = new List<_F>(); |
| 3653 print(v); | 3653 print(v); |
| 3654 }'''); | 3654 }'''); |
| 3655 resolve(source); | 3655 computeLibrarySourceErrors(source); |
| 3656 assertNoErrors(source); | 3656 assertNoErrors(source); |
| 3657 verify([source]); | 3657 verify([source]); |
| 3658 } | 3658 } |
| 3659 | 3659 |
| 3660 void test_unusedElement_functionTypeAlias_isUsed_variableDeclaration() { | 3660 void test_unusedElement_functionTypeAlias_isUsed_variableDeclaration() { |
| 3661 enableUnusedElement = true; | 3661 enableUnusedElement = true; |
| 3662 Source source = addSource(r''' | 3662 Source source = addSource(r''' |
| 3663 typedef _F(a, b); | 3663 typedef _F(a, b); |
| 3664 class A { | 3664 class A { |
| 3665 _F f; | 3665 _F f; |
| 3666 }'''); | 3666 }'''); |
| 3667 resolve(source); | 3667 computeLibrarySourceErrors(source); |
| 3668 assertNoErrors(source); | 3668 assertNoErrors(source); |
| 3669 verify([source]); | 3669 verify([source]); |
| 3670 } | 3670 } |
| 3671 | 3671 |
| 3672 void test_unusedElement_functionTypeAlias_notUsed_noReference() { | 3672 void test_unusedElement_functionTypeAlias_notUsed_noReference() { |
| 3673 enableUnusedElement = true; | 3673 enableUnusedElement = true; |
| 3674 Source source = addSource(r''' | 3674 Source source = addSource(r''' |
| 3675 typedef _F(a, b); | 3675 typedef _F(a, b); |
| 3676 main() { | 3676 main() { |
| 3677 }'''); | 3677 }'''); |
| 3678 resolve(source); | 3678 computeLibrarySourceErrors(source); |
| 3679 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3679 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3680 verify([source]); | 3680 verify([source]); |
| 3681 } | 3681 } |
| 3682 | 3682 |
| 3683 void test_unusedElement_getter_isUsed_invocation_implicitThis() { | 3683 void test_unusedElement_getter_isUsed_invocation_implicitThis() { |
| 3684 enableUnusedElement = true; | 3684 enableUnusedElement = true; |
| 3685 Source source = addSource(r''' | 3685 Source source = addSource(r''' |
| 3686 class A { | 3686 class A { |
| 3687 get _g => null; | 3687 get _g => null; |
| 3688 useGetter() { | 3688 useGetter() { |
| 3689 var v = _g; | 3689 var v = _g; |
| 3690 } | 3690 } |
| 3691 }'''); | 3691 }'''); |
| 3692 resolve(source); | 3692 computeLibrarySourceErrors(source); |
| 3693 assertNoErrors(source); | 3693 assertNoErrors(source); |
| 3694 verify([source]); | 3694 verify([source]); |
| 3695 } | 3695 } |
| 3696 | 3696 |
| 3697 void test_unusedElement_getter_isUsed_invocation_PrefixedIdentifier() { | 3697 void test_unusedElement_getter_isUsed_invocation_PrefixedIdentifier() { |
| 3698 enableUnusedElement = true; | 3698 enableUnusedElement = true; |
| 3699 Source source = addSource(r''' | 3699 Source source = addSource(r''' |
| 3700 class A { | 3700 class A { |
| 3701 get _g => null; | 3701 get _g => null; |
| 3702 } | 3702 } |
| 3703 main(A a) { | 3703 main(A a) { |
| 3704 var v = a._g; | 3704 var v = a._g; |
| 3705 } | 3705 } |
| 3706 '''); | 3706 '''); |
| 3707 resolve(source); | 3707 computeLibrarySourceErrors(source); |
| 3708 assertNoErrors(source); | 3708 assertNoErrors(source); |
| 3709 verify([source]); | 3709 verify([source]); |
| 3710 } | 3710 } |
| 3711 | 3711 |
| 3712 void test_unusedElement_getter_isUsed_invocation_PropertyAccess() { | 3712 void test_unusedElement_getter_isUsed_invocation_PropertyAccess() { |
| 3713 enableUnusedElement = true; | 3713 enableUnusedElement = true; |
| 3714 Source source = addSource(r''' | 3714 Source source = addSource(r''' |
| 3715 class A { | 3715 class A { |
| 3716 get _g => null; | 3716 get _g => null; |
| 3717 } | 3717 } |
| 3718 main() { | 3718 main() { |
| 3719 var v = new A()._g; | 3719 var v = new A()._g; |
| 3720 } | 3720 } |
| 3721 '''); | 3721 '''); |
| 3722 resolve(source); | 3722 computeLibrarySourceErrors(source); |
| 3723 assertNoErrors(source); | 3723 assertNoErrors(source); |
| 3724 verify([source]); | 3724 verify([source]); |
| 3725 } | 3725 } |
| 3726 | 3726 |
| 3727 void test_unusedElement_getter_notUsed_noReference() { | 3727 void test_unusedElement_getter_notUsed_noReference() { |
| 3728 enableUnusedElement = true; | 3728 enableUnusedElement = true; |
| 3729 Source source = addSource(r''' | 3729 Source source = addSource(r''' |
| 3730 class A { | 3730 class A { |
| 3731 get _g => null; | 3731 get _g => null; |
| 3732 }'''); | 3732 }'''); |
| 3733 resolve(source); | 3733 computeLibrarySourceErrors(source); |
| 3734 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3734 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3735 verify([source]); | 3735 verify([source]); |
| 3736 } | 3736 } |
| 3737 | 3737 |
| 3738 void test_unusedElement_getter_notUsed_referenceFromItself() { | 3738 void test_unusedElement_getter_notUsed_referenceFromItself() { |
| 3739 enableUnusedElement = true; | 3739 enableUnusedElement = true; |
| 3740 Source source = addSource(r''' | 3740 Source source = addSource(r''' |
| 3741 class A { | 3741 class A { |
| 3742 get _g { | 3742 get _g { |
| 3743 return _g; | 3743 return _g; |
| 3744 } | 3744 } |
| 3745 }'''); | 3745 }'''); |
| 3746 resolve(source); | 3746 computeLibrarySourceErrors(source); |
| 3747 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3747 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3748 verify([source]); | 3748 verify([source]); |
| 3749 } | 3749 } |
| 3750 | 3750 |
| 3751 void test_unusedElement_method_isUsed_hasReference_implicitThis() { | 3751 void test_unusedElement_method_isUsed_hasReference_implicitThis() { |
| 3752 enableUnusedElement = true; | 3752 enableUnusedElement = true; |
| 3753 Source source = addSource(r''' | 3753 Source source = addSource(r''' |
| 3754 class A { | 3754 class A { |
| 3755 _m() {} | 3755 _m() {} |
| 3756 useMethod() { | 3756 useMethod() { |
| 3757 print(_m); | 3757 print(_m); |
| 3758 } | 3758 } |
| 3759 } | 3759 } |
| 3760 print(x) {} | 3760 print(x) {} |
| 3761 '''); | 3761 '''); |
| 3762 resolve(source); | 3762 computeLibrarySourceErrors(source); |
| 3763 assertNoErrors(source); | 3763 assertNoErrors(source); |
| 3764 verify([source]); | 3764 verify([source]); |
| 3765 } | 3765 } |
| 3766 | 3766 |
| 3767 void test_unusedElement_method_isUsed_hasReference_implicitThis_subclass() { | 3767 void test_unusedElement_method_isUsed_hasReference_implicitThis_subclass() { |
| 3768 enableUnusedElement = true; | 3768 enableUnusedElement = true; |
| 3769 Source source = addSource(r''' | 3769 Source source = addSource(r''' |
| 3770 class A { | 3770 class A { |
| 3771 _m() {} | 3771 _m() {} |
| 3772 useMethod() { | 3772 useMethod() { |
| 3773 print(_m); | 3773 print(_m); |
| 3774 } | 3774 } |
| 3775 } | 3775 } |
| 3776 class B extends A { | 3776 class B extends A { |
| 3777 _m() {} | 3777 _m() {} |
| 3778 } | 3778 } |
| 3779 print(x) {} | 3779 print(x) {} |
| 3780 '''); | 3780 '''); |
| 3781 resolve(source); | 3781 computeLibrarySourceErrors(source); |
| 3782 assertNoErrors(source); | 3782 assertNoErrors(source); |
| 3783 verify([source]); | 3783 verify([source]); |
| 3784 } | 3784 } |
| 3785 | 3785 |
| 3786 void test_unusedElement_method_isUsed_hasReference_PrefixedIdentifier() { | 3786 void test_unusedElement_method_isUsed_hasReference_PrefixedIdentifier() { |
| 3787 enableUnusedElement = true; | 3787 enableUnusedElement = true; |
| 3788 Source source = addSource(r''' | 3788 Source source = addSource(r''' |
| 3789 class A { | 3789 class A { |
| 3790 _m() {} | 3790 _m() {} |
| 3791 } | 3791 } |
| 3792 main(A a) { | 3792 main(A a) { |
| 3793 a._m; | 3793 a._m; |
| 3794 }'''); | 3794 }'''); |
| 3795 resolve(source); | 3795 computeLibrarySourceErrors(source); |
| 3796 assertNoErrors(source); | 3796 assertNoErrors(source); |
| 3797 verify([source]); | 3797 verify([source]); |
| 3798 } | 3798 } |
| 3799 | 3799 |
| 3800 void test_unusedElement_method_isUsed_hasReference_PropertyAccess() { | 3800 void test_unusedElement_method_isUsed_hasReference_PropertyAccess() { |
| 3801 enableUnusedElement = true; | 3801 enableUnusedElement = true; |
| 3802 Source source = addSource(r''' | 3802 Source source = addSource(r''' |
| 3803 class A { | 3803 class A { |
| 3804 _m() {} | 3804 _m() {} |
| 3805 } | 3805 } |
| 3806 main() { | 3806 main() { |
| 3807 new A()._m; | 3807 new A()._m; |
| 3808 }'''); | 3808 }'''); |
| 3809 resolve(source); | 3809 computeLibrarySourceErrors(source); |
| 3810 assertNoErrors(source); | 3810 assertNoErrors(source); |
| 3811 verify([source]); | 3811 verify([source]); |
| 3812 } | 3812 } |
| 3813 | 3813 |
| 3814 void test_unusedElement_method_isUsed_invocation_implicitThis() { | 3814 void test_unusedElement_method_isUsed_invocation_implicitThis() { |
| 3815 enableUnusedElement = true; | 3815 enableUnusedElement = true; |
| 3816 Source source = addSource(r''' | 3816 Source source = addSource(r''' |
| 3817 class A { | 3817 class A { |
| 3818 _m() {} | 3818 _m() {} |
| 3819 useMethod() { | 3819 useMethod() { |
| 3820 _m(); | 3820 _m(); |
| 3821 } | 3821 } |
| 3822 }'''); | 3822 }'''); |
| 3823 resolve(source); | 3823 computeLibrarySourceErrors(source); |
| 3824 assertNoErrors(source); | 3824 assertNoErrors(source); |
| 3825 verify([source]); | 3825 verify([source]); |
| 3826 } | 3826 } |
| 3827 | 3827 |
| 3828 void test_unusedElement_method_isUsed_invocation_implicitThis_subclass() { | 3828 void test_unusedElement_method_isUsed_invocation_implicitThis_subclass() { |
| 3829 enableUnusedElement = true; | 3829 enableUnusedElement = true; |
| 3830 Source source = addSource(r''' | 3830 Source source = addSource(r''' |
| 3831 class A { | 3831 class A { |
| 3832 _m() {} | 3832 _m() {} |
| 3833 useMethod() { | 3833 useMethod() { |
| 3834 _m(); | 3834 _m(); |
| 3835 } | 3835 } |
| 3836 } | 3836 } |
| 3837 class B extends A { | 3837 class B extends A { |
| 3838 _m() {} | 3838 _m() {} |
| 3839 }'''); | 3839 }'''); |
| 3840 resolve(source); | 3840 computeLibrarySourceErrors(source); |
| 3841 assertNoErrors(source); | 3841 assertNoErrors(source); |
| 3842 verify([source]); | 3842 verify([source]); |
| 3843 } | 3843 } |
| 3844 | 3844 |
| 3845 void test_unusedElement_method_isUsed_invocation_MemberElement() { | 3845 void test_unusedElement_method_isUsed_invocation_MemberElement() { |
| 3846 enableUnusedElement = true; | 3846 enableUnusedElement = true; |
| 3847 Source source = addSource(r''' | 3847 Source source = addSource(r''' |
| 3848 class A<T> { | 3848 class A<T> { |
| 3849 _m(T t) {} | 3849 _m(T t) {} |
| 3850 } | 3850 } |
| 3851 main(A<int> a) { | 3851 main(A<int> a) { |
| 3852 a._m(0); | 3852 a._m(0); |
| 3853 }'''); | 3853 }'''); |
| 3854 resolve(source); | 3854 computeLibrarySourceErrors(source); |
| 3855 assertNoErrors(source); | 3855 assertNoErrors(source); |
| 3856 verify([source]); | 3856 verify([source]); |
| 3857 } | 3857 } |
| 3858 | 3858 |
| 3859 void test_unusedElement_method_isUsed_invocation_propagated() { | 3859 void test_unusedElement_method_isUsed_invocation_propagated() { |
| 3860 enableUnusedElement = true; | 3860 enableUnusedElement = true; |
| 3861 Source source = addSource(r''' | 3861 Source source = addSource(r''' |
| 3862 class A { | 3862 class A { |
| 3863 _m() {} | 3863 _m() {} |
| 3864 } | 3864 } |
| 3865 main() { | 3865 main() { |
| 3866 var a = new A(); | 3866 var a = new A(); |
| 3867 a._m(); | 3867 a._m(); |
| 3868 }'''); | 3868 }'''); |
| 3869 resolve(source); | 3869 computeLibrarySourceErrors(source); |
| 3870 assertNoErrors(source); | 3870 assertNoErrors(source); |
| 3871 verify([source]); | 3871 verify([source]); |
| 3872 } | 3872 } |
| 3873 | 3873 |
| 3874 void test_unusedElement_method_isUsed_invocation_static() { | 3874 void test_unusedElement_method_isUsed_invocation_static() { |
| 3875 enableUnusedElement = true; | 3875 enableUnusedElement = true; |
| 3876 Source source = addSource(r''' | 3876 Source source = addSource(r''' |
| 3877 class A { | 3877 class A { |
| 3878 _m() {} | 3878 _m() {} |
| 3879 } | 3879 } |
| 3880 main() { | 3880 main() { |
| 3881 A a = new A(); | 3881 A a = new A(); |
| 3882 a._m(); | 3882 a._m(); |
| 3883 }'''); | 3883 }'''); |
| 3884 resolve(source); | 3884 computeLibrarySourceErrors(source); |
| 3885 assertNoErrors(source); | 3885 assertNoErrors(source); |
| 3886 verify([source]); | 3886 verify([source]); |
| 3887 } | 3887 } |
| 3888 | 3888 |
| 3889 void test_unusedElement_method_isUsed_invocation_subclass() { | 3889 void test_unusedElement_method_isUsed_invocation_subclass() { |
| 3890 enableUnusedElement = true; | 3890 enableUnusedElement = true; |
| 3891 Source source = addSource(r''' | 3891 Source source = addSource(r''' |
| 3892 class A { | 3892 class A { |
| 3893 _m() {} | 3893 _m() {} |
| 3894 } | 3894 } |
| 3895 class B extends A { | 3895 class B extends A { |
| 3896 _m() {} | 3896 _m() {} |
| 3897 } | 3897 } |
| 3898 main(A a) { | 3898 main(A a) { |
| 3899 a._m(); | 3899 a._m(); |
| 3900 }'''); | 3900 }'''); |
| 3901 resolve(source); | 3901 computeLibrarySourceErrors(source); |
| 3902 assertNoErrors(source); | 3902 assertNoErrors(source); |
| 3903 verify([source]); | 3903 verify([source]); |
| 3904 } | 3904 } |
| 3905 | 3905 |
| 3906 void test_unusedElement_method_isUsed_notPrivate() { | 3906 void test_unusedElement_method_isUsed_notPrivate() { |
| 3907 enableUnusedElement = true; | 3907 enableUnusedElement = true; |
| 3908 Source source = addSource(r''' | 3908 Source source = addSource(r''' |
| 3909 class A { | 3909 class A { |
| 3910 m() {} | 3910 m() {} |
| 3911 } | 3911 } |
| 3912 main() { | 3912 main() { |
| 3913 }'''); | 3913 }'''); |
| 3914 resolve(source); | 3914 computeLibrarySourceErrors(source); |
| 3915 assertNoErrors(source); | 3915 assertNoErrors(source); |
| 3916 verify([source]); | 3916 verify([source]); |
| 3917 } | 3917 } |
| 3918 | 3918 |
| 3919 void test_unusedElement_method_isUsed_staticInvocation() { | 3919 void test_unusedElement_method_isUsed_staticInvocation() { |
| 3920 enableUnusedElement = true; | 3920 enableUnusedElement = true; |
| 3921 Source source = addSource(r''' | 3921 Source source = addSource(r''' |
| 3922 class A { | 3922 class A { |
| 3923 static _m() {} | 3923 static _m() {} |
| 3924 } | 3924 } |
| 3925 main() { | 3925 main() { |
| 3926 A._m(); | 3926 A._m(); |
| 3927 }'''); | 3927 }'''); |
| 3928 resolve(source); | 3928 computeLibrarySourceErrors(source); |
| 3929 assertNoErrors(source); | 3929 assertNoErrors(source); |
| 3930 verify([source]); | 3930 verify([source]); |
| 3931 } | 3931 } |
| 3932 | 3932 |
| 3933 void test_unusedElement_method_notUsed_noReference() { | 3933 void test_unusedElement_method_notUsed_noReference() { |
| 3934 enableUnusedElement = true; | 3934 enableUnusedElement = true; |
| 3935 Source source = addSource(r''' | 3935 Source source = addSource(r''' |
| 3936 class A { | 3936 class A { |
| 3937 static _m() {} | 3937 static _m() {} |
| 3938 }'''); | 3938 }'''); |
| 3939 resolve(source); | 3939 computeLibrarySourceErrors(source); |
| 3940 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3940 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3941 verify([source]); | 3941 verify([source]); |
| 3942 } | 3942 } |
| 3943 | 3943 |
| 3944 void test_unusedElement_method_notUsed_referenceFromItself() { | 3944 void test_unusedElement_method_notUsed_referenceFromItself() { |
| 3945 enableUnusedElement = true; | 3945 enableUnusedElement = true; |
| 3946 Source source = addSource(r''' | 3946 Source source = addSource(r''' |
| 3947 class A { | 3947 class A { |
| 3948 static _m(int p) { | 3948 static _m(int p) { |
| 3949 _m(p - 1); | 3949 _m(p - 1); |
| 3950 } | 3950 } |
| 3951 }'''); | 3951 }'''); |
| 3952 resolve(source); | 3952 computeLibrarySourceErrors(source); |
| 3953 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 3953 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 3954 verify([source]); | 3954 verify([source]); |
| 3955 } | 3955 } |
| 3956 | 3956 |
| 3957 void test_unusedElement_setter_isUsed_invocation_implicitThis() { | 3957 void test_unusedElement_setter_isUsed_invocation_implicitThis() { |
| 3958 enableUnusedElement = true; | 3958 enableUnusedElement = true; |
| 3959 Source source = addSource(r''' | 3959 Source source = addSource(r''' |
| 3960 class A { | 3960 class A { |
| 3961 set _s(x) {} | 3961 set _s(x) {} |
| 3962 useSetter() { | 3962 useSetter() { |
| 3963 _s = 42; | 3963 _s = 42; |
| 3964 } | 3964 } |
| 3965 }'''); | 3965 }'''); |
| 3966 resolve(source); | 3966 computeLibrarySourceErrors(source); |
| 3967 assertNoErrors(source); | 3967 assertNoErrors(source); |
| 3968 verify([source]); | 3968 verify([source]); |
| 3969 } | 3969 } |
| 3970 | 3970 |
| 3971 void test_unusedElement_setter_isUsed_invocation_PrefixedIdentifier() { | 3971 void test_unusedElement_setter_isUsed_invocation_PrefixedIdentifier() { |
| 3972 enableUnusedElement = true; | 3972 enableUnusedElement = true; |
| 3973 Source source = addSource(r''' | 3973 Source source = addSource(r''' |
| 3974 class A { | 3974 class A { |
| 3975 set _s(x) {} | 3975 set _s(x) {} |
| 3976 } | 3976 } |
| 3977 main(A a) { | 3977 main(A a) { |
| 3978 a._s = 42; | 3978 a._s = 42; |
| 3979 } | 3979 } |
| 3980 '''); | 3980 '''); |
| 3981 resolve(source); | 3981 computeLibrarySourceErrors(source); |
| 3982 assertNoErrors(source); | 3982 assertNoErrors(source); |
| 3983 verify([source]); | 3983 verify([source]); |
| 3984 } | 3984 } |
| 3985 | 3985 |
| 3986 void test_unusedElement_setter_isUsed_invocation_PropertyAccess() { | 3986 void test_unusedElement_setter_isUsed_invocation_PropertyAccess() { |
| 3987 enableUnusedElement = true; | 3987 enableUnusedElement = true; |
| 3988 Source source = addSource(r''' | 3988 Source source = addSource(r''' |
| 3989 class A { | 3989 class A { |
| 3990 set _s(x) {} | 3990 set _s(x) {} |
| 3991 } | 3991 } |
| 3992 main() { | 3992 main() { |
| 3993 new A()._s = 42; | 3993 new A()._s = 42; |
| 3994 } | 3994 } |
| 3995 '''); | 3995 '''); |
| 3996 resolve(source); | 3996 computeLibrarySourceErrors(source); |
| 3997 assertNoErrors(source); | 3997 assertNoErrors(source); |
| 3998 verify([source]); | 3998 verify([source]); |
| 3999 } | 3999 } |
| 4000 | 4000 |
| 4001 void test_unusedElement_setter_notUsed_noReference() { | 4001 void test_unusedElement_setter_notUsed_noReference() { |
| 4002 enableUnusedElement = true; | 4002 enableUnusedElement = true; |
| 4003 Source source = addSource(r''' | 4003 Source source = addSource(r''' |
| 4004 class A { | 4004 class A { |
| 4005 set _s(x) {} | 4005 set _s(x) {} |
| 4006 }'''); | 4006 }'''); |
| 4007 resolve(source); | 4007 computeLibrarySourceErrors(source); |
| 4008 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 4008 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 4009 verify([source]); | 4009 verify([source]); |
| 4010 } | 4010 } |
| 4011 | 4011 |
| 4012 void test_unusedElement_setter_notUsed_referenceFromItself() { | 4012 void test_unusedElement_setter_notUsed_referenceFromItself() { |
| 4013 enableUnusedElement = true; | 4013 enableUnusedElement = true; |
| 4014 Source source = addSource(r''' | 4014 Source source = addSource(r''' |
| 4015 class A { | 4015 class A { |
| 4016 set _s(int x) { | 4016 set _s(int x) { |
| 4017 if (x > 5) { | 4017 if (x > 5) { |
| 4018 _s = x - 1; | 4018 _s = x - 1; |
| 4019 } | 4019 } |
| 4020 } | 4020 } |
| 4021 }'''); | 4021 }'''); |
| 4022 resolve(source); | 4022 computeLibrarySourceErrors(source); |
| 4023 assertErrors(source, [HintCode.UNUSED_ELEMENT]); | 4023 assertErrors(source, [HintCode.UNUSED_ELEMENT]); |
| 4024 verify([source]); | 4024 verify([source]); |
| 4025 } | 4025 } |
| 4026 | 4026 |
| 4027 void test_unusedField_isUsed_argument() { | 4027 void test_unusedField_isUsed_argument() { |
| 4028 enableUnusedElement = true; | 4028 enableUnusedElement = true; |
| 4029 Source source = addSource(r''' | 4029 Source source = addSource(r''' |
| 4030 class A { | 4030 class A { |
| 4031 int _f = 0; | 4031 int _f = 0; |
| 4032 main() { | 4032 main() { |
| 4033 print(++_f); | 4033 print(++_f); |
| 4034 } | 4034 } |
| 4035 } | 4035 } |
| 4036 print(x) {}'''); | 4036 print(x) {}'''); |
| 4037 resolve(source); | 4037 computeLibrarySourceErrors(source); |
| 4038 assertErrors(source); | 4038 assertErrors(source); |
| 4039 verify([source]); | 4039 verify([source]); |
| 4040 } | 4040 } |
| 4041 | 4041 |
| 4042 void test_unusedField_isUsed_reference_implicitThis() { | 4042 void test_unusedField_isUsed_reference_implicitThis() { |
| 4043 enableUnusedElement = true; | 4043 enableUnusedElement = true; |
| 4044 Source source = addSource(r''' | 4044 Source source = addSource(r''' |
| 4045 class A { | 4045 class A { |
| 4046 int _f; | 4046 int _f; |
| 4047 main() { | 4047 main() { |
| 4048 print(_f); | 4048 print(_f); |
| 4049 } | 4049 } |
| 4050 } | 4050 } |
| 4051 print(x) {}'''); | 4051 print(x) {}'''); |
| 4052 resolve(source); | 4052 computeLibrarySourceErrors(source); |
| 4053 assertErrors(source); | 4053 assertErrors(source); |
| 4054 verify([source]); | 4054 verify([source]); |
| 4055 } | 4055 } |
| 4056 | 4056 |
| 4057 void test_unusedField_isUsed_reference_implicitThis_expressionFunctionBody() { | 4057 void test_unusedField_isUsed_reference_implicitThis_expressionFunctionBody() { |
| 4058 enableUnusedElement = true; | 4058 enableUnusedElement = true; |
| 4059 Source source = addSource(r''' | 4059 Source source = addSource(r''' |
| 4060 class A { | 4060 class A { |
| 4061 int _f; | 4061 int _f; |
| 4062 m() => _f; | 4062 m() => _f; |
| 4063 }'''); | 4063 }'''); |
| 4064 resolve(source); | 4064 computeLibrarySourceErrors(source); |
| 4065 assertErrors(source); | 4065 assertErrors(source); |
| 4066 verify([source]); | 4066 verify([source]); |
| 4067 } | 4067 } |
| 4068 | 4068 |
| 4069 void test_unusedField_isUsed_reference_implicitThis_subclass() { | 4069 void test_unusedField_isUsed_reference_implicitThis_subclass() { |
| 4070 enableUnusedElement = true; | 4070 enableUnusedElement = true; |
| 4071 Source source = addSource(r''' | 4071 Source source = addSource(r''' |
| 4072 class A { | 4072 class A { |
| 4073 int _f; | 4073 int _f; |
| 4074 main() { | 4074 main() { |
| 4075 print(_f); | 4075 print(_f); |
| 4076 } | 4076 } |
| 4077 } | 4077 } |
| 4078 class B extends A { | 4078 class B extends A { |
| 4079 int _f; | 4079 int _f; |
| 4080 } | 4080 } |
| 4081 print(x) {}'''); | 4081 print(x) {}'''); |
| 4082 resolve(source); | 4082 computeLibrarySourceErrors(source); |
| 4083 assertErrors(source); | 4083 assertErrors(source); |
| 4084 verify([source]); | 4084 verify([source]); |
| 4085 } | 4085 } |
| 4086 | 4086 |
| 4087 void test_unusedField_isUsed_reference_qualified_propagatedElement() { | 4087 void test_unusedField_isUsed_reference_qualified_propagatedElement() { |
| 4088 enableUnusedElement = true; | 4088 enableUnusedElement = true; |
| 4089 Source source = addSource(r''' | 4089 Source source = addSource(r''' |
| 4090 class A { | 4090 class A { |
| 4091 int _f; | 4091 int _f; |
| 4092 } | 4092 } |
| 4093 main() { | 4093 main() { |
| 4094 var a = new A(); | 4094 var a = new A(); |
| 4095 print(a._f); | 4095 print(a._f); |
| 4096 } | 4096 } |
| 4097 print(x) {}'''); | 4097 print(x) {}'''); |
| 4098 resolve(source); | 4098 computeLibrarySourceErrors(source); |
| 4099 assertErrors(source); | 4099 assertErrors(source); |
| 4100 verify([source]); | 4100 verify([source]); |
| 4101 } | 4101 } |
| 4102 | 4102 |
| 4103 void test_unusedField_isUsed_reference_qualified_staticElement() { | 4103 void test_unusedField_isUsed_reference_qualified_staticElement() { |
| 4104 enableUnusedElement = true; | 4104 enableUnusedElement = true; |
| 4105 Source source = addSource(r''' | 4105 Source source = addSource(r''' |
| 4106 class A { | 4106 class A { |
| 4107 int _f; | 4107 int _f; |
| 4108 } | 4108 } |
| 4109 main() { | 4109 main() { |
| 4110 A a = new A(); | 4110 A a = new A(); |
| 4111 print(a._f); | 4111 print(a._f); |
| 4112 } | 4112 } |
| 4113 print(x) {}'''); | 4113 print(x) {}'''); |
| 4114 resolve(source); | 4114 computeLibrarySourceErrors(source); |
| 4115 assertErrors(source); | 4115 assertErrors(source); |
| 4116 verify([source]); | 4116 verify([source]); |
| 4117 } | 4117 } |
| 4118 | 4118 |
| 4119 void test_unusedField_isUsed_reference_qualified_unresolved() { | 4119 void test_unusedField_isUsed_reference_qualified_unresolved() { |
| 4120 enableUnusedElement = true; | 4120 enableUnusedElement = true; |
| 4121 Source source = addSource(r''' | 4121 Source source = addSource(r''' |
| 4122 class A { | 4122 class A { |
| 4123 int _f; | 4123 int _f; |
| 4124 } | 4124 } |
| 4125 main(a) { | 4125 main(a) { |
| 4126 print(a._f); | 4126 print(a._f); |
| 4127 } | 4127 } |
| 4128 print(x) {}'''); | 4128 print(x) {}'''); |
| 4129 resolve(source); | 4129 computeLibrarySourceErrors(source); |
| 4130 assertErrors(source); | 4130 assertErrors(source); |
| 4131 verify([source]); | 4131 verify([source]); |
| 4132 } | 4132 } |
| 4133 | 4133 |
| 4134 void test_unusedField_notUsed_compoundAssign() { | 4134 void test_unusedField_notUsed_compoundAssign() { |
| 4135 enableUnusedElement = true; | 4135 enableUnusedElement = true; |
| 4136 Source source = addSource(r''' | 4136 Source source = addSource(r''' |
| 4137 class A { | 4137 class A { |
| 4138 int _f; | 4138 int _f; |
| 4139 main() { | 4139 main() { |
| 4140 _f += 2; | 4140 _f += 2; |
| 4141 } | 4141 } |
| 4142 }'''); | 4142 }'''); |
| 4143 resolve(source); | 4143 computeLibrarySourceErrors(source); |
| 4144 assertErrors(source, [HintCode.UNUSED_FIELD]); | 4144 assertErrors(source, [HintCode.UNUSED_FIELD]); |
| 4145 verify([source]); | 4145 verify([source]); |
| 4146 } | 4146 } |
| 4147 | 4147 |
| 4148 void test_unusedField_notUsed_noReference() { | 4148 void test_unusedField_notUsed_noReference() { |
| 4149 enableUnusedElement = true; | 4149 enableUnusedElement = true; |
| 4150 Source source = addSource(r''' | 4150 Source source = addSource(r''' |
| 4151 class A { | 4151 class A { |
| 4152 int _f; | 4152 int _f; |
| 4153 } | 4153 } |
| 4154 '''); | 4154 '''); |
| 4155 resolve(source); | 4155 computeLibrarySourceErrors(source); |
| 4156 assertErrors(source, [HintCode.UNUSED_FIELD]); | 4156 assertErrors(source, [HintCode.UNUSED_FIELD]); |
| 4157 verify([source]); | 4157 verify([source]); |
| 4158 } | 4158 } |
| 4159 | 4159 |
| 4160 void test_unusedField_notUsed_postfixExpr() { | 4160 void test_unusedField_notUsed_postfixExpr() { |
| 4161 enableUnusedElement = true; | 4161 enableUnusedElement = true; |
| 4162 Source source = addSource(r''' | 4162 Source source = addSource(r''' |
| 4163 class A { | 4163 class A { |
| 4164 int _f = 0; | 4164 int _f = 0; |
| 4165 main() { | 4165 main() { |
| 4166 _f++; | 4166 _f++; |
| 4167 } | 4167 } |
| 4168 }'''); | 4168 }'''); |
| 4169 resolve(source); | 4169 computeLibrarySourceErrors(source); |
| 4170 assertErrors(source, [HintCode.UNUSED_FIELD]); | 4170 assertErrors(source, [HintCode.UNUSED_FIELD]); |
| 4171 verify([source]); | 4171 verify([source]); |
| 4172 } | 4172 } |
| 4173 | 4173 |
| 4174 void test_unusedField_notUsed_prefixExpr() { | 4174 void test_unusedField_notUsed_prefixExpr() { |
| 4175 enableUnusedElement = true; | 4175 enableUnusedElement = true; |
| 4176 Source source = addSource(r''' | 4176 Source source = addSource(r''' |
| 4177 class A { | 4177 class A { |
| 4178 int _f = 0; | 4178 int _f = 0; |
| 4179 main() { | 4179 main() { |
| 4180 ++_f; | 4180 ++_f; |
| 4181 } | 4181 } |
| 4182 }'''); | 4182 }'''); |
| 4183 resolve(source); | 4183 computeLibrarySourceErrors(source); |
| 4184 assertErrors(source, [HintCode.UNUSED_FIELD]); | 4184 assertErrors(source, [HintCode.UNUSED_FIELD]); |
| 4185 verify([source]); | 4185 verify([source]); |
| 4186 } | 4186 } |
| 4187 | 4187 |
| 4188 void test_unusedField_notUsed_simpleAssignment() { | 4188 void test_unusedField_notUsed_simpleAssignment() { |
| 4189 enableUnusedElement = true; | 4189 enableUnusedElement = true; |
| 4190 Source source = addSource(r''' | 4190 Source source = addSource(r''' |
| 4191 class A { | 4191 class A { |
| 4192 int _f; | 4192 int _f; |
| 4193 m() { | 4193 m() { |
| 4194 _f = 1; | 4194 _f = 1; |
| 4195 } | 4195 } |
| 4196 } | 4196 } |
| 4197 main(A a) { | 4197 main(A a) { |
| 4198 a._f = 2; | 4198 a._f = 2; |
| 4199 } | 4199 } |
| 4200 '''); | 4200 '''); |
| 4201 resolve(source); | 4201 computeLibrarySourceErrors(source); |
| 4202 assertErrors(source, [HintCode.UNUSED_FIELD]); | 4202 assertErrors(source, [HintCode.UNUSED_FIELD]); |
| 4203 verify([source]); | 4203 verify([source]); |
| 4204 } | 4204 } |
| 4205 | 4205 |
| 4206 void test_unusedImport() { | 4206 void test_unusedImport() { |
| 4207 Source source = addSource(r''' | 4207 Source source = addSource(r''' |
| 4208 library L; | 4208 library L; |
| 4209 import 'lib1.dart';'''); | 4209 import 'lib1.dart';'''); |
| 4210 Source source2 = addNamedSource("/lib1.dart", "library lib1;"); | 4210 Source source2 = addNamedSource("/lib1.dart", "library lib1;"); |
| 4211 resolve(source); | 4211 computeLibrarySourceErrors(source); |
| 4212 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 4212 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 4213 assertNoErrors(source2); | 4213 assertNoErrors(source2); |
| 4214 verify([source, source2]); | 4214 verify([source, source2]); |
| 4215 } | 4215 } |
| 4216 | 4216 |
| 4217 void test_unusedImport_as() { | 4217 void test_unusedImport_as() { |
| 4218 Source source = addSource(r''' | 4218 Source source = addSource(r''' |
| 4219 library L; | 4219 library L; |
| 4220 import 'lib1.dart'; | 4220 import 'lib1.dart'; |
| 4221 import 'lib1.dart' as one; | 4221 import 'lib1.dart' as one; |
| 4222 one.A a;'''); | 4222 one.A a;'''); |
| 4223 Source source2 = addNamedSource("/lib1.dart", r''' | 4223 Source source2 = addNamedSource("/lib1.dart", r''' |
| 4224 library lib1; | 4224 library lib1; |
| 4225 class A {}'''); | 4225 class A {}'''); |
| 4226 resolve(source); | 4226 computeLibrarySourceErrors(source); |
| 4227 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 4227 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 4228 assertNoErrors(source2); | 4228 assertNoErrors(source2); |
| 4229 verify([source, source2]); | 4229 verify([source, source2]); |
| 4230 } | 4230 } |
| 4231 | 4231 |
| 4232 void test_unusedImport_hide() { | 4232 void test_unusedImport_hide() { |
| 4233 Source source = addSource(r''' | 4233 Source source = addSource(r''' |
| 4234 library L; | 4234 library L; |
| 4235 import 'lib1.dart'; | 4235 import 'lib1.dart'; |
| 4236 import 'lib1.dart' hide A; | 4236 import 'lib1.dart' hide A; |
| 4237 A a;'''); | 4237 A a;'''); |
| 4238 Source source2 = addNamedSource("/lib1.dart", r''' | 4238 Source source2 = addNamedSource("/lib1.dart", r''' |
| 4239 library lib1; | 4239 library lib1; |
| 4240 class A {}'''); | 4240 class A {}'''); |
| 4241 resolve(source); | 4241 computeLibrarySourceErrors(source); |
| 4242 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 4242 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 4243 assertNoErrors(source2); | 4243 assertNoErrors(source2); |
| 4244 verify([source, source2]); | 4244 verify([source, source2]); |
| 4245 } | 4245 } |
| 4246 | 4246 |
| 4247 void test_unusedImport_show() { | 4247 void test_unusedImport_show() { |
| 4248 Source source = addSource(r''' | 4248 Source source = addSource(r''' |
| 4249 library L; | 4249 library L; |
| 4250 import 'lib1.dart' show A; | 4250 import 'lib1.dart' show A; |
| 4251 import 'lib1.dart' show B; | 4251 import 'lib1.dart' show B; |
| 4252 A a;'''); | 4252 A a;'''); |
| 4253 Source source2 = addNamedSource("/lib1.dart", r''' | 4253 Source source2 = addNamedSource("/lib1.dart", r''' |
| 4254 library lib1; | 4254 library lib1; |
| 4255 class A {} | 4255 class A {} |
| 4256 class B {}'''); | 4256 class B {}'''); |
| 4257 resolve(source); | 4257 computeLibrarySourceErrors(source); |
| 4258 assertErrors(source, [HintCode.UNUSED_IMPORT]); | 4258 assertErrors(source, [HintCode.UNUSED_IMPORT]); |
| 4259 assertNoErrors(source2); | 4259 assertNoErrors(source2); |
| 4260 verify([source, source2]); | 4260 verify([source, source2]); |
| 4261 } | 4261 } |
| 4262 | 4262 |
| 4263 void test_unusedLocalVariable_inCatch_exception() { | 4263 void test_unusedLocalVariable_inCatch_exception() { |
| 4264 enableUnusedLocalVariable = true; | 4264 enableUnusedLocalVariable = true; |
| 4265 Source source = addSource(r''' | 4265 Source source = addSource(r''' |
| 4266 main() { | 4266 main() { |
| 4267 try { | 4267 try { |
| 4268 } on String catch (exception) { | 4268 } on String catch (exception) { |
| 4269 } | 4269 } |
| 4270 }'''); | 4270 }'''); |
| 4271 resolve(source); | 4271 computeLibrarySourceErrors(source); |
| 4272 assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]); | 4272 assertErrors(source, [HintCode.UNUSED_CATCH_CLAUSE]); |
| 4273 verify([source]); | 4273 verify([source]); |
| 4274 } | 4274 } |
| 4275 | 4275 |
| 4276 void test_unusedLocalVariable_inCatch_exception_hasStack() { | 4276 void test_unusedLocalVariable_inCatch_exception_hasStack() { |
| 4277 enableUnusedLocalVariable = true; | 4277 enableUnusedLocalVariable = true; |
| 4278 Source source = addSource(r''' | 4278 Source source = addSource(r''' |
| 4279 main() { | 4279 main() { |
| 4280 try { | 4280 try { |
| 4281 } catch (exception, stack) { | 4281 } catch (exception, stack) { |
| 4282 print(stack); | 4282 print(stack); |
| 4283 } | 4283 } |
| 4284 }'''); | 4284 }'''); |
| 4285 resolve(source); | 4285 computeLibrarySourceErrors(source); |
| 4286 assertNoErrors(source); | 4286 assertNoErrors(source); |
| 4287 verify([source]); | 4287 verify([source]); |
| 4288 } | 4288 } |
| 4289 | 4289 |
| 4290 void test_unusedLocalVariable_inCatch_exception_noOnClause() { | 4290 void test_unusedLocalVariable_inCatch_exception_noOnClause() { |
| 4291 enableUnusedLocalVariable = true; | 4291 enableUnusedLocalVariable = true; |
| 4292 Source source = addSource(r''' | 4292 Source source = addSource(r''' |
| 4293 main() { | 4293 main() { |
| 4294 try { | 4294 try { |
| 4295 } catch (exception) { | 4295 } catch (exception) { |
| 4296 } | 4296 } |
| 4297 }'''); | 4297 }'''); |
| 4298 resolve(source); | 4298 computeLibrarySourceErrors(source); |
| 4299 assertNoErrors(source); | 4299 assertNoErrors(source); |
| 4300 verify([source]); | 4300 verify([source]); |
| 4301 } | 4301 } |
| 4302 | 4302 |
| 4303 void test_unusedLocalVariable_inCatch_stackTrace() { | 4303 void test_unusedLocalVariable_inCatch_stackTrace() { |
| 4304 enableUnusedLocalVariable = true; | 4304 enableUnusedLocalVariable = true; |
| 4305 Source source = addSource(r''' | 4305 Source source = addSource(r''' |
| 4306 main() { | 4306 main() { |
| 4307 try { | 4307 try { |
| 4308 } catch (exception, stackTrace) { | 4308 } catch (exception, stackTrace) { |
| 4309 } | 4309 } |
| 4310 }'''); | 4310 }'''); |
| 4311 resolve(source); | 4311 computeLibrarySourceErrors(source); |
| 4312 assertErrors(source, [HintCode.UNUSED_CATCH_STACK]); | 4312 assertErrors(source, [HintCode.UNUSED_CATCH_STACK]); |
| 4313 verify([source]); | 4313 verify([source]); |
| 4314 } | 4314 } |
| 4315 | 4315 |
| 4316 void test_unusedLocalVariable_inCatch_stackTrace_used() { | 4316 void test_unusedLocalVariable_inCatch_stackTrace_used() { |
| 4317 enableUnusedLocalVariable = true; | 4317 enableUnusedLocalVariable = true; |
| 4318 Source source = addSource(r''' | 4318 Source source = addSource(r''' |
| 4319 main() { | 4319 main() { |
| 4320 try { | 4320 try { |
| 4321 } catch (exception, stackTrace) { | 4321 } catch (exception, stackTrace) { |
| 4322 print('exception at $stackTrace'); | 4322 print('exception at $stackTrace'); |
| 4323 } | 4323 } |
| 4324 } | 4324 } |
| 4325 print(x) {}'''); | 4325 print(x) {}'''); |
| 4326 resolve(source); | 4326 computeLibrarySourceErrors(source); |
| 4327 assertErrors(source); | 4327 assertErrors(source); |
| 4328 verify([source]); | 4328 verify([source]); |
| 4329 } | 4329 } |
| 4330 | 4330 |
| 4331 void test_unusedLocalVariable_inFor_underscore_ignored() { | 4331 void test_unusedLocalVariable_inFor_underscore_ignored() { |
| 4332 enableUnusedLocalVariable = true; | 4332 enableUnusedLocalVariable = true; |
| 4333 Source source = addSource(r''' | 4333 Source source = addSource(r''' |
| 4334 main() { | 4334 main() { |
| 4335 for (var _ in [1,2,3]) { | 4335 for (var _ in [1,2,3]) { |
| 4336 for (var __ in [4,5,6]) { | 4336 for (var __ in [4,5,6]) { |
| 4337 // do something | 4337 // do something |
| 4338 } | 4338 } |
| 4339 } | 4339 } |
| 4340 }'''); | 4340 }'''); |
| 4341 resolve(source); | 4341 computeLibrarySourceErrors(source); |
| 4342 assertErrors(source); | 4342 assertErrors(source); |
| 4343 verify([source]); | 4343 verify([source]); |
| 4344 } | 4344 } |
| 4345 | 4345 |
| 4346 void test_unusedLocalVariable_inFunction() { | 4346 void test_unusedLocalVariable_inFunction() { |
| 4347 enableUnusedLocalVariable = true; | 4347 enableUnusedLocalVariable = true; |
| 4348 Source source = addSource(r''' | 4348 Source source = addSource(r''' |
| 4349 main() { | 4349 main() { |
| 4350 var v = 1; | 4350 var v = 1; |
| 4351 v = 2; | 4351 v = 2; |
| 4352 }'''); | 4352 }'''); |
| 4353 resolve(source); | 4353 computeLibrarySourceErrors(source); |
| 4354 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); | 4354 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); |
| 4355 verify([source]); | 4355 verify([source]); |
| 4356 } | 4356 } |
| 4357 | 4357 |
| 4358 void test_unusedLocalVariable_inMethod() { | 4358 void test_unusedLocalVariable_inMethod() { |
| 4359 enableUnusedLocalVariable = true; | 4359 enableUnusedLocalVariable = true; |
| 4360 Source source = addSource(r''' | 4360 Source source = addSource(r''' |
| 4361 class A { | 4361 class A { |
| 4362 foo() { | 4362 foo() { |
| 4363 var v = 1; | 4363 var v = 1; |
| 4364 v = 2; | 4364 v = 2; |
| 4365 } | 4365 } |
| 4366 }'''); | 4366 }'''); |
| 4367 resolve(source); | 4367 computeLibrarySourceErrors(source); |
| 4368 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); | 4368 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); |
| 4369 verify([source]); | 4369 verify([source]); |
| 4370 } | 4370 } |
| 4371 | 4371 |
| 4372 void test_unusedLocalVariable_isInvoked() { | 4372 void test_unusedLocalVariable_isInvoked() { |
| 4373 enableUnusedLocalVariable = true; | 4373 enableUnusedLocalVariable = true; |
| 4374 Source source = addSource(r''' | 4374 Source source = addSource(r''' |
| 4375 typedef Foo(); | 4375 typedef Foo(); |
| 4376 main() { | 4376 main() { |
| 4377 Foo foo; | 4377 Foo foo; |
| 4378 foo(); | 4378 foo(); |
| 4379 }'''); | 4379 }'''); |
| 4380 resolve(source); | 4380 computeLibrarySourceErrors(source); |
| 4381 assertErrors(source); | 4381 assertErrors(source); |
| 4382 verify([source]); | 4382 verify([source]); |
| 4383 } | 4383 } |
| 4384 | 4384 |
| 4385 void test_unusedLocalVariable_isRead_notUsed_compoundAssign() { | 4385 void test_unusedLocalVariable_isRead_notUsed_compoundAssign() { |
| 4386 enableUnusedLocalVariable = true; | 4386 enableUnusedLocalVariable = true; |
| 4387 Source source = addSource(r''' | 4387 Source source = addSource(r''' |
| 4388 main() { | 4388 main() { |
| 4389 var v = 1; | 4389 var v = 1; |
| 4390 v += 2; | 4390 v += 2; |
| 4391 }'''); | 4391 }'''); |
| 4392 resolve(source); | 4392 computeLibrarySourceErrors(source); |
| 4393 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); | 4393 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); |
| 4394 verify([source]); | 4394 verify([source]); |
| 4395 } | 4395 } |
| 4396 | 4396 |
| 4397 void test_unusedLocalVariable_isRead_notUsed_postfixExpr() { | 4397 void test_unusedLocalVariable_isRead_notUsed_postfixExpr() { |
| 4398 enableUnusedLocalVariable = true; | 4398 enableUnusedLocalVariable = true; |
| 4399 Source source = addSource(r''' | 4399 Source source = addSource(r''' |
| 4400 main() { | 4400 main() { |
| 4401 var v = 1; | 4401 var v = 1; |
| 4402 v++; | 4402 v++; |
| 4403 }'''); | 4403 }'''); |
| 4404 resolve(source); | 4404 computeLibrarySourceErrors(source); |
| 4405 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); | 4405 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); |
| 4406 verify([source]); | 4406 verify([source]); |
| 4407 } | 4407 } |
| 4408 | 4408 |
| 4409 void test_unusedLocalVariable_isRead_notUsed_prefixExpr() { | 4409 void test_unusedLocalVariable_isRead_notUsed_prefixExpr() { |
| 4410 enableUnusedLocalVariable = true; | 4410 enableUnusedLocalVariable = true; |
| 4411 Source source = addSource(r''' | 4411 Source source = addSource(r''' |
| 4412 main() { | 4412 main() { |
| 4413 var v = 1; | 4413 var v = 1; |
| 4414 ++v; | 4414 ++v; |
| 4415 }'''); | 4415 }'''); |
| 4416 resolve(source); | 4416 computeLibrarySourceErrors(source); |
| 4417 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); | 4417 assertErrors(source, [HintCode.UNUSED_LOCAL_VARIABLE]); |
| 4418 verify([source]); | 4418 verify([source]); |
| 4419 } | 4419 } |
| 4420 | 4420 |
| 4421 void test_unusedLocalVariable_isRead_usedArgument() { | 4421 void test_unusedLocalVariable_isRead_usedArgument() { |
| 4422 enableUnusedLocalVariable = true; | 4422 enableUnusedLocalVariable = true; |
| 4423 Source source = addSource(r''' | 4423 Source source = addSource(r''' |
| 4424 main() { | 4424 main() { |
| 4425 var v = 1; | 4425 var v = 1; |
| 4426 print(++v); | 4426 print(++v); |
| 4427 } | 4427 } |
| 4428 print(x) {}'''); | 4428 print(x) {}'''); |
| 4429 resolve(source); | 4429 computeLibrarySourceErrors(source); |
| 4430 assertErrors(source); | 4430 assertErrors(source); |
| 4431 verify([source]); | 4431 verify([source]); |
| 4432 } | 4432 } |
| 4433 | 4433 |
| 4434 void test_unusedLocalVariable_isRead_usedInvocationTarget() { | 4434 void test_unusedLocalVariable_isRead_usedInvocationTarget() { |
| 4435 enableUnusedLocalVariable = true; | 4435 enableUnusedLocalVariable = true; |
| 4436 Source source = addSource(r''' | 4436 Source source = addSource(r''' |
| 4437 class A { | 4437 class A { |
| 4438 foo() {} | 4438 foo() {} |
| 4439 } | 4439 } |
| 4440 main() { | 4440 main() { |
| 4441 var a = new A(); | 4441 var a = new A(); |
| 4442 a.foo(); | 4442 a.foo(); |
| 4443 } | 4443 } |
| 4444 '''); | 4444 '''); |
| 4445 resolve(source); | 4445 computeLibrarySourceErrors(source); |
| 4446 assertErrors(source); | 4446 assertErrors(source); |
| 4447 verify([source]); | 4447 verify([source]); |
| 4448 } | 4448 } |
| 4449 | 4449 |
| 4450 void test_useOfVoidResult_assignmentExpression_function() { | 4450 void test_useOfVoidResult_assignmentExpression_function() { |
| 4451 Source source = addSource(r''' | 4451 Source source = addSource(r''' |
| 4452 void f() {} | 4452 void f() {} |
| 4453 class A { | 4453 class A { |
| 4454 n() { | 4454 n() { |
| 4455 var a; | 4455 var a; |
| 4456 a = f(); | 4456 a = f(); |
| 4457 } | 4457 } |
| 4458 }'''); | 4458 }'''); |
| 4459 resolve(source); | 4459 computeLibrarySourceErrors(source); |
| 4460 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 4460 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 4461 verify([source]); | 4461 verify([source]); |
| 4462 } | 4462 } |
| 4463 | 4463 |
| 4464 void test_useOfVoidResult_assignmentExpression_method() { | 4464 void test_useOfVoidResult_assignmentExpression_method() { |
| 4465 Source source = addSource(r''' | 4465 Source source = addSource(r''' |
| 4466 class A { | 4466 class A { |
| 4467 void m() {} | 4467 void m() {} |
| 4468 n() { | 4468 n() { |
| 4469 var a; | 4469 var a; |
| 4470 a = m(); | 4470 a = m(); |
| 4471 } | 4471 } |
| 4472 }'''); | 4472 }'''); |
| 4473 resolve(source); | 4473 computeLibrarySourceErrors(source); |
| 4474 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 4474 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 4475 verify([source]); | 4475 verify([source]); |
| 4476 } | 4476 } |
| 4477 | 4477 |
| 4478 void test_useOfVoidResult_inForLoop() { | 4478 void test_useOfVoidResult_inForLoop() { |
| 4479 Source source = addSource(r''' | 4479 Source source = addSource(r''' |
| 4480 class A { | 4480 class A { |
| 4481 void m() {} | 4481 void m() {} |
| 4482 n() { | 4482 n() { |
| 4483 for(var a = m();;) {} | 4483 for(var a = m();;) {} |
| 4484 } | 4484 } |
| 4485 }'''); | 4485 }'''); |
| 4486 resolve(source); | 4486 computeLibrarySourceErrors(source); |
| 4487 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 4487 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 4488 verify([source]); | 4488 verify([source]); |
| 4489 } | 4489 } |
| 4490 | 4490 |
| 4491 void test_useOfVoidResult_variableDeclaration_function() { | 4491 void test_useOfVoidResult_variableDeclaration_function() { |
| 4492 Source source = addSource(r''' | 4492 Source source = addSource(r''' |
| 4493 void f() {} | 4493 void f() {} |
| 4494 class A { | 4494 class A { |
| 4495 n() { | 4495 n() { |
| 4496 var a = f(); | 4496 var a = f(); |
| 4497 } | 4497 } |
| 4498 }'''); | 4498 }'''); |
| 4499 resolve(source); | 4499 computeLibrarySourceErrors(source); |
| 4500 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 4500 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 4501 verify([source]); | 4501 verify([source]); |
| 4502 } | 4502 } |
| 4503 | 4503 |
| 4504 void test_useOfVoidResult_variableDeclaration_method() { | 4504 void test_useOfVoidResult_variableDeclaration_method() { |
| 4505 Source source = addSource(r''' | 4505 Source source = addSource(r''' |
| 4506 class A { | 4506 class A { |
| 4507 void m() {} | 4507 void m() {} |
| 4508 n() { | 4508 n() { |
| 4509 var a = m(); | 4509 var a = m(); |
| 4510 } | 4510 } |
| 4511 }'''); | 4511 }'''); |
| 4512 resolve(source); | 4512 computeLibrarySourceErrors(source); |
| 4513 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); | 4513 assertErrors(source, [HintCode.USE_OF_VOID_RESULT]); |
| 4514 verify([source]); | 4514 verify([source]); |
| 4515 } | 4515 } |
| 4516 | 4516 |
| 4517 void test_useOfVoidResult_variableDeclaration_method2() { | 4517 void test_useOfVoidResult_variableDeclaration_method2() { |
| 4518 Source source = addSource(r''' | 4518 Source source = addSource(r''' |
| 4519 class A { | 4519 class A { |
| 4520 void m() {} | 4520 void m() {} |
| 4521 n() { | 4521 n() { |
| 4522 var a = m(), b = m(); | 4522 var a = m(), b = m(); |
| 4523 } | 4523 } |
| 4524 }'''); | 4524 }'''); |
| 4525 resolve(source); | 4525 computeLibrarySourceErrors(source); |
| 4526 assertErrors( | 4526 assertErrors( |
| 4527 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); | 4527 source, [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); |
| 4528 verify([source]); | 4528 verify([source]); |
| 4529 } | 4529 } |
| 4530 } | 4530 } |
| 4531 | 4531 |
| 4532 @reflectiveTest | 4532 @reflectiveTest |
| 4533 class InheritanceManagerTest extends EngineTestCase { | 4533 class InheritanceManagerTest extends EngineTestCase { |
| 4534 /** | 4534 /** |
| 4535 * The type provider used to access the types. | 4535 * The type provider used to access the types. |
| (...skipping 1917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6453 } | 6453 } |
| 6454 | 6454 |
| 6455 @reflectiveTest | 6455 @reflectiveTest |
| 6456 class NonHintCodeTest extends ResolverTestCase { | 6456 class NonHintCodeTest extends ResolverTestCase { |
| 6457 void test_deadCode_deadBlock_conditionalElse_debugConst() { | 6457 void test_deadCode_deadBlock_conditionalElse_debugConst() { |
| 6458 Source source = addSource(r''' | 6458 Source source = addSource(r''' |
| 6459 const bool DEBUG = true; | 6459 const bool DEBUG = true; |
| 6460 f() { | 6460 f() { |
| 6461 DEBUG ? 1 : 2; | 6461 DEBUG ? 1 : 2; |
| 6462 }'''); | 6462 }'''); |
| 6463 resolve(source); | 6463 computeLibrarySourceErrors(source); |
| 6464 assertNoErrors(source); | 6464 assertNoErrors(source); |
| 6465 verify([source]); | 6465 verify([source]); |
| 6466 } | 6466 } |
| 6467 | 6467 |
| 6468 void test_deadCode_deadBlock_conditionalIf_debugConst() { | 6468 void test_deadCode_deadBlock_conditionalIf_debugConst() { |
| 6469 Source source = addSource(r''' | 6469 Source source = addSource(r''' |
| 6470 const bool DEBUG = false; | 6470 const bool DEBUG = false; |
| 6471 f() { | 6471 f() { |
| 6472 DEBUG ? 1 : 2; | 6472 DEBUG ? 1 : 2; |
| 6473 }'''); | 6473 }'''); |
| 6474 resolve(source); | 6474 computeLibrarySourceErrors(source); |
| 6475 assertNoErrors(source); | 6475 assertNoErrors(source); |
| 6476 verify([source]); | 6476 verify([source]); |
| 6477 } | 6477 } |
| 6478 | 6478 |
| 6479 void test_deadCode_deadBlock_else() { | 6479 void test_deadCode_deadBlock_else() { |
| 6480 Source source = addSource(r''' | 6480 Source source = addSource(r''' |
| 6481 const bool DEBUG = true; | 6481 const bool DEBUG = true; |
| 6482 f() { | 6482 f() { |
| 6483 if(DEBUG) {} else {} | 6483 if(DEBUG) {} else {} |
| 6484 }'''); | 6484 }'''); |
| 6485 resolve(source); | 6485 computeLibrarySourceErrors(source); |
| 6486 assertNoErrors(source); | 6486 assertNoErrors(source); |
| 6487 verify([source]); | 6487 verify([source]); |
| 6488 } | 6488 } |
| 6489 | 6489 |
| 6490 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier() { | 6490 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier() { |
| 6491 Source source = addSource(r''' | 6491 Source source = addSource(r''' |
| 6492 class A { | 6492 class A { |
| 6493 static const bool DEBUG = false; | 6493 static const bool DEBUG = false; |
| 6494 } | 6494 } |
| 6495 f() { | 6495 f() { |
| 6496 if(A.DEBUG) {} | 6496 if(A.DEBUG) {} |
| 6497 }'''); | 6497 }'''); |
| 6498 resolve(source); | 6498 computeLibrarySourceErrors(source); |
| 6499 assertNoErrors(source); | 6499 assertNoErrors(source); |
| 6500 verify([source]); | 6500 verify([source]); |
| 6501 } | 6501 } |
| 6502 | 6502 |
| 6503 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() { | 6503 void test_deadCode_deadBlock_if_debugConst_prefixedIdentifier2() { |
| 6504 Source source = addSource(r''' | 6504 Source source = addSource(r''' |
| 6505 library L; | 6505 library L; |
| 6506 import 'lib2.dart'; | 6506 import 'lib2.dart'; |
| 6507 f() { | 6507 f() { |
| 6508 if(A.DEBUG) {} | 6508 if(A.DEBUG) {} |
| 6509 }'''); | 6509 }'''); |
| 6510 addNamedSource("/lib2.dart", r''' | 6510 addNamedSource("/lib2.dart", r''' |
| 6511 library lib2; | 6511 library lib2; |
| 6512 class A { | 6512 class A { |
| 6513 static const bool DEBUG = false; | 6513 static const bool DEBUG = false; |
| 6514 }'''); | 6514 }'''); |
| 6515 resolve(source); | 6515 computeLibrarySourceErrors(source); |
| 6516 assertNoErrors(source); | 6516 assertNoErrors(source); |
| 6517 verify([source]); | 6517 verify([source]); |
| 6518 } | 6518 } |
| 6519 | 6519 |
| 6520 void test_deadCode_deadBlock_if_debugConst_propertyAccessor() { | 6520 void test_deadCode_deadBlock_if_debugConst_propertyAccessor() { |
| 6521 Source source = addSource(r''' | 6521 Source source = addSource(r''' |
| 6522 library L; | 6522 library L; |
| 6523 import 'lib2.dart' as LIB; | 6523 import 'lib2.dart' as LIB; |
| 6524 f() { | 6524 f() { |
| 6525 if(LIB.A.DEBUG) {} | 6525 if(LIB.A.DEBUG) {} |
| 6526 }'''); | 6526 }'''); |
| 6527 addNamedSource("/lib2.dart", r''' | 6527 addNamedSource("/lib2.dart", r''' |
| 6528 library lib2; | 6528 library lib2; |
| 6529 class A { | 6529 class A { |
| 6530 static const bool DEBUG = false; | 6530 static const bool DEBUG = false; |
| 6531 }'''); | 6531 }'''); |
| 6532 resolve(source); | 6532 computeLibrarySourceErrors(source); |
| 6533 assertNoErrors(source); | 6533 assertNoErrors(source); |
| 6534 verify([source]); | 6534 verify([source]); |
| 6535 } | 6535 } |
| 6536 | 6536 |
| 6537 void test_deadCode_deadBlock_if_debugConst_simpleIdentifier() { | 6537 void test_deadCode_deadBlock_if_debugConst_simpleIdentifier() { |
| 6538 Source source = addSource(r''' | 6538 Source source = addSource(r''' |
| 6539 const bool DEBUG = false; | 6539 const bool DEBUG = false; |
| 6540 f() { | 6540 f() { |
| 6541 if(DEBUG) {} | 6541 if(DEBUG) {} |
| 6542 }'''); | 6542 }'''); |
| 6543 resolve(source); | 6543 computeLibrarySourceErrors(source); |
| 6544 assertNoErrors(source); | 6544 assertNoErrors(source); |
| 6545 verify([source]); | 6545 verify([source]); |
| 6546 } | 6546 } |
| 6547 | 6547 |
| 6548 void test_deadCode_deadBlock_while_debugConst() { | 6548 void test_deadCode_deadBlock_while_debugConst() { |
| 6549 Source source = addSource(r''' | 6549 Source source = addSource(r''' |
| 6550 const bool DEBUG = false; | 6550 const bool DEBUG = false; |
| 6551 f() { | 6551 f() { |
| 6552 while(DEBUG) {} | 6552 while(DEBUG) {} |
| 6553 }'''); | 6553 }'''); |
| 6554 resolve(source); | 6554 computeLibrarySourceErrors(source); |
| 6555 assertNoErrors(source); | 6555 assertNoErrors(source); |
| 6556 verify([source]); | 6556 verify([source]); |
| 6557 } | 6557 } |
| 6558 | 6558 |
| 6559 void test_deadCode_deadCatch_onCatchSubtype() { | 6559 void test_deadCode_deadCatch_onCatchSubtype() { |
| 6560 Source source = addSource(r''' | 6560 Source source = addSource(r''' |
| 6561 class A {} | 6561 class A {} |
| 6562 class B extends A {} | 6562 class B extends A {} |
| 6563 f() { | 6563 f() { |
| 6564 try {} on B catch (e) {} on A catch (e) {} catch (e) {} | 6564 try {} on B catch (e) {} on A catch (e) {} catch (e) {} |
| 6565 }'''); | 6565 }'''); |
| 6566 resolve(source); | 6566 computeLibrarySourceErrors(source); |
| 6567 assertNoErrors(source); | 6567 assertNoErrors(source); |
| 6568 verify([source]); | 6568 verify([source]); |
| 6569 } | 6569 } |
| 6570 | 6570 |
| 6571 void test_deadCode_deadOperandLHS_and_debugConst() { | 6571 void test_deadCode_deadOperandLHS_and_debugConst() { |
| 6572 Source source = addSource(r''' | 6572 Source source = addSource(r''' |
| 6573 const bool DEBUG = false; | 6573 const bool DEBUG = false; |
| 6574 f() { | 6574 f() { |
| 6575 bool b = DEBUG && false; | 6575 bool b = DEBUG && false; |
| 6576 }'''); | 6576 }'''); |
| 6577 resolve(source); | 6577 computeLibrarySourceErrors(source); |
| 6578 assertNoErrors(source); | 6578 assertNoErrors(source); |
| 6579 verify([source]); | 6579 verify([source]); |
| 6580 } | 6580 } |
| 6581 | 6581 |
| 6582 void test_deadCode_deadOperandLHS_or_debugConst() { | 6582 void test_deadCode_deadOperandLHS_or_debugConst() { |
| 6583 Source source = addSource(r''' | 6583 Source source = addSource(r''' |
| 6584 const bool DEBUG = true; | 6584 const bool DEBUG = true; |
| 6585 f() { | 6585 f() { |
| 6586 bool b = DEBUG || true; | 6586 bool b = DEBUG || true; |
| 6587 }'''); | 6587 }'''); |
| 6588 resolve(source); | 6588 computeLibrarySourceErrors(source); |
| 6589 assertNoErrors(source); | 6589 assertNoErrors(source); |
| 6590 verify([source]); | 6590 verify([source]); |
| 6591 } | 6591 } |
| 6592 | 6592 |
| 6593 void test_divisionOptimization() { | 6593 void test_divisionOptimization() { |
| 6594 Source source = addSource(r''' | 6594 Source source = addSource(r''' |
| 6595 f(int x, int y) { | 6595 f(int x, int y) { |
| 6596 var v = x / y.toInt(); | 6596 var v = x / y.toInt(); |
| 6597 }'''); | 6597 }'''); |
| 6598 resolve(source); | 6598 computeLibrarySourceErrors(source); |
| 6599 assertNoErrors(source); | 6599 assertNoErrors(source); |
| 6600 verify([source]); | 6600 verify([source]); |
| 6601 } | 6601 } |
| 6602 | 6602 |
| 6603 void test_divisionOptimization_supressIfDivisionNotDefinedInCore() { | 6603 void test_divisionOptimization_supressIfDivisionNotDefinedInCore() { |
| 6604 Source source = addSource(r''' | 6604 Source source = addSource(r''' |
| 6605 f(x, y) { | 6605 f(x, y) { |
| 6606 var v = (x / y).toInt(); | 6606 var v = (x / y).toInt(); |
| 6607 }'''); | 6607 }'''); |
| 6608 resolve(source); | 6608 computeLibrarySourceErrors(source); |
| 6609 assertNoErrors(source); | 6609 assertNoErrors(source); |
| 6610 verify([source]); | 6610 verify([source]); |
| 6611 } | 6611 } |
| 6612 | 6612 |
| 6613 void test_divisionOptimization_supressIfDivisionOverridden() { | 6613 void test_divisionOptimization_supressIfDivisionOverridden() { |
| 6614 Source source = addSource(r''' | 6614 Source source = addSource(r''' |
| 6615 class A { | 6615 class A { |
| 6616 num operator /(x) { return x; } | 6616 num operator /(x) { return x; } |
| 6617 } | 6617 } |
| 6618 f(A x, A y) { | 6618 f(A x, A y) { |
| 6619 var v = (x / y).toInt(); | 6619 var v = (x / y).toInt(); |
| 6620 }'''); | 6620 }'''); |
| 6621 resolve(source); | 6621 computeLibrarySourceErrors(source); |
| 6622 assertNoErrors(source); | 6622 assertNoErrors(source); |
| 6623 verify([source]); | 6623 verify([source]); |
| 6624 } | 6624 } |
| 6625 | 6625 |
| 6626 void test_duplicateImport_as() { | 6626 void test_duplicateImport_as() { |
| 6627 Source source = addSource(r''' | 6627 Source source = addSource(r''' |
| 6628 library L; | 6628 library L; |
| 6629 import 'lib1.dart'; | 6629 import 'lib1.dart'; |
| 6630 import 'lib1.dart' as one; | 6630 import 'lib1.dart' as one; |
| 6631 A a; | 6631 A a; |
| 6632 one.A a2;'''); | 6632 one.A a2;'''); |
| 6633 addNamedSource("/lib1.dart", r''' | 6633 addNamedSource("/lib1.dart", r''' |
| 6634 library lib1; | 6634 library lib1; |
| 6635 class A {}'''); | 6635 class A {}'''); |
| 6636 resolve(source); | 6636 computeLibrarySourceErrors(source); |
| 6637 assertNoErrors(source); | 6637 assertNoErrors(source); |
| 6638 verify([source]); | 6638 verify([source]); |
| 6639 } | 6639 } |
| 6640 | 6640 |
| 6641 void test_duplicateImport_hide() { | 6641 void test_duplicateImport_hide() { |
| 6642 Source source = addSource(r''' | 6642 Source source = addSource(r''' |
| 6643 library L; | 6643 library L; |
| 6644 import 'lib1.dart'; | 6644 import 'lib1.dart'; |
| 6645 import 'lib1.dart' hide A; | 6645 import 'lib1.dart' hide A; |
| 6646 A a; | 6646 A a; |
| 6647 B b;'''); | 6647 B b;'''); |
| 6648 addNamedSource("/lib1.dart", r''' | 6648 addNamedSource("/lib1.dart", r''' |
| 6649 library lib1; | 6649 library lib1; |
| 6650 class A {} | 6650 class A {} |
| 6651 class B {}'''); | 6651 class B {}'''); |
| 6652 resolve(source); | 6652 computeLibrarySourceErrors(source); |
| 6653 assertNoErrors(source); | 6653 assertNoErrors(source); |
| 6654 verify([source]); | 6654 verify([source]); |
| 6655 } | 6655 } |
| 6656 | 6656 |
| 6657 void test_duplicateImport_show() { | 6657 void test_duplicateImport_show() { |
| 6658 Source source = addSource(r''' | 6658 Source source = addSource(r''' |
| 6659 library L; | 6659 library L; |
| 6660 import 'lib1.dart'; | 6660 import 'lib1.dart'; |
| 6661 import 'lib1.dart' show A; | 6661 import 'lib1.dart' show A; |
| 6662 A a; | 6662 A a; |
| 6663 B b;'''); | 6663 B b;'''); |
| 6664 addNamedSource("/lib1.dart", r''' | 6664 addNamedSource("/lib1.dart", r''' |
| 6665 library lib1; | 6665 library lib1; |
| 6666 class A {} | 6666 class A {} |
| 6667 class B {}'''); | 6667 class B {}'''); |
| 6668 resolve(source); | 6668 computeLibrarySourceErrors(source); |
| 6669 assertNoErrors(source); | 6669 assertNoErrors(source); |
| 6670 verify([source]); | 6670 verify([source]); |
| 6671 } | 6671 } |
| 6672 | 6672 |
| 6673 void test_importDeferredLibraryWithLoadFunction() { | 6673 void test_importDeferredLibraryWithLoadFunction() { |
| 6674 resolveWithErrors(<String>[ | 6674 resolveWithErrors(<String>[ |
| 6675 r''' | 6675 r''' |
| 6676 library lib1; | 6676 library lib1; |
| 6677 f() {}''', | 6677 f() {}''', |
| 6678 r''' | 6678 r''' |
| 6679 library root; | 6679 library root; |
| 6680 import 'lib1.dart' deferred as lib1; | 6680 import 'lib1.dart' deferred as lib1; |
| 6681 main() { lib1.f(); }''' | 6681 main() { lib1.f(); }''' |
| 6682 ], ErrorCode.EMPTY_LIST); | 6682 ], ErrorCode.EMPTY_LIST); |
| 6683 } | 6683 } |
| 6684 | 6684 |
| 6685 void test_issue20904BuggyTypePromotionAtIfJoin_1() { | 6685 void test_issue20904BuggyTypePromotionAtIfJoin_1() { |
| 6686 // https://code.google.com/p/dart/issues/detail?id=20904 | 6686 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 6687 Source source = addSource(r''' | 6687 Source source = addSource(r''' |
| 6688 f(var message, var dynamic_) { | 6688 f(var message, var dynamic_) { |
| 6689 if (message is Function) { | 6689 if (message is Function) { |
| 6690 message = dynamic_; | 6690 message = dynamic_; |
| 6691 } | 6691 } |
| 6692 int s = message; | 6692 int s = message; |
| 6693 }'''); | 6693 }'''); |
| 6694 resolve(source); | 6694 computeLibrarySourceErrors(source); |
| 6695 assertNoErrors(source); | 6695 assertNoErrors(source); |
| 6696 verify([source]); | 6696 verify([source]); |
| 6697 } | 6697 } |
| 6698 | 6698 |
| 6699 void test_issue20904BuggyTypePromotionAtIfJoin_3() { | 6699 void test_issue20904BuggyTypePromotionAtIfJoin_3() { |
| 6700 // https://code.google.com/p/dart/issues/detail?id=20904 | 6700 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 6701 Source source = addSource(r''' | 6701 Source source = addSource(r''' |
| 6702 f(var message) { | 6702 f(var message) { |
| 6703 var dynamic_; | 6703 var dynamic_; |
| 6704 if (message is Function) { | 6704 if (message is Function) { |
| 6705 message = dynamic_; | 6705 message = dynamic_; |
| 6706 } else { | 6706 } else { |
| 6707 return; | 6707 return; |
| 6708 } | 6708 } |
| 6709 int s = message; | 6709 int s = message; |
| 6710 }'''); | 6710 }'''); |
| 6711 resolve(source); | 6711 computeLibrarySourceErrors(source); |
| 6712 assertNoErrors(source); | 6712 assertNoErrors(source); |
| 6713 verify([source]); | 6713 verify([source]); |
| 6714 } | 6714 } |
| 6715 | 6715 |
| 6716 void test_issue20904BuggyTypePromotionAtIfJoin_4() { | 6716 void test_issue20904BuggyTypePromotionAtIfJoin_4() { |
| 6717 // https://code.google.com/p/dart/issues/detail?id=20904 | 6717 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 6718 Source source = addSource(r''' | 6718 Source source = addSource(r''' |
| 6719 f(var message) { | 6719 f(var message) { |
| 6720 if (message is Function) { | 6720 if (message is Function) { |
| 6721 message = ''; | 6721 message = ''; |
| 6722 } else { | 6722 } else { |
| 6723 return; | 6723 return; |
| 6724 } | 6724 } |
| 6725 String s = message; | 6725 String s = message; |
| 6726 }'''); | 6726 }'''); |
| 6727 resolve(source); | 6727 computeLibrarySourceErrors(source); |
| 6728 assertNoErrors(source); | 6728 assertNoErrors(source); |
| 6729 verify([source]); | 6729 verify([source]); |
| 6730 } | 6730 } |
| 6731 | 6731 |
| 6732 void test_missingReturn_emptyFunctionBody() { | 6732 void test_missingReturn_emptyFunctionBody() { |
| 6733 Source source = addSource(r''' | 6733 Source source = addSource(r''' |
| 6734 abstract class A { | 6734 abstract class A { |
| 6735 int m(); | 6735 int m(); |
| 6736 }'''); | 6736 }'''); |
| 6737 resolve(source); | 6737 computeLibrarySourceErrors(source); |
| 6738 assertNoErrors(source); | 6738 assertNoErrors(source); |
| 6739 verify([source]); | 6739 verify([source]); |
| 6740 } | 6740 } |
| 6741 | 6741 |
| 6742 void test_missingReturn_expressionFunctionBody() { | 6742 void test_missingReturn_expressionFunctionBody() { |
| 6743 Source source = addSource("int f() => 0;"); | 6743 Source source = addSource("int f() => 0;"); |
| 6744 resolve(source); | 6744 computeLibrarySourceErrors(source); |
| 6745 assertNoErrors(source); | 6745 assertNoErrors(source); |
| 6746 verify([source]); | 6746 verify([source]); |
| 6747 } | 6747 } |
| 6748 | 6748 |
| 6749 void test_missingReturn_noReturnType() { | 6749 void test_missingReturn_noReturnType() { |
| 6750 Source source = addSource("f() {}"); | 6750 Source source = addSource("f() {}"); |
| 6751 resolve(source); | 6751 computeLibrarySourceErrors(source); |
| 6752 assertNoErrors(source); | 6752 assertNoErrors(source); |
| 6753 verify([source]); | 6753 verify([source]); |
| 6754 } | 6754 } |
| 6755 | 6755 |
| 6756 void test_missingReturn_voidReturnType() { | 6756 void test_missingReturn_voidReturnType() { |
| 6757 Source source = addSource("void f() {}"); | 6757 Source source = addSource("void f() {}"); |
| 6758 resolve(source); | 6758 computeLibrarySourceErrors(source); |
| 6759 assertNoErrors(source); | 6759 assertNoErrors(source); |
| 6760 verify([source]); | 6760 verify([source]); |
| 6761 } | 6761 } |
| 6762 | 6762 |
| 6763 void test_overrideEqualsButNotHashCode() { | 6763 void test_overrideEqualsButNotHashCode() { |
| 6764 Source source = addSource(r''' | 6764 Source source = addSource(r''' |
| 6765 class A { | 6765 class A { |
| 6766 bool operator ==(x) { return x; } | 6766 bool operator ==(x) { return x; } |
| 6767 get hashCode => 0; | 6767 get hashCode => 0; |
| 6768 }'''); | 6768 }'''); |
| 6769 resolve(source); | 6769 computeLibrarySourceErrors(source); |
| 6770 assertNoErrors(source); | 6770 assertNoErrors(source); |
| 6771 verify([source]); | 6771 verify([source]); |
| 6772 } | 6772 } |
| 6773 | 6773 |
| 6774 void test_overrideOnNonOverridingGetter_inInterface() { | 6774 void test_overrideOnNonOverridingGetter_inInterface() { |
| 6775 Source source = addSource(r''' | 6775 Source source = addSource(r''' |
| 6776 library dart.core; | 6776 library dart.core; |
| 6777 const override = null; | 6777 const override = null; |
| 6778 class A { | 6778 class A { |
| 6779 int get m => 0; | 6779 int get m => 0; |
| 6780 } | 6780 } |
| 6781 class B implements A { | 6781 class B implements A { |
| 6782 @override | 6782 @override |
| 6783 int get m => 1; | 6783 int get m => 1; |
| 6784 }'''); | 6784 }'''); |
| 6785 resolve(source); | 6785 computeLibrarySourceErrors(source); |
| 6786 assertNoErrors(source); | 6786 assertNoErrors(source); |
| 6787 verify([source]); | 6787 verify([source]); |
| 6788 } | 6788 } |
| 6789 | 6789 |
| 6790 void test_overrideOnNonOverridingGetter_inSuperclass() { | 6790 void test_overrideOnNonOverridingGetter_inSuperclass() { |
| 6791 Source source = addSource(r''' | 6791 Source source = addSource(r''' |
| 6792 library dart.core; | 6792 library dart.core; |
| 6793 const override = null; | 6793 const override = null; |
| 6794 class A { | 6794 class A { |
| 6795 int get m => 0; | 6795 int get m => 0; |
| 6796 } | 6796 } |
| 6797 class B extends A { | 6797 class B extends A { |
| 6798 @override | 6798 @override |
| 6799 int get m => 1; | 6799 int get m => 1; |
| 6800 }'''); | 6800 }'''); |
| 6801 resolve(source); | 6801 computeLibrarySourceErrors(source); |
| 6802 assertNoErrors(source); | 6802 assertNoErrors(source); |
| 6803 verify([source]); | 6803 verify([source]); |
| 6804 } | 6804 } |
| 6805 | 6805 |
| 6806 void test_overrideOnNonOverridingMethod_inInterface() { | 6806 void test_overrideOnNonOverridingMethod_inInterface() { |
| 6807 Source source = addSource(r''' | 6807 Source source = addSource(r''' |
| 6808 library dart.core; | 6808 library dart.core; |
| 6809 const override = null; | 6809 const override = null; |
| 6810 class A { | 6810 class A { |
| 6811 int m() => 0; | 6811 int m() => 0; |
| 6812 } | 6812 } |
| 6813 class B implements A { | 6813 class B implements A { |
| 6814 @override | 6814 @override |
| 6815 int m() => 1; | 6815 int m() => 1; |
| 6816 }'''); | 6816 }'''); |
| 6817 resolve(source); | 6817 computeLibrarySourceErrors(source); |
| 6818 assertNoErrors(source); | 6818 assertNoErrors(source); |
| 6819 verify([source]); | 6819 verify([source]); |
| 6820 } | 6820 } |
| 6821 | 6821 |
| 6822 void test_overrideOnNonOverridingMethod_inSuperclass() { | 6822 void test_overrideOnNonOverridingMethod_inSuperclass() { |
| 6823 Source source = addSource(r''' | 6823 Source source = addSource(r''' |
| 6824 library dart.core; | 6824 library dart.core; |
| 6825 const override = null; | 6825 const override = null; |
| 6826 class A { | 6826 class A { |
| 6827 int m() => 0; | 6827 int m() => 0; |
| 6828 } | 6828 } |
| 6829 class B extends A { | 6829 class B extends A { |
| 6830 @override | 6830 @override |
| 6831 int m() => 1; | 6831 int m() => 1; |
| 6832 }'''); | 6832 }'''); |
| 6833 resolve(source); | 6833 computeLibrarySourceErrors(source); |
| 6834 assertNoErrors(source); | 6834 assertNoErrors(source); |
| 6835 verify([source]); | 6835 verify([source]); |
| 6836 } | 6836 } |
| 6837 | 6837 |
| 6838 void test_overrideOnNonOverridingSetter_inInterface() { | 6838 void test_overrideOnNonOverridingSetter_inInterface() { |
| 6839 Source source = addSource(r''' | 6839 Source source = addSource(r''' |
| 6840 library dart.core; | 6840 library dart.core; |
| 6841 const override = null; | 6841 const override = null; |
| 6842 class A { | 6842 class A { |
| 6843 set m(int x) {} | 6843 set m(int x) {} |
| 6844 } | 6844 } |
| 6845 class B implements A { | 6845 class B implements A { |
| 6846 @override | 6846 @override |
| 6847 set m(int x) {} | 6847 set m(int x) {} |
| 6848 }'''); | 6848 }'''); |
| 6849 resolve(source); | 6849 computeLibrarySourceErrors(source); |
| 6850 assertNoErrors(source); | 6850 assertNoErrors(source); |
| 6851 verify([source]); | 6851 verify([source]); |
| 6852 } | 6852 } |
| 6853 | 6853 |
| 6854 void test_overrideOnNonOverridingSetter_inSuperclass() { | 6854 void test_overrideOnNonOverridingSetter_inSuperclass() { |
| 6855 Source source = addSource(r''' | 6855 Source source = addSource(r''' |
| 6856 library dart.core; | 6856 library dart.core; |
| 6857 const override = null; | 6857 const override = null; |
| 6858 class A { | 6858 class A { |
| 6859 set m(int x) {} | 6859 set m(int x) {} |
| 6860 } | 6860 } |
| 6861 class B extends A { | 6861 class B extends A { |
| 6862 @override | 6862 @override |
| 6863 set m(int x) {} | 6863 set m(int x) {} |
| 6864 }'''); | 6864 }'''); |
| 6865 resolve(source); | 6865 computeLibrarySourceErrors(source); |
| 6866 assertNoErrors(source); | 6866 assertNoErrors(source); |
| 6867 verify([source]); | 6867 verify([source]); |
| 6868 } | 6868 } |
| 6869 | 6869 |
| 6870 void test_propagatedFieldType() { | 6870 void test_propagatedFieldType() { |
| 6871 Source source = addSource(r''' | 6871 Source source = addSource(r''' |
| 6872 class A { } | 6872 class A { } |
| 6873 class X<T> { | 6873 class X<T> { |
| 6874 final x = new List<T>(); | 6874 final x = new List<T>(); |
| 6875 } | 6875 } |
| 6876 class Z { | 6876 class Z { |
| 6877 final X<A> y = new X<A>(); | 6877 final X<A> y = new X<A>(); |
| 6878 foo() { | 6878 foo() { |
| 6879 y.x.add(new A()); | 6879 y.x.add(new A()); |
| 6880 } | 6880 } |
| 6881 }'''); | 6881 }'''); |
| 6882 resolve(source); | 6882 computeLibrarySourceErrors(source); |
| 6883 assertNoErrors(source); | 6883 assertNoErrors(source); |
| 6884 verify([source]); | 6884 verify([source]); |
| 6885 } | 6885 } |
| 6886 | 6886 |
| 6887 void test_proxy_annotation_prefixed() { | 6887 void test_proxy_annotation_prefixed() { |
| 6888 Source source = addSource(r''' | 6888 Source source = addSource(r''' |
| 6889 library L; | 6889 library L; |
| 6890 @proxy | 6890 @proxy |
| 6891 class A {} | 6891 class A {} |
| 6892 f(var a) { | 6892 f(var a) { |
| 6893 a = new A(); | 6893 a = new A(); |
| 6894 a.m(); | 6894 a.m(); |
| 6895 var x = a.g; | 6895 var x = a.g; |
| 6896 a.s = 1; | 6896 a.s = 1; |
| 6897 var y = a + a; | 6897 var y = a + a; |
| 6898 a++; | 6898 a++; |
| 6899 ++a; | 6899 ++a; |
| 6900 }'''); | 6900 }'''); |
| 6901 resolve(source); | 6901 computeLibrarySourceErrors(source); |
| 6902 assertNoErrors(source); | 6902 assertNoErrors(source); |
| 6903 } | 6903 } |
| 6904 | 6904 |
| 6905 void test_proxy_annotation_prefixed2() { | 6905 void test_proxy_annotation_prefixed2() { |
| 6906 Source source = addSource(r''' | 6906 Source source = addSource(r''' |
| 6907 library L; | 6907 library L; |
| 6908 @proxy | 6908 @proxy |
| 6909 class A {} | 6909 class A {} |
| 6910 class B { | 6910 class B { |
| 6911 f(var a) { | 6911 f(var a) { |
| 6912 a = new A(); | 6912 a = new A(); |
| 6913 a.m(); | 6913 a.m(); |
| 6914 var x = a.g; | 6914 var x = a.g; |
| 6915 a.s = 1; | 6915 a.s = 1; |
| 6916 var y = a + a; | 6916 var y = a + a; |
| 6917 a++; | 6917 a++; |
| 6918 ++a; | 6918 ++a; |
| 6919 } | 6919 } |
| 6920 }'''); | 6920 }'''); |
| 6921 resolve(source); | 6921 computeLibrarySourceErrors(source); |
| 6922 assertNoErrors(source); | 6922 assertNoErrors(source); |
| 6923 } | 6923 } |
| 6924 | 6924 |
| 6925 void test_proxy_annotation_prefixed3() { | 6925 void test_proxy_annotation_prefixed3() { |
| 6926 Source source = addSource(r''' | 6926 Source source = addSource(r''' |
| 6927 library L; | 6927 library L; |
| 6928 class B { | 6928 class B { |
| 6929 f(var a) { | 6929 f(var a) { |
| 6930 a = new A(); | 6930 a = new A(); |
| 6931 a.m(); | 6931 a.m(); |
| 6932 var x = a.g; | 6932 var x = a.g; |
| 6933 a.s = 1; | 6933 a.s = 1; |
| 6934 var y = a + a; | 6934 var y = a + a; |
| 6935 a++; | 6935 a++; |
| 6936 ++a; | 6936 ++a; |
| 6937 } | 6937 } |
| 6938 } | 6938 } |
| 6939 @proxy | 6939 @proxy |
| 6940 class A {}'''); | 6940 class A {}'''); |
| 6941 resolve(source); | 6941 computeLibrarySourceErrors(source); |
| 6942 assertNoErrors(source); | 6942 assertNoErrors(source); |
| 6943 } | 6943 } |
| 6944 | 6944 |
| 6945 void test_undefinedGetter_inSubtype() { | 6945 void test_undefinedGetter_inSubtype() { |
| 6946 Source source = addSource(r''' | 6946 Source source = addSource(r''' |
| 6947 class A {} | 6947 class A {} |
| 6948 class B extends A { | 6948 class B extends A { |
| 6949 get b => 0; | 6949 get b => 0; |
| 6950 } | 6950 } |
| 6951 f(var a) { | 6951 f(var a) { |
| 6952 if(a is A) { | 6952 if(a is A) { |
| 6953 return a.b; | 6953 return a.b; |
| 6954 } | 6954 } |
| 6955 }'''); | 6955 }'''); |
| 6956 resolve(source); | 6956 computeLibrarySourceErrors(source); |
| 6957 assertNoErrors(source); | 6957 assertNoErrors(source); |
| 6958 } | 6958 } |
| 6959 | 6959 |
| 6960 void test_undefinedMethod_assignmentExpression_inSubtype() { | 6960 void test_undefinedMethod_assignmentExpression_inSubtype() { |
| 6961 Source source = addSource(r''' | 6961 Source source = addSource(r''' |
| 6962 class A {} | 6962 class A {} |
| 6963 class B extends A { | 6963 class B extends A { |
| 6964 operator +(B b) {return new B();} | 6964 operator +(B b) {return new B();} |
| 6965 } | 6965 } |
| 6966 f(var a, var a2) { | 6966 f(var a, var a2) { |
| 6967 a = new A(); | 6967 a = new A(); |
| 6968 a2 = new A(); | 6968 a2 = new A(); |
| 6969 a += a2; | 6969 a += a2; |
| 6970 }'''); | 6970 }'''); |
| 6971 resolve(source); | 6971 computeLibrarySourceErrors(source); |
| 6972 assertNoErrors(source); | 6972 assertNoErrors(source); |
| 6973 } | 6973 } |
| 6974 | 6974 |
| 6975 void test_undefinedMethod_dynamic() { | 6975 void test_undefinedMethod_dynamic() { |
| 6976 Source source = addSource(r''' | 6976 Source source = addSource(r''' |
| 6977 class D<T extends dynamic> { | 6977 class D<T extends dynamic> { |
| 6978 fieldAccess(T t) => t.abc; | 6978 fieldAccess(T t) => t.abc; |
| 6979 methodAccess(T t) => t.xyz(1, 2, 'three'); | 6979 methodAccess(T t) => t.xyz(1, 2, 'three'); |
| 6980 }'''); | 6980 }'''); |
| 6981 resolve(source); | 6981 computeLibrarySourceErrors(source); |
| 6982 assertNoErrors(source); | 6982 assertNoErrors(source); |
| 6983 } | 6983 } |
| 6984 | 6984 |
| 6985 void test_undefinedMethod_inSubtype() { | 6985 void test_undefinedMethod_inSubtype() { |
| 6986 Source source = addSource(r''' | 6986 Source source = addSource(r''' |
| 6987 class A {} | 6987 class A {} |
| 6988 class B extends A { | 6988 class B extends A { |
| 6989 b() {} | 6989 b() {} |
| 6990 } | 6990 } |
| 6991 f() { | 6991 f() { |
| 6992 var a = new A(); | 6992 var a = new A(); |
| 6993 a.b(); | 6993 a.b(); |
| 6994 }'''); | 6994 }'''); |
| 6995 resolve(source); | 6995 computeLibrarySourceErrors(source); |
| 6996 assertNoErrors(source); | 6996 assertNoErrors(source); |
| 6997 } | 6997 } |
| 6998 | 6998 |
| 6999 void test_undefinedMethod_unionType_all() { | 6999 void test_undefinedMethod_unionType_all() { |
| 7000 Source source = addSource(r''' | 7000 Source source = addSource(r''' |
| 7001 class A { | 7001 class A { |
| 7002 int m(int x) => 0; | 7002 int m(int x) => 0; |
| 7003 } | 7003 } |
| 7004 class B { | 7004 class B { |
| 7005 String m() => '0'; | 7005 String m() => '0'; |
| 7006 } | 7006 } |
| 7007 f(A a, B b) { | 7007 f(A a, B b) { |
| 7008 var ab; | 7008 var ab; |
| 7009 if (0 < 1) { | 7009 if (0 < 1) { |
| 7010 ab = a; | 7010 ab = a; |
| 7011 } else { | 7011 } else { |
| 7012 ab = b; | 7012 ab = b; |
| 7013 } | 7013 } |
| 7014 ab.m(); | 7014 ab.m(); |
| 7015 }'''); | 7015 }'''); |
| 7016 resolve(source); | 7016 computeLibrarySourceErrors(source); |
| 7017 assertNoErrors(source); | 7017 assertNoErrors(source); |
| 7018 } | 7018 } |
| 7019 | 7019 |
| 7020 void test_undefinedMethod_unionType_some() { | 7020 void test_undefinedMethod_unionType_some() { |
| 7021 Source source = addSource(r''' | 7021 Source source = addSource(r''' |
| 7022 class A { | 7022 class A { |
| 7023 int m(int x) => 0; | 7023 int m(int x) => 0; |
| 7024 } | 7024 } |
| 7025 class B {} | 7025 class B {} |
| 7026 f(A a, B b) { | 7026 f(A a, B b) { |
| 7027 var ab; | 7027 var ab; |
| 7028 if (0 < 1) { | 7028 if (0 < 1) { |
| 7029 ab = a; | 7029 ab = a; |
| 7030 } else { | 7030 } else { |
| 7031 ab = b; | 7031 ab = b; |
| 7032 } | 7032 } |
| 7033 ab.m(0); | 7033 ab.m(0); |
| 7034 }'''); | 7034 }'''); |
| 7035 resolve(source); | 7035 computeLibrarySourceErrors(source); |
| 7036 assertNoErrors(source); | 7036 assertNoErrors(source); |
| 7037 } | 7037 } |
| 7038 | 7038 |
| 7039 void test_undefinedOperator_binaryExpression_inSubtype() { | 7039 void test_undefinedOperator_binaryExpression_inSubtype() { |
| 7040 Source source = addSource(r''' | 7040 Source source = addSource(r''' |
| 7041 class A {} | 7041 class A {} |
| 7042 class B extends A { | 7042 class B extends A { |
| 7043 operator +(B b) {} | 7043 operator +(B b) {} |
| 7044 } | 7044 } |
| 7045 f(var a) { | 7045 f(var a) { |
| 7046 if(a is A) { | 7046 if(a is A) { |
| 7047 a + 1; | 7047 a + 1; |
| 7048 } | 7048 } |
| 7049 }'''); | 7049 }'''); |
| 7050 resolve(source); | 7050 computeLibrarySourceErrors(source); |
| 7051 assertNoErrors(source); | 7051 assertNoErrors(source); |
| 7052 } | 7052 } |
| 7053 | 7053 |
| 7054 void test_undefinedOperator_indexBoth_inSubtype() { | 7054 void test_undefinedOperator_indexBoth_inSubtype() { |
| 7055 Source source = addSource(r''' | 7055 Source source = addSource(r''' |
| 7056 class A {} | 7056 class A {} |
| 7057 class B extends A { | 7057 class B extends A { |
| 7058 operator [](int index) {} | 7058 operator [](int index) {} |
| 7059 } | 7059 } |
| 7060 f(var a) { | 7060 f(var a) { |
| 7061 if(a is A) { | 7061 if(a is A) { |
| 7062 a[0]++; | 7062 a[0]++; |
| 7063 } | 7063 } |
| 7064 }'''); | 7064 }'''); |
| 7065 resolve(source); | 7065 computeLibrarySourceErrors(source); |
| 7066 assertNoErrors(source); | 7066 assertNoErrors(source); |
| 7067 } | 7067 } |
| 7068 | 7068 |
| 7069 void test_undefinedOperator_indexGetter_inSubtype() { | 7069 void test_undefinedOperator_indexGetter_inSubtype() { |
| 7070 Source source = addSource(r''' | 7070 Source source = addSource(r''' |
| 7071 class A {} | 7071 class A {} |
| 7072 class B extends A { | 7072 class B extends A { |
| 7073 operator [](int index) {} | 7073 operator [](int index) {} |
| 7074 } | 7074 } |
| 7075 f(var a) { | 7075 f(var a) { |
| 7076 if(a is A) { | 7076 if(a is A) { |
| 7077 a[0]; | 7077 a[0]; |
| 7078 } | 7078 } |
| 7079 }'''); | 7079 }'''); |
| 7080 resolve(source); | 7080 computeLibrarySourceErrors(source); |
| 7081 assertNoErrors(source); | 7081 assertNoErrors(source); |
| 7082 } | 7082 } |
| 7083 | 7083 |
| 7084 void test_undefinedOperator_indexSetter_inSubtype() { | 7084 void test_undefinedOperator_indexSetter_inSubtype() { |
| 7085 Source source = addSource(r''' | 7085 Source source = addSource(r''' |
| 7086 class A {} | 7086 class A {} |
| 7087 class B extends A { | 7087 class B extends A { |
| 7088 operator []=(i, v) {} | 7088 operator []=(i, v) {} |
| 7089 } | 7089 } |
| 7090 f(var a) { | 7090 f(var a) { |
| 7091 if(a is A) { | 7091 if(a is A) { |
| 7092 a[0] = 1; | 7092 a[0] = 1; |
| 7093 } | 7093 } |
| 7094 }'''); | 7094 }'''); |
| 7095 resolve(source); | 7095 computeLibrarySourceErrors(source); |
| 7096 assertNoErrors(source); | 7096 assertNoErrors(source); |
| 7097 } | 7097 } |
| 7098 | 7098 |
| 7099 void test_undefinedOperator_postfixExpression() { | 7099 void test_undefinedOperator_postfixExpression() { |
| 7100 Source source = addSource(r''' | 7100 Source source = addSource(r''' |
| 7101 class A {} | 7101 class A {} |
| 7102 class B extends A { | 7102 class B extends A { |
| 7103 operator +(B b) {return new B();} | 7103 operator +(B b) {return new B();} |
| 7104 } | 7104 } |
| 7105 f(var a) { | 7105 f(var a) { |
| 7106 if(a is A) { | 7106 if(a is A) { |
| 7107 a++; | 7107 a++; |
| 7108 } | 7108 } |
| 7109 }'''); | 7109 }'''); |
| 7110 resolve(source); | 7110 computeLibrarySourceErrors(source); |
| 7111 assertNoErrors(source); | 7111 assertNoErrors(source); |
| 7112 } | 7112 } |
| 7113 | 7113 |
| 7114 void test_undefinedOperator_prefixExpression() { | 7114 void test_undefinedOperator_prefixExpression() { |
| 7115 Source source = addSource(r''' | 7115 Source source = addSource(r''' |
| 7116 class A {} | 7116 class A {} |
| 7117 class B extends A { | 7117 class B extends A { |
| 7118 operator +(B b) {return new B();} | 7118 operator +(B b) {return new B();} |
| 7119 } | 7119 } |
| 7120 f(var a) { | 7120 f(var a) { |
| 7121 if(a is A) { | 7121 if(a is A) { |
| 7122 ++a; | 7122 ++a; |
| 7123 } | 7123 } |
| 7124 }'''); | 7124 }'''); |
| 7125 resolve(source); | 7125 computeLibrarySourceErrors(source); |
| 7126 assertNoErrors(source); | 7126 assertNoErrors(source); |
| 7127 } | 7127 } |
| 7128 | 7128 |
| 7129 void test_undefinedSetter_inSubtype() { | 7129 void test_undefinedSetter_inSubtype() { |
| 7130 Source source = addSource(r''' | 7130 Source source = addSource(r''' |
| 7131 class A {} | 7131 class A {} |
| 7132 class B extends A { | 7132 class B extends A { |
| 7133 set b(x) {} | 7133 set b(x) {} |
| 7134 } | 7134 } |
| 7135 f(var a) { | 7135 f(var a) { |
| 7136 if(a is A) { | 7136 if(a is A) { |
| 7137 a.b = 0; | 7137 a.b = 0; |
| 7138 } | 7138 } |
| 7139 }'''); | 7139 }'''); |
| 7140 resolve(source); | 7140 computeLibrarySourceErrors(source); |
| 7141 assertNoErrors(source); | 7141 assertNoErrors(source); |
| 7142 } | 7142 } |
| 7143 | 7143 |
| 7144 void test_unnecessaryCast_13855_parameter_A() { | 7144 void test_unnecessaryCast_13855_parameter_A() { |
| 7145 // dartbug.com/13855, dartbug.com/13732 | 7145 // dartbug.com/13855, dartbug.com/13732 |
| 7146 Source source = addSource(r''' | 7146 Source source = addSource(r''' |
| 7147 class A{ | 7147 class A{ |
| 7148 a() {} | 7148 a() {} |
| 7149 } | 7149 } |
| 7150 class B<E> { | 7150 class B<E> { |
| 7151 E e; | 7151 E e; |
| 7152 m() { | 7152 m() { |
| 7153 (e as A).a(); | 7153 (e as A).a(); |
| 7154 } | 7154 } |
| 7155 }'''); | 7155 }'''); |
| 7156 resolve(source); | 7156 computeLibrarySourceErrors(source); |
| 7157 assertNoErrors(source); | 7157 assertNoErrors(source); |
| 7158 verify([source]); | 7158 verify([source]); |
| 7159 } | 7159 } |
| 7160 | 7160 |
| 7161 void test_unnecessaryCast_conditionalExpression() { | 7161 void test_unnecessaryCast_conditionalExpression() { |
| 7162 Source source = addSource(r''' | 7162 Source source = addSource(r''' |
| 7163 abstract class I {} | 7163 abstract class I {} |
| 7164 class A implements I {} | 7164 class A implements I {} |
| 7165 class B implements I {} | 7165 class B implements I {} |
| 7166 I m(A a, B b) { | 7166 I m(A a, B b) { |
| 7167 return a == null ? b as I : a as I; | 7167 return a == null ? b as I : a as I; |
| 7168 }'''); | 7168 }'''); |
| 7169 resolve(source); | 7169 computeLibrarySourceErrors(source); |
| 7170 assertNoErrors(source); | 7170 assertNoErrors(source); |
| 7171 verify([source]); | 7171 verify([source]); |
| 7172 } | 7172 } |
| 7173 | 7173 |
| 7174 void test_unnecessaryCast_dynamic_type() { | 7174 void test_unnecessaryCast_dynamic_type() { |
| 7175 Source source = addSource(r''' | 7175 Source source = addSource(r''' |
| 7176 m(v) { | 7176 m(v) { |
| 7177 var b = v as Object; | 7177 var b = v as Object; |
| 7178 }'''); | 7178 }'''); |
| 7179 resolve(source); | 7179 computeLibrarySourceErrors(source); |
| 7180 assertNoErrors(source); | 7180 assertNoErrors(source); |
| 7181 verify([source]); | 7181 verify([source]); |
| 7182 } | 7182 } |
| 7183 | 7183 |
| 7184 void test_unnecessaryCast_generics() { | 7184 void test_unnecessaryCast_generics() { |
| 7185 // dartbug.com/18953 | 7185 // dartbug.com/18953 |
| 7186 Source source = addSource(r''' | 7186 Source source = addSource(r''' |
| 7187 import 'dart:async'; | 7187 import 'dart:async'; |
| 7188 Future<int> f() => new Future.value(0); | 7188 Future<int> f() => new Future.value(0); |
| 7189 void g(bool c) { | 7189 void g(bool c) { |
| 7190 (c ? f(): new Future.value(0) as Future<int>).then((int value) {}); | 7190 (c ? f(): new Future.value(0) as Future<int>).then((int value) {}); |
| 7191 }'''); | 7191 }'''); |
| 7192 resolve(source); | 7192 computeLibrarySourceErrors(source); |
| 7193 assertNoErrors(source); | 7193 assertNoErrors(source); |
| 7194 verify([source]); | 7194 verify([source]); |
| 7195 } | 7195 } |
| 7196 | 7196 |
| 7197 void test_unnecessaryCast_type_dynamic() { | 7197 void test_unnecessaryCast_type_dynamic() { |
| 7198 Source source = addSource(r''' | 7198 Source source = addSource(r''' |
| 7199 m(v) { | 7199 m(v) { |
| 7200 var b = Object as dynamic; | 7200 var b = Object as dynamic; |
| 7201 }'''); | 7201 }'''); |
| 7202 resolve(source); | 7202 computeLibrarySourceErrors(source); |
| 7203 assertNoErrors(source); | 7203 assertNoErrors(source); |
| 7204 verify([source]); | 7204 verify([source]); |
| 7205 } | 7205 } |
| 7206 | 7206 |
| 7207 void test_unusedImport_annotationOnDirective() { | 7207 void test_unusedImport_annotationOnDirective() { |
| 7208 Source source = addSource(r''' | 7208 Source source = addSource(r''' |
| 7209 library L; | 7209 library L; |
| 7210 @A() | 7210 @A() |
| 7211 import 'lib1.dart';'''); | 7211 import 'lib1.dart';'''); |
| 7212 Source source2 = addNamedSource("/lib1.dart", r''' | 7212 Source source2 = addNamedSource("/lib1.dart", r''' |
| 7213 library lib1; | 7213 library lib1; |
| 7214 class A { | 7214 class A { |
| 7215 const A() {} | 7215 const A() {} |
| 7216 }'''); | 7216 }'''); |
| 7217 resolve(source); | 7217 computeLibrarySourceErrors(source); |
| 7218 assertErrors(source); | 7218 assertErrors(source); |
| 7219 verify([source, source2]); | 7219 verify([source, source2]); |
| 7220 } | 7220 } |
| 7221 | 7221 |
| 7222 void test_unusedImport_as_equalPrefixes() { | 7222 void test_unusedImport_as_equalPrefixes() { |
| 7223 // 18818 | 7223 // 18818 |
| 7224 Source source = addSource(r''' | 7224 Source source = addSource(r''' |
| 7225 library L; | 7225 library L; |
| 7226 import 'lib1.dart' as one; | 7226 import 'lib1.dart' as one; |
| 7227 import 'lib2.dart' as one; | 7227 import 'lib2.dart' as one; |
| 7228 one.A a; | 7228 one.A a; |
| 7229 one.B b;'''); | 7229 one.B b;'''); |
| 7230 Source source2 = addNamedSource("/lib1.dart", r''' | 7230 Source source2 = addNamedSource("/lib1.dart", r''' |
| 7231 library lib1; | 7231 library lib1; |
| 7232 class A {}'''); | 7232 class A {}'''); |
| 7233 Source source3 = addNamedSource("/lib2.dart", r''' | 7233 Source source3 = addNamedSource("/lib2.dart", r''' |
| 7234 library lib2; | 7234 library lib2; |
| 7235 class B {}'''); | 7235 class B {}'''); |
| 7236 resolve(source); | 7236 computeLibrarySourceErrors(source); |
| 7237 assertErrors(source); | 7237 assertErrors(source); |
| 7238 assertNoErrors(source2); | 7238 assertNoErrors(source2); |
| 7239 assertNoErrors(source3); | 7239 assertNoErrors(source3); |
| 7240 verify([source, source2, source3]); | 7240 verify([source, source2, source3]); |
| 7241 } | 7241 } |
| 7242 | 7242 |
| 7243 void test_unusedImport_core_library() { | 7243 void test_unusedImport_core_library() { |
| 7244 Source source = addSource(r''' | 7244 Source source = addSource(r''' |
| 7245 library L; | 7245 library L; |
| 7246 import 'dart:core';'''); | 7246 import 'dart:core';'''); |
| 7247 resolve(source); | 7247 computeLibrarySourceErrors(source); |
| 7248 assertNoErrors(source); | 7248 assertNoErrors(source); |
| 7249 verify([source]); | 7249 verify([source]); |
| 7250 } | 7250 } |
| 7251 | 7251 |
| 7252 void test_unusedImport_export() { | 7252 void test_unusedImport_export() { |
| 7253 Source source = addSource(r''' | 7253 Source source = addSource(r''' |
| 7254 library L; | 7254 library L; |
| 7255 import 'lib1.dart'; | 7255 import 'lib1.dart'; |
| 7256 Two two;'''); | 7256 Two two;'''); |
| 7257 addNamedSource("/lib1.dart", r''' | 7257 addNamedSource("/lib1.dart", r''' |
| 7258 library lib1; | 7258 library lib1; |
| 7259 export 'lib2.dart'; | 7259 export 'lib2.dart'; |
| 7260 class One {}'''); | 7260 class One {}'''); |
| 7261 addNamedSource("/lib2.dart", r''' | 7261 addNamedSource("/lib2.dart", r''' |
| 7262 library lib2; | 7262 library lib2; |
| 7263 class Two {}'''); | 7263 class Two {}'''); |
| 7264 resolve(source); | 7264 computeLibrarySourceErrors(source); |
| 7265 assertNoErrors(source); | 7265 assertNoErrors(source); |
| 7266 verify([source]); | 7266 verify([source]); |
| 7267 } | 7267 } |
| 7268 | 7268 |
| 7269 void test_unusedImport_export2() { | 7269 void test_unusedImport_export2() { |
| 7270 Source source = addSource(r''' | 7270 Source source = addSource(r''' |
| 7271 library L; | 7271 library L; |
| 7272 import 'lib1.dart'; | 7272 import 'lib1.dart'; |
| 7273 Three three;'''); | 7273 Three three;'''); |
| 7274 addNamedSource("/lib1.dart", r''' | 7274 addNamedSource("/lib1.dart", r''' |
| 7275 library lib1; | 7275 library lib1; |
| 7276 export 'lib2.dart'; | 7276 export 'lib2.dart'; |
| 7277 class One {}'''); | 7277 class One {}'''); |
| 7278 addNamedSource("/lib2.dart", r''' | 7278 addNamedSource("/lib2.dart", r''' |
| 7279 library lib2; | 7279 library lib2; |
| 7280 export 'lib3.dart'; | 7280 export 'lib3.dart'; |
| 7281 class Two {}'''); | 7281 class Two {}'''); |
| 7282 addNamedSource("/lib3.dart", r''' | 7282 addNamedSource("/lib3.dart", r''' |
| 7283 library lib3; | 7283 library lib3; |
| 7284 class Three {}'''); | 7284 class Three {}'''); |
| 7285 resolve(source); | 7285 computeLibrarySourceErrors(source); |
| 7286 assertNoErrors(source); | 7286 assertNoErrors(source); |
| 7287 verify([source]); | 7287 verify([source]); |
| 7288 } | 7288 } |
| 7289 | 7289 |
| 7290 void test_unusedImport_export_infiniteLoop() { | 7290 void test_unusedImport_export_infiniteLoop() { |
| 7291 Source source = addSource(r''' | 7291 Source source = addSource(r''' |
| 7292 library L; | 7292 library L; |
| 7293 import 'lib1.dart'; | 7293 import 'lib1.dart'; |
| 7294 Two two;'''); | 7294 Two two;'''); |
| 7295 addNamedSource("/lib1.dart", r''' | 7295 addNamedSource("/lib1.dart", r''' |
| 7296 library lib1; | 7296 library lib1; |
| 7297 export 'lib2.dart'; | 7297 export 'lib2.dart'; |
| 7298 class One {}'''); | 7298 class One {}'''); |
| 7299 addNamedSource("/lib2.dart", r''' | 7299 addNamedSource("/lib2.dart", r''' |
| 7300 library lib2; | 7300 library lib2; |
| 7301 export 'lib3.dart'; | 7301 export 'lib3.dart'; |
| 7302 class Two {}'''); | 7302 class Two {}'''); |
| 7303 addNamedSource("/lib3.dart", r''' | 7303 addNamedSource("/lib3.dart", r''' |
| 7304 library lib3; | 7304 library lib3; |
| 7305 export 'lib2.dart'; | 7305 export 'lib2.dart'; |
| 7306 class Three {}'''); | 7306 class Three {}'''); |
| 7307 resolve(source); | 7307 computeLibrarySourceErrors(source); |
| 7308 assertNoErrors(source); | 7308 assertNoErrors(source); |
| 7309 verify([source]); | 7309 verify([source]); |
| 7310 } | 7310 } |
| 7311 | 7311 |
| 7312 void test_unusedImport_metadata() { | 7312 void test_unusedImport_metadata() { |
| 7313 Source source = addSource(r''' | 7313 Source source = addSource(r''' |
| 7314 library L; | 7314 library L; |
| 7315 @A(x) | 7315 @A(x) |
| 7316 import 'lib1.dart'; | 7316 import 'lib1.dart'; |
| 7317 class A { | 7317 class A { |
| 7318 final int value; | 7318 final int value; |
| 7319 const A(this.value); | 7319 const A(this.value); |
| 7320 }'''); | 7320 }'''); |
| 7321 addNamedSource("/lib1.dart", r''' | 7321 addNamedSource("/lib1.dart", r''' |
| 7322 library lib1; | 7322 library lib1; |
| 7323 const x = 0;'''); | 7323 const x = 0;'''); |
| 7324 resolve(source); | 7324 computeLibrarySourceErrors(source); |
| 7325 assertNoErrors(source); | 7325 assertNoErrors(source); |
| 7326 verify([source]); | 7326 verify([source]); |
| 7327 } | 7327 } |
| 7328 | 7328 |
| 7329 void test_unusedImport_prefix_topLevelFunction() { | 7329 void test_unusedImport_prefix_topLevelFunction() { |
| 7330 Source source = addSource(r''' | 7330 Source source = addSource(r''' |
| 7331 library L; | 7331 library L; |
| 7332 import 'lib1.dart' hide topLevelFunction; | 7332 import 'lib1.dart' hide topLevelFunction; |
| 7333 import 'lib1.dart' as one show topLevelFunction; | 7333 import 'lib1.dart' as one show topLevelFunction; |
| 7334 class A { | 7334 class A { |
| 7335 static void x() { | 7335 static void x() { |
| 7336 One o; | 7336 One o; |
| 7337 one.topLevelFunction(); | 7337 one.topLevelFunction(); |
| 7338 } | 7338 } |
| 7339 }'''); | 7339 }'''); |
| 7340 addNamedSource("/lib1.dart", r''' | 7340 addNamedSource("/lib1.dart", r''' |
| 7341 library lib1; | 7341 library lib1; |
| 7342 class One {} | 7342 class One {} |
| 7343 topLevelFunction() {}'''); | 7343 topLevelFunction() {}'''); |
| 7344 resolve(source); | 7344 computeLibrarySourceErrors(source); |
| 7345 assertNoErrors(source); | 7345 assertNoErrors(source); |
| 7346 verify([source]); | 7346 verify([source]); |
| 7347 } | 7347 } |
| 7348 | 7348 |
| 7349 void test_useOfVoidResult_implicitReturnValue() { | 7349 void test_useOfVoidResult_implicitReturnValue() { |
| 7350 Source source = addSource(r''' | 7350 Source source = addSource(r''' |
| 7351 f() {} | 7351 f() {} |
| 7352 class A { | 7352 class A { |
| 7353 n() { | 7353 n() { |
| 7354 var a = f(); | 7354 var a = f(); |
| 7355 } | 7355 } |
| 7356 }'''); | 7356 }'''); |
| 7357 resolve(source); | 7357 computeLibrarySourceErrors(source); |
| 7358 assertNoErrors(source); | 7358 assertNoErrors(source); |
| 7359 verify([source]); | 7359 verify([source]); |
| 7360 } | 7360 } |
| 7361 | 7361 |
| 7362 void test_useOfVoidResult_nonVoidReturnValue() { | 7362 void test_useOfVoidResult_nonVoidReturnValue() { |
| 7363 Source source = addSource(r''' | 7363 Source source = addSource(r''' |
| 7364 int f() => 1; | 7364 int f() => 1; |
| 7365 g() { | 7365 g() { |
| 7366 var a = f(); | 7366 var a = f(); |
| 7367 }'''); | 7367 }'''); |
| 7368 resolve(source); | 7368 computeLibrarySourceErrors(source); |
| 7369 assertNoErrors(source); | 7369 assertNoErrors(source); |
| 7370 verify([source]); | 7370 verify([source]); |
| 7371 } | 7371 } |
| 7372 } | 7372 } |
| 7373 | 7373 |
| 7374 class PubSuggestionCodeTest extends ResolverTestCase { | 7374 class PubSuggestionCodeTest extends ResolverTestCase { |
| 7375 void test_import_package() { | 7375 void test_import_package() { |
| 7376 Source source = addSource("import 'package:somepackage/other.dart';"); | 7376 Source source = addSource("import 'package:somepackage/other.dart';"); |
| 7377 resolve(source); | 7377 computeLibrarySourceErrors(source); |
| 7378 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 7378 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 7379 } | 7379 } |
| 7380 | 7380 |
| 7381 void test_import_packageWithDotDot() { | 7381 void test_import_packageWithDotDot() { |
| 7382 Source source = addSource("import 'package:somepackage/../other.dart';"); | 7382 Source source = addSource("import 'package:somepackage/../other.dart';"); |
| 7383 resolve(source); | 7383 computeLibrarySourceErrors(source); |
| 7384 assertErrors(source, [ | 7384 assertErrors(source, [ |
| 7385 CompileTimeErrorCode.URI_DOES_NOT_EXIST, | 7385 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 7386 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT | 7386 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT |
| 7387 ]); | 7387 ]); |
| 7388 } | 7388 } |
| 7389 | 7389 |
| 7390 void test_import_packageWithLeadingDotDot() { | 7390 void test_import_packageWithLeadingDotDot() { |
| 7391 Source source = addSource("import 'package:../other.dart';"); | 7391 Source source = addSource("import 'package:../other.dart';"); |
| 7392 resolve(source); | 7392 computeLibrarySourceErrors(source); |
| 7393 assertErrors(source, [ | 7393 assertErrors(source, [ |
| 7394 CompileTimeErrorCode.URI_DOES_NOT_EXIST, | 7394 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 7395 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT | 7395 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT |
| 7396 ]); | 7396 ]); |
| 7397 } | 7397 } |
| 7398 | 7398 |
| 7399 void test_import_referenceIntoLibDirectory() { | 7399 void test_import_referenceIntoLibDirectory() { |
| 7400 cacheSource("/myproj/pubspec.yaml", ""); | 7400 cacheSource("/myproj/pubspec.yaml", ""); |
| 7401 cacheSource("/myproj/lib/other.dart", ""); | 7401 cacheSource("/myproj/lib/other.dart", ""); |
| 7402 Source source = | 7402 Source source = |
| 7403 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); | 7403 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); |
| 7404 resolve(source); | 7404 computeLibrarySourceErrors(source); |
| 7405 assertErrors( | 7405 assertErrors( |
| 7406 source, [HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE]); | 7406 source, [HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE]); |
| 7407 } | 7407 } |
| 7408 | 7408 |
| 7409 void test_import_referenceIntoLibDirectory_no_pubspec() { | 7409 void test_import_referenceIntoLibDirectory_no_pubspec() { |
| 7410 cacheSource("/myproj/lib/other.dart", ""); | 7410 cacheSource("/myproj/lib/other.dart", ""); |
| 7411 Source source = | 7411 Source source = |
| 7412 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); | 7412 addNamedSource("/myproj/web/test.dart", "import '../lib/other.dart';"); |
| 7413 resolve(source); | 7413 computeLibrarySourceErrors(source); |
| 7414 assertNoErrors(source); | 7414 assertNoErrors(source); |
| 7415 } | 7415 } |
| 7416 | 7416 |
| 7417 void test_import_referenceOutOfLibDirectory() { | 7417 void test_import_referenceOutOfLibDirectory() { |
| 7418 cacheSource("/myproj/pubspec.yaml", ""); | 7418 cacheSource("/myproj/pubspec.yaml", ""); |
| 7419 cacheSource("/myproj/web/other.dart", ""); | 7419 cacheSource("/myproj/web/other.dart", ""); |
| 7420 Source source = | 7420 Source source = |
| 7421 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); | 7421 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); |
| 7422 resolve(source); | 7422 computeLibrarySourceErrors(source); |
| 7423 assertErrors( | 7423 assertErrors( |
| 7424 source, [HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE]); | 7424 source, [HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE]); |
| 7425 } | 7425 } |
| 7426 | 7426 |
| 7427 void test_import_referenceOutOfLibDirectory_no_pubspec() { | 7427 void test_import_referenceOutOfLibDirectory_no_pubspec() { |
| 7428 cacheSource("/myproj/web/other.dart", ""); | 7428 cacheSource("/myproj/web/other.dart", ""); |
| 7429 Source source = | 7429 Source source = |
| 7430 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); | 7430 addNamedSource("/myproj/lib/test.dart", "import '../web/other.dart';"); |
| 7431 resolve(source); | 7431 computeLibrarySourceErrors(source); |
| 7432 assertNoErrors(source); | 7432 assertNoErrors(source); |
| 7433 } | 7433 } |
| 7434 | 7434 |
| 7435 void test_import_valid_inside_lib1() { | 7435 void test_import_valid_inside_lib1() { |
| 7436 cacheSource("/myproj/pubspec.yaml", ""); | 7436 cacheSource("/myproj/pubspec.yaml", ""); |
| 7437 cacheSource("/myproj/lib/other.dart", ""); | 7437 cacheSource("/myproj/lib/other.dart", ""); |
| 7438 Source source = | 7438 Source source = |
| 7439 addNamedSource("/myproj/lib/test.dart", "import 'other.dart';"); | 7439 addNamedSource("/myproj/lib/test.dart", "import 'other.dart';"); |
| 7440 resolve(source); | 7440 computeLibrarySourceErrors(source); |
| 7441 assertNoErrors(source); | 7441 assertNoErrors(source); |
| 7442 } | 7442 } |
| 7443 | 7443 |
| 7444 void test_import_valid_inside_lib2() { | 7444 void test_import_valid_inside_lib2() { |
| 7445 cacheSource("/myproj/pubspec.yaml", ""); | 7445 cacheSource("/myproj/pubspec.yaml", ""); |
| 7446 cacheSource("/myproj/lib/bar/other.dart", ""); | 7446 cacheSource("/myproj/lib/bar/other.dart", ""); |
| 7447 Source source = addNamedSource( | 7447 Source source = addNamedSource( |
| 7448 "/myproj/lib/foo/test.dart", "import '../bar/other.dart';"); | 7448 "/myproj/lib/foo/test.dart", "import '../bar/other.dart';"); |
| 7449 resolve(source); | 7449 computeLibrarySourceErrors(source); |
| 7450 assertNoErrors(source); | 7450 assertNoErrors(source); |
| 7451 } | 7451 } |
| 7452 | 7452 |
| 7453 void test_import_valid_outside_lib() { | 7453 void test_import_valid_outside_lib() { |
| 7454 cacheSource("/myproj/pubspec.yaml", ""); | 7454 cacheSource("/myproj/pubspec.yaml", ""); |
| 7455 cacheSource("/myproj/web/other.dart", ""); | 7455 cacheSource("/myproj/web/other.dart", ""); |
| 7456 Source source = | 7456 Source source = |
| 7457 addNamedSource("/myproj/lib2/test.dart", "import '../web/other.dart';"); | 7457 addNamedSource("/myproj/lib2/test.dart", "import '../web/other.dart';"); |
| 7458 resolve(source); | 7458 computeLibrarySourceErrors(source); |
| 7459 assertNoErrors(source); | 7459 assertNoErrors(source); |
| 7460 } | 7460 } |
| 7461 } | 7461 } |
| 7462 | 7462 |
| 7463 /** | 7463 /** |
| 7464 * An AST visitor used to verify that all of the nodes in an AST structure that | 7464 * An AST visitor used to verify that all of the nodes in an AST structure that |
| 7465 * should have been resolved were resolved. | 7465 * should have been resolved were resolved. |
| 7466 */ | 7466 */ |
| 7467 class ResolutionVerifier extends RecursiveAstVisitor<Object> { | 7467 class ResolutionVerifier extends RecursiveAstVisitor<Object> { |
| 7468 /** | 7468 /** |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7829 * @param contents the contents to be returned by the content provider for the
specified file | 7829 * @param contents the contents to be returned by the content provider for the
specified file |
| 7830 * @return the source object representing the cached file | 7830 * @return the source object representing the cached file |
| 7831 */ | 7831 */ |
| 7832 Source cacheSource(String filePath, String contents) { | 7832 Source cacheSource(String filePath, String contents) { |
| 7833 Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); | 7833 Source source = new FileBasedSource(FileUtilities2.createFile(filePath)); |
| 7834 analysisContext2.setContents(source, contents); | 7834 analysisContext2.setContents(source, contents); |
| 7835 return source; | 7835 return source; |
| 7836 } | 7836 } |
| 7837 | 7837 |
| 7838 /** | 7838 /** |
| 7839 * Computes errors for the given [librarySource]. |
| 7840 * This assumes that the given [librarySource] and its parts have already |
| 7841 * been added to the content provider using the method [addNamedSource]. |
| 7842 */ |
| 7843 void computeLibrarySourceErrors(Source librarySource) { |
| 7844 analysisContext.computeErrors(librarySource); |
| 7845 } |
| 7846 |
| 7847 /** |
| 7839 * Create a library element that represents a library named `"test"` containin
g a single | 7848 * Create a library element that represents a library named `"test"` containin
g a single |
| 7840 * empty compilation unit. | 7849 * empty compilation unit. |
| 7841 * | 7850 * |
| 7842 * @return the library element that was created | 7851 * @return the library element that was created |
| 7843 */ | 7852 */ |
| 7844 LibraryElementImpl createDefaultTestLibrary() => | 7853 LibraryElementImpl createDefaultTestLibrary() => |
| 7845 createTestLibrary(AnalysisContextFactory.contextWithCore(), "test"); | 7854 createTestLibrary(AnalysisContextFactory.contextWithCore(), "test"); |
| 7846 | 7855 |
| 7847 /** | 7856 /** |
| 7848 * Create a library element that represents a library with the given name cont
aining a single | 7857 * Create a library element that represents a library with the given name cont
aining a single |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7925 | 7934 |
| 7926 /** | 7935 /** |
| 7927 * Given a library and all of its parts, resolve the contents of the library a
nd the contents of | 7936 * Given a library and all of its parts, resolve the contents of the library a
nd the contents of |
| 7928 * the parts. This assumes that the sources for the library and its parts have
already been added | 7937 * the parts. This assumes that the sources for the library and its parts have
already been added |
| 7929 * to the content provider using the method [addNamedSource]. | 7938 * to the content provider using the method [addNamedSource]. |
| 7930 * | 7939 * |
| 7931 * @param librarySource the source for the compilation unit that defines the l
ibrary | 7940 * @param librarySource the source for the compilation unit that defines the l
ibrary |
| 7932 * @return the element representing the resolved library | 7941 * @return the element representing the resolved library |
| 7933 * @throws AnalysisException if the analysis could not be performed | 7942 * @throws AnalysisException if the analysis could not be performed |
| 7934 */ | 7943 */ |
| 7935 LibraryElement resolve(Source librarySource) => | 7944 LibraryElement resolve2(Source librarySource) => |
| 7936 analysisContext2.computeLibraryElement(librarySource); | 7945 analysisContext2.computeLibraryElement(librarySource); |
| 7937 | 7946 |
| 7938 /** | 7947 /** |
| 7939 * Return the resolved compilation unit corresponding to the given source in t
he given library. | 7948 * Return the resolved compilation unit corresponding to the given source in t
he given library. |
| 7940 * | 7949 * |
| 7941 * @param source the source of the compilation unit to be returned | 7950 * @param source the source of the compilation unit to be returned |
| 7942 * @param library the library in which the compilation unit is to be resolved | 7951 * @param library the library in which the compilation unit is to be resolved |
| 7943 * @return the resolved compilation unit | 7952 * @return the resolved compilation unit |
| 7944 * @throws Exception if the compilation unit could not be resolved | 7953 * @throws Exception if the compilation unit could not be resolved |
| 7945 */ | 7954 */ |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8132 } | 8141 } |
| 8133 class M2 { | 8142 class M2 { |
| 8134 get x => null; | 8143 get x => null; |
| 8135 set x(value) {} | 8144 set x(value) {} |
| 8136 } | 8145 } |
| 8137 class C extends B with M1, M2 {} | 8146 class C extends B with M1, M2 {} |
| 8138 void main() { | 8147 void main() { |
| 8139 new C().x += 1; | 8148 new C().x += 1; |
| 8140 } | 8149 } |
| 8141 '''); | 8150 '''); |
| 8142 LibraryElement library = resolve(source); | 8151 LibraryElement library = resolve2(source); |
| 8143 assertNoErrors(source); | 8152 assertNoErrors(source); |
| 8144 verify([source]); | 8153 verify([source]); |
| 8145 // Verify that both the getter and setter for "x" in "new C().x" refer to | 8154 // Verify that both the getter and setter for "x" in "new C().x" refer to |
| 8146 // the accessors defined in M2. | 8155 // the accessors defined in M2. |
| 8147 FunctionDeclaration main = | 8156 FunctionDeclaration main = |
| 8148 library.definingCompilationUnit.functions[0].computeNode(); | 8157 library.definingCompilationUnit.functions[0].computeNode(); |
| 8149 BlockFunctionBody body = main.functionExpression.body; | 8158 BlockFunctionBody body = main.functionExpression.body; |
| 8150 ExpressionStatement stmt = body.block.statements[0]; | 8159 ExpressionStatement stmt = body.block.statements[0]; |
| 8151 AssignmentExpression assignment = stmt.expression; | 8160 AssignmentExpression assignment = stmt.expression; |
| 8152 PropertyAccess propertyAccess = assignment.leftHandSide; | 8161 PropertyAccess propertyAccess = assignment.leftHandSide; |
| 8153 expect( | 8162 expect( |
| 8154 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); | 8163 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); |
| 8155 expect( | 8164 expect( |
| 8156 propertyAccess.propertyName.auxiliaryElements.staticElement.enclosingEle
ment.name, | 8165 propertyAccess.propertyName.auxiliaryElements.staticElement.enclosingEle
ment.name, |
| 8157 'M2'); | 8166 'M2'); |
| 8158 } | 8167 } |
| 8159 | 8168 |
| 8160 void fail_staticInvocation() { | 8169 void fail_staticInvocation() { |
| 8161 Source source = addSource(r''' | 8170 Source source = addSource(r''' |
| 8162 class A { | 8171 class A { |
| 8163 static int get g => (a,b) => 0; | 8172 static int get g => (a,b) => 0; |
| 8164 } | 8173 } |
| 8165 class B { | 8174 class B { |
| 8166 f() { | 8175 f() { |
| 8167 A.g(1,0); | 8176 A.g(1,0); |
| 8168 } | 8177 } |
| 8169 }'''); | 8178 }'''); |
| 8170 resolve(source); | 8179 computeLibrarySourceErrors(source); |
| 8171 assertNoErrors(source); | 8180 assertNoErrors(source); |
| 8172 verify([source]); | 8181 verify([source]); |
| 8173 } | 8182 } |
| 8174 | 8183 |
| 8175 void test_argumentResolution_required_matching() { | 8184 void test_argumentResolution_required_matching() { |
| 8176 Source source = addSource(r''' | 8185 Source source = addSource(r''' |
| 8177 class A { | 8186 class A { |
| 8178 void f() { | 8187 void f() { |
| 8179 g(1, 2, 3); | 8188 g(1, 2, 3); |
| 8180 } | 8189 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8273 | 8282 |
| 8274 void test_argumentResolution_setter_propagated() { | 8283 void test_argumentResolution_setter_propagated() { |
| 8275 Source source = addSource(r''' | 8284 Source source = addSource(r''' |
| 8276 main() { | 8285 main() { |
| 8277 var a = new A(); | 8286 var a = new A(); |
| 8278 a.sss = 0; | 8287 a.sss = 0; |
| 8279 } | 8288 } |
| 8280 class A { | 8289 class A { |
| 8281 set sss(x) {} | 8290 set sss(x) {} |
| 8282 }'''); | 8291 }'''); |
| 8283 LibraryElement library = resolve(source); | 8292 LibraryElement library = resolve2(source); |
| 8284 CompilationUnitElement unit = library.definingCompilationUnit; | 8293 CompilationUnitElement unit = library.definingCompilationUnit; |
| 8285 // find "a.sss = 0" | 8294 // find "a.sss = 0" |
| 8286 AssignmentExpression assignment; | 8295 AssignmentExpression assignment; |
| 8287 { | 8296 { |
| 8288 FunctionElement mainElement = unit.functions[0]; | 8297 FunctionElement mainElement = unit.functions[0]; |
| 8289 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; | 8298 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; |
| 8290 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 8299 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 8291 ExpressionStatement expressionStatement = | 8300 ExpressionStatement expressionStatement = |
| 8292 statement as ExpressionStatement; | 8301 statement as ExpressionStatement; |
| 8293 assignment = expressionStatement.expression as AssignmentExpression; | 8302 assignment = expressionStatement.expression as AssignmentExpression; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 8309 main() { | 8318 main() { |
| 8310 var a = new A(); | 8319 var a = new A(); |
| 8311 a.b.sss = 0; | 8320 a.b.sss = 0; |
| 8312 } | 8321 } |
| 8313 class A { | 8322 class A { |
| 8314 B b = new B(); | 8323 B b = new B(); |
| 8315 } | 8324 } |
| 8316 class B { | 8325 class B { |
| 8317 set sss(x) {} | 8326 set sss(x) {} |
| 8318 }'''); | 8327 }'''); |
| 8319 LibraryElement library = resolve(source); | 8328 LibraryElement library = resolve2(source); |
| 8320 CompilationUnitElement unit = library.definingCompilationUnit; | 8329 CompilationUnitElement unit = library.definingCompilationUnit; |
| 8321 // find "a.b.sss = 0" | 8330 // find "a.b.sss = 0" |
| 8322 AssignmentExpression assignment; | 8331 AssignmentExpression assignment; |
| 8323 { | 8332 { |
| 8324 FunctionElement mainElement = unit.functions[0]; | 8333 FunctionElement mainElement = unit.functions[0]; |
| 8325 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; | 8334 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; |
| 8326 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 8335 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 8327 ExpressionStatement expressionStatement = | 8336 ExpressionStatement expressionStatement = |
| 8328 statement as ExpressionStatement; | 8337 statement as ExpressionStatement; |
| 8329 assignment = expressionStatement.expression as AssignmentExpression; | 8338 assignment = expressionStatement.expression as AssignmentExpression; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 8342 | 8351 |
| 8343 void test_argumentResolution_setter_static() { | 8352 void test_argumentResolution_setter_static() { |
| 8344 Source source = addSource(r''' | 8353 Source source = addSource(r''' |
| 8345 main() { | 8354 main() { |
| 8346 A a = new A(); | 8355 A a = new A(); |
| 8347 a.sss = 0; | 8356 a.sss = 0; |
| 8348 } | 8357 } |
| 8349 class A { | 8358 class A { |
| 8350 set sss(x) {} | 8359 set sss(x) {} |
| 8351 }'''); | 8360 }'''); |
| 8352 LibraryElement library = resolve(source); | 8361 LibraryElement library = resolve2(source); |
| 8353 CompilationUnitElement unit = library.definingCompilationUnit; | 8362 CompilationUnitElement unit = library.definingCompilationUnit; |
| 8354 // find "a.sss = 0" | 8363 // find "a.sss = 0" |
| 8355 AssignmentExpression assignment; | 8364 AssignmentExpression assignment; |
| 8356 { | 8365 { |
| 8357 FunctionElement mainElement = unit.functions[0]; | 8366 FunctionElement mainElement = unit.functions[0]; |
| 8358 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; | 8367 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; |
| 8359 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 8368 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 8360 ExpressionStatement expressionStatement = | 8369 ExpressionStatement expressionStatement = |
| 8361 statement as ExpressionStatement; | 8370 statement as ExpressionStatement; |
| 8362 assignment = expressionStatement.expression as AssignmentExpression; | 8371 assignment = expressionStatement.expression as AssignmentExpression; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 8377 main() { | 8386 main() { |
| 8378 A a = new A(); | 8387 A a = new A(); |
| 8379 a.b.sss = 0; | 8388 a.b.sss = 0; |
| 8380 } | 8389 } |
| 8381 class A { | 8390 class A { |
| 8382 B b = new B(); | 8391 B b = new B(); |
| 8383 } | 8392 } |
| 8384 class B { | 8393 class B { |
| 8385 set sss(x) {} | 8394 set sss(x) {} |
| 8386 }'''); | 8395 }'''); |
| 8387 LibraryElement library = resolve(source); | 8396 LibraryElement library = resolve2(source); |
| 8388 CompilationUnitElement unit = library.definingCompilationUnit; | 8397 CompilationUnitElement unit = library.definingCompilationUnit; |
| 8389 // find "a.b.sss = 0" | 8398 // find "a.b.sss = 0" |
| 8390 AssignmentExpression assignment; | 8399 AssignmentExpression assignment; |
| 8391 { | 8400 { |
| 8392 FunctionElement mainElement = unit.functions[0]; | 8401 FunctionElement mainElement = unit.functions[0]; |
| 8393 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; | 8402 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; |
| 8394 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 8403 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 8395 ExpressionStatement expressionStatement = | 8404 ExpressionStatement expressionStatement = |
| 8396 statement as ExpressionStatement; | 8405 statement as ExpressionStatement; |
| 8397 assignment = expressionStatement.expression as AssignmentExpression; | 8406 assignment = expressionStatement.expression as AssignmentExpression; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8535 } | 8544 } |
| 8536 | 8545 |
| 8537 void test_class_definesCall() { | 8546 void test_class_definesCall() { |
| 8538 Source source = addSource(r''' | 8547 Source source = addSource(r''' |
| 8539 class A { | 8548 class A { |
| 8540 int call(int x) { return x; } | 8549 int call(int x) { return x; } |
| 8541 } | 8550 } |
| 8542 int f(A a) { | 8551 int f(A a) { |
| 8543 return a(0); | 8552 return a(0); |
| 8544 }'''); | 8553 }'''); |
| 8545 resolve(source); | 8554 computeLibrarySourceErrors(source); |
| 8546 assertNoErrors(source); | 8555 assertNoErrors(source); |
| 8547 verify([source]); | 8556 verify([source]); |
| 8548 } | 8557 } |
| 8549 | 8558 |
| 8550 void test_class_extends_implements() { | 8559 void test_class_extends_implements() { |
| 8551 Source source = addSource(r''' | 8560 Source source = addSource(r''' |
| 8552 class A extends B implements C {} | 8561 class A extends B implements C {} |
| 8553 class B {} | 8562 class B {} |
| 8554 class C {}'''); | 8563 class C {}'''); |
| 8555 resolve(source); | 8564 computeLibrarySourceErrors(source); |
| 8556 assertNoErrors(source); | 8565 assertNoErrors(source); |
| 8557 verify([source]); | 8566 verify([source]); |
| 8558 } | 8567 } |
| 8559 | 8568 |
| 8560 void test_commentReference_class() { | 8569 void test_commentReference_class() { |
| 8561 Source source = addSource(r''' | 8570 Source source = addSource(r''' |
| 8562 f() {} | 8571 f() {} |
| 8563 /** [A] [new A] [A.n] [new A.n] [m] [f] */ | 8572 /** [A] [new A] [A.n] [new A.n] [m] [f] */ |
| 8564 class A { | 8573 class A { |
| 8565 A() {} | 8574 A() {} |
| 8566 A.n() {} | 8575 A.n() {} |
| 8567 m() {} | 8576 m() {} |
| 8568 }'''); | 8577 }'''); |
| 8569 resolve(source); | 8578 computeLibrarySourceErrors(source); |
| 8570 assertNoErrors(source); | 8579 assertNoErrors(source); |
| 8571 verify([source]); | 8580 verify([source]); |
| 8572 } | 8581 } |
| 8573 | 8582 |
| 8574 void test_commentReference_parameter() { | 8583 void test_commentReference_parameter() { |
| 8575 Source source = addSource(r''' | 8584 Source source = addSource(r''' |
| 8576 class A { | 8585 class A { |
| 8577 A() {} | 8586 A() {} |
| 8578 A.n() {} | 8587 A.n() {} |
| 8579 /** [e] [f] */ | 8588 /** [e] [f] */ |
| 8580 m(e, f()) {} | 8589 m(e, f()) {} |
| 8581 }'''); | 8590 }'''); |
| 8582 resolve(source); | 8591 computeLibrarySourceErrors(source); |
| 8583 assertNoErrors(source); | 8592 assertNoErrors(source); |
| 8584 verify([source]); | 8593 verify([source]); |
| 8585 } | 8594 } |
| 8586 | 8595 |
| 8587 void test_commentReference_singleLine() { | 8596 void test_commentReference_singleLine() { |
| 8588 Source source = addSource(r''' | 8597 Source source = addSource(r''' |
| 8589 /// [A] | 8598 /// [A] |
| 8590 class A {}'''); | 8599 class A {}'''); |
| 8591 resolve(source); | 8600 computeLibrarySourceErrors(source); |
| 8592 assertNoErrors(source); | 8601 assertNoErrors(source); |
| 8593 verify([source]); | 8602 verify([source]); |
| 8594 } | 8603 } |
| 8595 | 8604 |
| 8596 void test_continueTarget_labeled() { | 8605 void test_continueTarget_labeled() { |
| 8597 // Verify that the target of the label is correctly found and is recorded | 8606 // Verify that the target of the label is correctly found and is recorded |
| 8598 // as the unlabeled portion of the statement. | 8607 // as the unlabeled portion of the statement. |
| 8599 String text = r''' | 8608 String text = r''' |
| 8600 void f() { | 8609 void f() { |
| 8601 loop1: while (true) { | 8610 loop1: while (true) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8715 } | 8724 } |
| 8716 '''; | 8725 '''; |
| 8717 CompilationUnit unit = resolveSource(text); | 8726 CompilationUnit unit = resolveSource(text); |
| 8718 ContinueStatement continueStatement = EngineTestCase.findNode( | 8727 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 8719 unit, text, 'continue', (n) => n is ContinueStatement); | 8728 unit, text, 'continue', (n) => n is ContinueStatement); |
| 8720 expect(continueStatement.target, isNull); | 8729 expect(continueStatement.target, isNull); |
| 8721 } | 8730 } |
| 8722 | 8731 |
| 8723 void test_empty() { | 8732 void test_empty() { |
| 8724 Source source = addSource(""); | 8733 Source source = addSource(""); |
| 8725 resolve(source); | 8734 computeLibrarySourceErrors(source); |
| 8726 assertNoErrors(source); | 8735 assertNoErrors(source); |
| 8727 verify([source]); | 8736 verify([source]); |
| 8728 } | 8737 } |
| 8729 | 8738 |
| 8730 void test_entryPoint_exported() { | 8739 void test_entryPoint_exported() { |
| 8731 addNamedSource("/two.dart", r''' | 8740 addNamedSource("/two.dart", r''' |
| 8732 library two; | 8741 library two; |
| 8733 main() {}'''); | 8742 main() {}'''); |
| 8734 Source source = addNamedSource("/one.dart", r''' | 8743 Source source = addNamedSource("/one.dart", r''' |
| 8735 library one; | 8744 library one; |
| 8736 export 'two.dart';'''); | 8745 export 'two.dart';'''); |
| 8737 LibraryElement library = resolve(source); | 8746 LibraryElement library = resolve2(source); |
| 8738 expect(library, isNotNull); | 8747 expect(library, isNotNull); |
| 8739 FunctionElement main = library.entryPoint; | 8748 FunctionElement main = library.entryPoint; |
| 8740 expect(main, isNotNull); | 8749 expect(main, isNotNull); |
| 8741 expect(main.library, isNot(same(library))); | 8750 expect(main.library, isNot(same(library))); |
| 8742 assertNoErrors(source); | 8751 assertNoErrors(source); |
| 8743 verify([source]); | 8752 verify([source]); |
| 8744 } | 8753 } |
| 8745 | 8754 |
| 8746 void test_entryPoint_local() { | 8755 void test_entryPoint_local() { |
| 8747 Source source = addNamedSource("/one.dart", r''' | 8756 Source source = addNamedSource("/one.dart", r''' |
| 8748 library one; | 8757 library one; |
| 8749 main() {}'''); | 8758 main() {}'''); |
| 8750 LibraryElement library = resolve(source); | 8759 LibraryElement library = resolve2(source); |
| 8751 expect(library, isNotNull); | 8760 expect(library, isNotNull); |
| 8752 FunctionElement main = library.entryPoint; | 8761 FunctionElement main = library.entryPoint; |
| 8753 expect(main, isNotNull); | 8762 expect(main, isNotNull); |
| 8754 expect(main.library, same(library)); | 8763 expect(main.library, same(library)); |
| 8755 assertNoErrors(source); | 8764 assertNoErrors(source); |
| 8756 verify([source]); | 8765 verify([source]); |
| 8757 } | 8766 } |
| 8758 | 8767 |
| 8759 void test_entryPoint_none() { | 8768 void test_entryPoint_none() { |
| 8760 Source source = addNamedSource("/one.dart", "library one;"); | 8769 Source source = addNamedSource("/one.dart", "library one;"); |
| 8761 LibraryElement library = resolve(source); | 8770 LibraryElement library = resolve2(source); |
| 8762 expect(library, isNotNull); | 8771 expect(library, isNotNull); |
| 8763 expect(library.entryPoint, isNull); | 8772 expect(library.entryPoint, isNull); |
| 8764 assertNoErrors(source); | 8773 assertNoErrors(source); |
| 8765 verify([source]); | 8774 verify([source]); |
| 8766 } | 8775 } |
| 8767 | 8776 |
| 8768 void test_enum_externalLibrary() { | 8777 void test_enum_externalLibrary() { |
| 8769 addNamedSource("/my_lib.dart", r''' | 8778 addNamedSource("/my_lib.dart", r''' |
| 8770 library my_lib; | 8779 library my_lib; |
| 8771 enum EEE {A, B, C}'''); | 8780 enum EEE {A, B, C}'''); |
| 8772 Source source = addSource(r''' | 8781 Source source = addSource(r''' |
| 8773 import 'my_lib.dart'; | 8782 import 'my_lib.dart'; |
| 8774 main() { | 8783 main() { |
| 8775 EEE e = null; | 8784 EEE e = null; |
| 8776 }'''); | 8785 }'''); |
| 8777 resolve(source); | 8786 computeLibrarySourceErrors(source); |
| 8778 assertNoErrors(source); | 8787 assertNoErrors(source); |
| 8779 verify([source]); | 8788 verify([source]); |
| 8780 } | 8789 } |
| 8781 | 8790 |
| 8782 void test_extractedMethodAsConstant() { | 8791 void test_extractedMethodAsConstant() { |
| 8783 Source source = addSource(r''' | 8792 Source source = addSource(r''' |
| 8784 abstract class Comparable<T> { | 8793 abstract class Comparable<T> { |
| 8785 int compareTo(T other); | 8794 int compareTo(T other); |
| 8786 static int compare(Comparable a, Comparable b) => a.compareTo(b); | 8795 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 8787 } | 8796 } |
| 8788 class A { | 8797 class A { |
| 8789 void sort([compare = Comparable.compare]) {} | 8798 void sort([compare = Comparable.compare]) {} |
| 8790 }'''); | 8799 }'''); |
| 8791 resolve(source); | 8800 computeLibrarySourceErrors(source); |
| 8792 assertNoErrors(source); | 8801 assertNoErrors(source); |
| 8793 verify([source]); | 8802 verify([source]); |
| 8794 } | 8803 } |
| 8795 | 8804 |
| 8796 void test_fieldFormalParameter() { | 8805 void test_fieldFormalParameter() { |
| 8797 Source source = addSource(r''' | 8806 Source source = addSource(r''' |
| 8798 class A { | 8807 class A { |
| 8799 int x; | 8808 int x; |
| 8800 A(this.x) {} | 8809 A(this.x) {} |
| 8801 }'''); | 8810 }'''); |
| 8802 resolve(source); | 8811 computeLibrarySourceErrors(source); |
| 8803 assertNoErrors(source); | 8812 assertNoErrors(source); |
| 8804 verify([source]); | 8813 verify([source]); |
| 8805 } | 8814 } |
| 8806 | 8815 |
| 8807 void test_forEachLoops_nonConflicting() { | 8816 void test_forEachLoops_nonConflicting() { |
| 8808 Source source = addSource(r''' | 8817 Source source = addSource(r''' |
| 8809 f() { | 8818 f() { |
| 8810 List list = [1,2,3]; | 8819 List list = [1,2,3]; |
| 8811 for (int x in list) {} | 8820 for (int x in list) {} |
| 8812 for (int x in list) {} | 8821 for (int x in list) {} |
| 8813 }'''); | 8822 }'''); |
| 8814 resolve(source); | 8823 computeLibrarySourceErrors(source); |
| 8815 assertNoErrors(source); | 8824 assertNoErrors(source); |
| 8816 verify([source]); | 8825 verify([source]); |
| 8817 } | 8826 } |
| 8818 | 8827 |
| 8819 void test_forLoops_nonConflicting() { | 8828 void test_forLoops_nonConflicting() { |
| 8820 Source source = addSource(r''' | 8829 Source source = addSource(r''' |
| 8821 f() { | 8830 f() { |
| 8822 for (int i = 0; i < 3; i++) { | 8831 for (int i = 0; i < 3; i++) { |
| 8823 } | 8832 } |
| 8824 for (int i = 0; i < 3; i++) { | 8833 for (int i = 0; i < 3; i++) { |
| 8825 } | 8834 } |
| 8826 }'''); | 8835 }'''); |
| 8827 resolve(source); | 8836 computeLibrarySourceErrors(source); |
| 8828 assertNoErrors(source); | 8837 assertNoErrors(source); |
| 8829 verify([source]); | 8838 verify([source]); |
| 8830 } | 8839 } |
| 8831 | 8840 |
| 8832 void test_functionTypeAlias() { | 8841 void test_functionTypeAlias() { |
| 8833 Source source = addSource(r''' | 8842 Source source = addSource(r''' |
| 8834 typedef bool P(e); | 8843 typedef bool P(e); |
| 8835 class A { | 8844 class A { |
| 8836 P p; | 8845 P p; |
| 8837 m(e) { | 8846 m(e) { |
| 8838 if (p(e)) {} | 8847 if (p(e)) {} |
| 8839 } | 8848 } |
| 8840 }'''); | 8849 }'''); |
| 8841 resolve(source); | 8850 computeLibrarySourceErrors(source); |
| 8842 assertNoErrors(source); | 8851 assertNoErrors(source); |
| 8843 verify([source]); | 8852 verify([source]); |
| 8844 } | 8853 } |
| 8845 | 8854 |
| 8846 void test_getter_and_setter_fromMixins_bare_identifier() { | 8855 void test_getter_and_setter_fromMixins_bare_identifier() { |
| 8847 Source source = addSource(''' | 8856 Source source = addSource(''' |
| 8848 class B {} | 8857 class B {} |
| 8849 class M1 { | 8858 class M1 { |
| 8850 get x => null; | 8859 get x => null; |
| 8851 set x(value) {} | 8860 set x(value) {} |
| 8852 } | 8861 } |
| 8853 class M2 { | 8862 class M2 { |
| 8854 get x => null; | 8863 get x => null; |
| 8855 set x(value) {} | 8864 set x(value) {} |
| 8856 } | 8865 } |
| 8857 class C extends B with M1, M2 { | 8866 class C extends B with M1, M2 { |
| 8858 void f() { | 8867 void f() { |
| 8859 x += 1; | 8868 x += 1; |
| 8860 } | 8869 } |
| 8861 } | 8870 } |
| 8862 '''); | 8871 '''); |
| 8863 LibraryElement library = resolve(source); | 8872 LibraryElement library = resolve2(source); |
| 8864 assertNoErrors(source); | 8873 assertNoErrors(source); |
| 8865 verify([source]); | 8874 verify([source]); |
| 8866 // Verify that both the getter and setter for "x" in C.f() refer to the | 8875 // Verify that both the getter and setter for "x" in C.f() refer to the |
| 8867 // accessors defined in M2. | 8876 // accessors defined in M2. |
| 8868 ClassElement classC = library.definingCompilationUnit.types[3]; | 8877 ClassElement classC = library.definingCompilationUnit.types[3]; |
| 8869 MethodDeclaration f = classC.getMethod('f').computeNode(); | 8878 MethodDeclaration f = classC.getMethod('f').computeNode(); |
| 8870 BlockFunctionBody body = f.body; | 8879 BlockFunctionBody body = f.body; |
| 8871 ExpressionStatement stmt = body.block.statements[0]; | 8880 ExpressionStatement stmt = body.block.statements[0]; |
| 8872 AssignmentExpression assignment = stmt.expression; | 8881 AssignmentExpression assignment = stmt.expression; |
| 8873 SimpleIdentifier leftHandSide = assignment.leftHandSide; | 8882 SimpleIdentifier leftHandSide = assignment.leftHandSide; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 8884 } | 8893 } |
| 8885 class M2 { | 8894 class M2 { |
| 8886 get x => null; | 8895 get x => null; |
| 8887 } | 8896 } |
| 8888 class C extends B with M1, M2 { | 8897 class C extends B with M1, M2 { |
| 8889 f() { | 8898 f() { |
| 8890 return x; | 8899 return x; |
| 8891 } | 8900 } |
| 8892 } | 8901 } |
| 8893 '''); | 8902 '''); |
| 8894 LibraryElement library = resolve(source); | 8903 LibraryElement library = resolve2(source); |
| 8895 assertNoErrors(source); | 8904 assertNoErrors(source); |
| 8896 verify([source]); | 8905 verify([source]); |
| 8897 // Verify that the getter for "x" in C.f() refers to the getter defined in | 8906 // Verify that the getter for "x" in C.f() refers to the getter defined in |
| 8898 // M2. | 8907 // M2. |
| 8899 ClassElement classC = library.definingCompilationUnit.types[3]; | 8908 ClassElement classC = library.definingCompilationUnit.types[3]; |
| 8900 MethodDeclaration f = classC.getMethod('f').computeNode(); | 8909 MethodDeclaration f = classC.getMethod('f').computeNode(); |
| 8901 BlockFunctionBody body = f.body; | 8910 BlockFunctionBody body = f.body; |
| 8902 ReturnStatement stmt = body.block.statements[0]; | 8911 ReturnStatement stmt = body.block.statements[0]; |
| 8903 SimpleIdentifier x = stmt.expression; | 8912 SimpleIdentifier x = stmt.expression; |
| 8904 expect(x.staticElement.enclosingElement.name, 'M2'); | 8913 expect(x.staticElement.enclosingElement.name, 'M2'); |
| 8905 } | 8914 } |
| 8906 | 8915 |
| 8907 void test_getter_fromMixins_property_access() { | 8916 void test_getter_fromMixins_property_access() { |
| 8908 Source source = addSource(''' | 8917 Source source = addSource(''' |
| 8909 class B {} | 8918 class B {} |
| 8910 class M1 { | 8919 class M1 { |
| 8911 get x => null; | 8920 get x => null; |
| 8912 } | 8921 } |
| 8913 class M2 { | 8922 class M2 { |
| 8914 get x => null; | 8923 get x => null; |
| 8915 } | 8924 } |
| 8916 class C extends B with M1, M2 {} | 8925 class C extends B with M1, M2 {} |
| 8917 void main() { | 8926 void main() { |
| 8918 var y = new C().x; | 8927 var y = new C().x; |
| 8919 } | 8928 } |
| 8920 '''); | 8929 '''); |
| 8921 LibraryElement library = resolve(source); | 8930 LibraryElement library = resolve2(source); |
| 8922 assertNoErrors(source); | 8931 assertNoErrors(source); |
| 8923 verify([source]); | 8932 verify([source]); |
| 8924 // Verify that the getter for "x" in "new C().x" refers to the getter | 8933 // Verify that the getter for "x" in "new C().x" refers to the getter |
| 8925 // defined in M2. | 8934 // defined in M2. |
| 8926 FunctionDeclaration main = | 8935 FunctionDeclaration main = |
| 8927 library.definingCompilationUnit.functions[0].computeNode(); | 8936 library.definingCompilationUnit.functions[0].computeNode(); |
| 8928 BlockFunctionBody body = main.functionExpression.body; | 8937 BlockFunctionBody body = main.functionExpression.body; |
| 8929 VariableDeclarationStatement stmt = body.block.statements[0]; | 8938 VariableDeclarationStatement stmt = body.block.statements[0]; |
| 8930 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer; | 8939 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer; |
| 8931 expect( | 8940 expect( |
| 8932 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); | 8941 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); |
| 8933 } | 8942 } |
| 8934 | 8943 |
| 8935 void test_getterAndSetterWithDifferentTypes() { | 8944 void test_getterAndSetterWithDifferentTypes() { |
| 8936 Source source = addSource(r''' | 8945 Source source = addSource(r''' |
| 8937 class A { | 8946 class A { |
| 8938 int get f => 0; | 8947 int get f => 0; |
| 8939 void set f(String s) {} | 8948 void set f(String s) {} |
| 8940 } | 8949 } |
| 8941 g (A a) { | 8950 g (A a) { |
| 8942 a.f = a.f.toString(); | 8951 a.f = a.f.toString(); |
| 8943 }'''); | 8952 }'''); |
| 8944 resolve(source); | 8953 computeLibrarySourceErrors(source); |
| 8945 assertErrors( | 8954 assertErrors( |
| 8946 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); | 8955 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); |
| 8947 verify([source]); | 8956 verify([source]); |
| 8948 } | 8957 } |
| 8949 | 8958 |
| 8950 void test_hasReferenceToSuper() { | 8959 void test_hasReferenceToSuper() { |
| 8951 Source source = addSource(r''' | 8960 Source source = addSource(r''' |
| 8952 class A {} | 8961 class A {} |
| 8953 class B {toString() => super.toString();}'''); | 8962 class B {toString() => super.toString();}'''); |
| 8954 LibraryElement library = resolve(source); | 8963 LibraryElement library = resolve2(source); |
| 8955 expect(library, isNotNull); | 8964 expect(library, isNotNull); |
| 8956 CompilationUnitElement unit = library.definingCompilationUnit; | 8965 CompilationUnitElement unit = library.definingCompilationUnit; |
| 8957 expect(unit, isNotNull); | 8966 expect(unit, isNotNull); |
| 8958 List<ClassElement> classes = unit.types; | 8967 List<ClassElement> classes = unit.types; |
| 8959 expect(classes, hasLength(2)); | 8968 expect(classes, hasLength(2)); |
| 8960 expect(classes[0].hasReferenceToSuper, isFalse); | 8969 expect(classes[0].hasReferenceToSuper, isFalse); |
| 8961 expect(classes[1].hasReferenceToSuper, isTrue); | 8970 expect(classes[1].hasReferenceToSuper, isTrue); |
| 8962 assertNoErrors(source); | 8971 assertNoErrors(source); |
| 8963 verify([source]); | 8972 verify([source]); |
| 8964 } | 8973 } |
| 8965 | 8974 |
| 8966 void test_import_hide() { | 8975 void test_import_hide() { |
| 8967 addNamedSource("lib1.dart", r''' | 8976 addNamedSource("lib1.dart", r''' |
| 8968 library lib1; | 8977 library lib1; |
| 8969 set foo(value) {} | 8978 set foo(value) {} |
| 8970 class A {}'''); | 8979 class A {}'''); |
| 8971 addNamedSource("lib2.dart", r''' | 8980 addNamedSource("lib2.dart", r''' |
| 8972 library lib2; | 8981 library lib2; |
| 8973 set foo(value) {}'''); | 8982 set foo(value) {}'''); |
| 8974 Source source = addNamedSource("lib3.dart", r''' | 8983 Source source = addNamedSource("lib3.dart", r''' |
| 8975 import 'lib1.dart' hide foo; | 8984 import 'lib1.dart' hide foo; |
| 8976 import 'lib2.dart'; | 8985 import 'lib2.dart'; |
| 8977 | 8986 |
| 8978 main() { | 8987 main() { |
| 8979 foo = 0; | 8988 foo = 0; |
| 8980 } | 8989 } |
| 8981 A a;'''); | 8990 A a;'''); |
| 8982 resolve(source); | 8991 computeLibrarySourceErrors(source); |
| 8983 assertNoErrors(source); | 8992 assertNoErrors(source); |
| 8984 verify([source]); | 8993 verify([source]); |
| 8985 } | 8994 } |
| 8986 | 8995 |
| 8987 void test_import_prefix() { | 8996 void test_import_prefix() { |
| 8988 addNamedSource("/two.dart", r''' | 8997 addNamedSource("/two.dart", r''' |
| 8989 library two; | 8998 library two; |
| 8990 f(int x) { | 8999 f(int x) { |
| 8991 return x * x; | 9000 return x * x; |
| 8992 }'''); | 9001 }'''); |
| 8993 Source source = addNamedSource("/one.dart", r''' | 9002 Source source = addNamedSource("/one.dart", r''' |
| 8994 library one; | 9003 library one; |
| 8995 import 'two.dart' as _two; | 9004 import 'two.dart' as _two; |
| 8996 main() { | 9005 main() { |
| 8997 _two.f(0); | 9006 _two.f(0); |
| 8998 }'''); | 9007 }'''); |
| 8999 resolve(source); | 9008 computeLibrarySourceErrors(source); |
| 9000 assertNoErrors(source); | 9009 assertNoErrors(source); |
| 9001 verify([source]); | 9010 verify([source]); |
| 9002 } | 9011 } |
| 9003 | 9012 |
| 9004 void test_import_spaceInUri() { | 9013 void test_import_spaceInUri() { |
| 9005 addNamedSource("sub folder/lib.dart", r''' | 9014 addNamedSource("sub folder/lib.dart", r''' |
| 9006 library lib; | 9015 library lib; |
| 9007 foo() {}'''); | 9016 foo() {}'''); |
| 9008 Source source = addNamedSource("app.dart", r''' | 9017 Source source = addNamedSource("app.dart", r''' |
| 9009 import 'sub folder/lib.dart'; | 9018 import 'sub folder/lib.dart'; |
| 9010 | 9019 |
| 9011 main() { | 9020 main() { |
| 9012 foo(); | 9021 foo(); |
| 9013 }'''); | 9022 }'''); |
| 9014 resolve(source); | 9023 computeLibrarySourceErrors(source); |
| 9015 assertNoErrors(source); | 9024 assertNoErrors(source); |
| 9016 verify([source]); | 9025 verify([source]); |
| 9017 } | 9026 } |
| 9018 | 9027 |
| 9019 void test_indexExpression_typeParameters() { | 9028 void test_indexExpression_typeParameters() { |
| 9020 Source source = addSource(r''' | 9029 Source source = addSource(r''' |
| 9021 f() { | 9030 f() { |
| 9022 List<int> a; | 9031 List<int> a; |
| 9023 a[0]; | 9032 a[0]; |
| 9024 List<List<int>> b; | 9033 List<List<int>> b; |
| 9025 b[0][0]; | 9034 b[0][0]; |
| 9026 List<List<List<int>>> c; | 9035 List<List<List<int>>> c; |
| 9027 c[0][0][0]; | 9036 c[0][0][0]; |
| 9028 }'''); | 9037 }'''); |
| 9029 resolve(source); | 9038 computeLibrarySourceErrors(source); |
| 9030 assertNoErrors(source); | 9039 assertNoErrors(source); |
| 9031 verify([source]); | 9040 verify([source]); |
| 9032 } | 9041 } |
| 9033 | 9042 |
| 9034 void test_indexExpression_typeParameters_invalidAssignmentWarning() { | 9043 void test_indexExpression_typeParameters_invalidAssignmentWarning() { |
| 9035 Source source = addSource(r''' | 9044 Source source = addSource(r''' |
| 9036 f() { | 9045 f() { |
| 9037 List<List<int>> b; | 9046 List<List<int>> b; |
| 9038 b[0][0] = 'hi'; | 9047 b[0][0] = 'hi'; |
| 9039 }'''); | 9048 }'''); |
| 9040 resolve(source); | 9049 computeLibrarySourceErrors(source); |
| 9041 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 9050 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 9042 verify([source]); | 9051 verify([source]); |
| 9043 } | 9052 } |
| 9044 | 9053 |
| 9045 void test_indirectOperatorThroughCall() { | 9054 void test_indirectOperatorThroughCall() { |
| 9046 Source source = addSource(r''' | 9055 Source source = addSource(r''' |
| 9047 class A { | 9056 class A { |
| 9048 B call() { return new B(); } | 9057 B call() { return new B(); } |
| 9049 } | 9058 } |
| 9050 | 9059 |
| 9051 class B { | 9060 class B { |
| 9052 int operator [](int i) { return i; } | 9061 int operator [](int i) { return i; } |
| 9053 } | 9062 } |
| 9054 | 9063 |
| 9055 A f = new A(); | 9064 A f = new A(); |
| 9056 | 9065 |
| 9057 g(int x) {} | 9066 g(int x) {} |
| 9058 | 9067 |
| 9059 main() { | 9068 main() { |
| 9060 g(f()[0]); | 9069 g(f()[0]); |
| 9061 }'''); | 9070 }'''); |
| 9062 resolve(source); | 9071 computeLibrarySourceErrors(source); |
| 9063 assertNoErrors(source); | 9072 assertNoErrors(source); |
| 9064 verify([source]); | 9073 verify([source]); |
| 9065 } | 9074 } |
| 9066 | 9075 |
| 9067 void test_invoke_dynamicThroughGetter() { | 9076 void test_invoke_dynamicThroughGetter() { |
| 9068 Source source = addSource(r''' | 9077 Source source = addSource(r''' |
| 9069 class A { | 9078 class A { |
| 9070 List get X => [() => 0]; | 9079 List get X => [() => 0]; |
| 9071 m(A a) { | 9080 m(A a) { |
| 9072 X.last; | 9081 X.last; |
| 9073 } | 9082 } |
| 9074 }'''); | 9083 }'''); |
| 9075 resolve(source); | 9084 computeLibrarySourceErrors(source); |
| 9076 assertNoErrors(source); | 9085 assertNoErrors(source); |
| 9077 verify([source]); | 9086 verify([source]); |
| 9078 } | 9087 } |
| 9079 | 9088 |
| 9080 void test_isValidMixin_badSuperclass() { | 9089 void test_isValidMixin_badSuperclass() { |
| 9081 Source source = addSource(r''' | 9090 Source source = addSource(r''' |
| 9082 class A extends B {} | 9091 class A extends B {} |
| 9083 class B {}'''); | 9092 class B {}'''); |
| 9084 LibraryElement library = resolve(source); | 9093 LibraryElement library = resolve2(source); |
| 9085 expect(library, isNotNull); | 9094 expect(library, isNotNull); |
| 9086 CompilationUnitElement unit = library.definingCompilationUnit; | 9095 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9087 expect(unit, isNotNull); | 9096 expect(unit, isNotNull); |
| 9088 List<ClassElement> classes = unit.types; | 9097 List<ClassElement> classes = unit.types; |
| 9089 expect(classes, hasLength(2)); | 9098 expect(classes, hasLength(2)); |
| 9090 expect(classes[0].isValidMixin, isFalse); | 9099 expect(classes[0].isValidMixin, isFalse); |
| 9091 assertNoErrors(source); | 9100 assertNoErrors(source); |
| 9092 verify([source]); | 9101 verify([source]); |
| 9093 } | 9102 } |
| 9094 | 9103 |
| 9095 void test_isValidMixin_constructor() { | 9104 void test_isValidMixin_constructor() { |
| 9096 Source source = addSource(r''' | 9105 Source source = addSource(r''' |
| 9097 class A { | 9106 class A { |
| 9098 A() {} | 9107 A() {} |
| 9099 }'''); | 9108 }'''); |
| 9100 LibraryElement library = resolve(source); | 9109 LibraryElement library = resolve2(source); |
| 9101 expect(library, isNotNull); | 9110 expect(library, isNotNull); |
| 9102 CompilationUnitElement unit = library.definingCompilationUnit; | 9111 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9103 expect(unit, isNotNull); | 9112 expect(unit, isNotNull); |
| 9104 List<ClassElement> classes = unit.types; | 9113 List<ClassElement> classes = unit.types; |
| 9105 expect(classes, hasLength(1)); | 9114 expect(classes, hasLength(1)); |
| 9106 expect(classes[0].isValidMixin, isFalse); | 9115 expect(classes[0].isValidMixin, isFalse); |
| 9107 assertNoErrors(source); | 9116 assertNoErrors(source); |
| 9108 verify([source]); | 9117 verify([source]); |
| 9109 } | 9118 } |
| 9110 | 9119 |
| 9111 void test_isValidMixin_super() { | 9120 void test_isValidMixin_super() { |
| 9112 Source source = addSource(r''' | 9121 Source source = addSource(r''' |
| 9113 class A { | 9122 class A { |
| 9114 toString() { | 9123 toString() { |
| 9115 return super.toString(); | 9124 return super.toString(); |
| 9116 } | 9125 } |
| 9117 }'''); | 9126 }'''); |
| 9118 LibraryElement library = resolve(source); | 9127 LibraryElement library = resolve2(source); |
| 9119 expect(library, isNotNull); | 9128 expect(library, isNotNull); |
| 9120 CompilationUnitElement unit = library.definingCompilationUnit; | 9129 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9121 expect(unit, isNotNull); | 9130 expect(unit, isNotNull); |
| 9122 List<ClassElement> classes = unit.types; | 9131 List<ClassElement> classes = unit.types; |
| 9123 expect(classes, hasLength(1)); | 9132 expect(classes, hasLength(1)); |
| 9124 expect(classes[0].isValidMixin, isFalse); | 9133 expect(classes[0].isValidMixin, isFalse); |
| 9125 assertNoErrors(source); | 9134 assertNoErrors(source); |
| 9126 verify([source]); | 9135 verify([source]); |
| 9127 } | 9136 } |
| 9128 | 9137 |
| 9129 void test_isValidMixin_valid() { | 9138 void test_isValidMixin_valid() { |
| 9130 Source source = addSource("class A {}"); | 9139 Source source = addSource("class A {}"); |
| 9131 LibraryElement library = resolve(source); | 9140 LibraryElement library = resolve2(source); |
| 9132 expect(library, isNotNull); | 9141 expect(library, isNotNull); |
| 9133 CompilationUnitElement unit = library.definingCompilationUnit; | 9142 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9134 expect(unit, isNotNull); | 9143 expect(unit, isNotNull); |
| 9135 List<ClassElement> classes = unit.types; | 9144 List<ClassElement> classes = unit.types; |
| 9136 expect(classes, hasLength(1)); | 9145 expect(classes, hasLength(1)); |
| 9137 expect(classes[0].isValidMixin, isTrue); | 9146 expect(classes[0].isValidMixin, isTrue); |
| 9138 assertNoErrors(source); | 9147 assertNoErrors(source); |
| 9139 verify([source]); | 9148 verify([source]); |
| 9140 } | 9149 } |
| 9141 | 9150 |
| 9142 void test_labels_switch() { | 9151 void test_labels_switch() { |
| 9143 Source source = addSource(r''' | 9152 Source source = addSource(r''' |
| 9144 void doSwitch(int target) { | 9153 void doSwitch(int target) { |
| 9145 switch (target) { | 9154 switch (target) { |
| 9146 l0: case 0: | 9155 l0: case 0: |
| 9147 continue l1; | 9156 continue l1; |
| 9148 l1: case 1: | 9157 l1: case 1: |
| 9149 continue l0; | 9158 continue l0; |
| 9150 default: | 9159 default: |
| 9151 continue l1; | 9160 continue l1; |
| 9152 } | 9161 } |
| 9153 }'''); | 9162 }'''); |
| 9154 LibraryElement library = resolve(source); | 9163 LibraryElement library = resolve2(source); |
| 9155 expect(library, isNotNull); | 9164 expect(library, isNotNull); |
| 9156 assertNoErrors(source); | 9165 assertNoErrors(source); |
| 9157 verify([source]); | 9166 verify([source]); |
| 9158 } | 9167 } |
| 9159 | 9168 |
| 9160 void test_localVariable_types_invoked() { | 9169 void test_localVariable_types_invoked() { |
| 9161 Source source = addSource(r''' | 9170 Source source = addSource(r''' |
| 9162 const A = null; | 9171 const A = null; |
| 9163 main() { | 9172 main() { |
| 9164 var myVar = (int p) => 'foo'; | 9173 var myVar = (int p) => 'foo'; |
| 9165 myVar(42); | 9174 myVar(42); |
| 9166 }'''); | 9175 }'''); |
| 9167 LibraryElement library = resolve(source); | 9176 LibraryElement library = resolve2(source); |
| 9168 expect(library, isNotNull); | 9177 expect(library, isNotNull); |
| 9169 CompilationUnit unit = | 9178 CompilationUnit unit = |
| 9170 analysisContext.resolveCompilationUnit(source, library); | 9179 analysisContext.resolveCompilationUnit(source, library); |
| 9171 expect(unit, isNotNull); | 9180 expect(unit, isNotNull); |
| 9172 List<bool> found = [false]; | 9181 List<bool> found = [false]; |
| 9173 List<CaughtException> thrownException = new List<CaughtException>(1); | 9182 List<CaughtException> thrownException = new List<CaughtException>(1); |
| 9174 unit.accept(new _SimpleResolverTest_localVariable_types_invoked( | 9183 unit.accept(new _SimpleResolverTest_localVariable_types_invoked( |
| 9175 this, found, thrownException)); | 9184 this, found, thrownException)); |
| 9176 if (thrownException[0] != null) { | 9185 if (thrownException[0] != null) { |
| 9177 throw new AnalysisException( | 9186 throw new AnalysisException( |
| 9178 "Exception", new CaughtException(thrownException[0], null)); | 9187 "Exception", new CaughtException(thrownException[0], null)); |
| 9179 } | 9188 } |
| 9180 expect(found[0], isTrue); | 9189 expect(found[0], isTrue); |
| 9181 } | 9190 } |
| 9182 | 9191 |
| 9183 void test_metadata_class() { | 9192 void test_metadata_class() { |
| 9184 Source source = addSource(r''' | 9193 Source source = addSource(r''' |
| 9185 const A = null; | 9194 const A = null; |
| 9186 @A class C<A> {}'''); | 9195 @A class C<A> {}'''); |
| 9187 LibraryElement library = resolve(source); | 9196 LibraryElement library = resolve2(source); |
| 9188 expect(library, isNotNull); | 9197 expect(library, isNotNull); |
| 9189 CompilationUnitElement unitElement = library.definingCompilationUnit; | 9198 CompilationUnitElement unitElement = library.definingCompilationUnit; |
| 9190 expect(unitElement, isNotNull); | 9199 expect(unitElement, isNotNull); |
| 9191 List<ClassElement> classes = unitElement.types; | 9200 List<ClassElement> classes = unitElement.types; |
| 9192 expect(classes, hasLength(1)); | 9201 expect(classes, hasLength(1)); |
| 9193 List<ElementAnnotation> annotations = classes[0].metadata; | 9202 List<ElementAnnotation> annotations = classes[0].metadata; |
| 9194 expect(annotations, hasLength(1)); | 9203 expect(annotations, hasLength(1)); |
| 9195 assertNoErrors(source); | 9204 assertNoErrors(source); |
| 9196 verify([source]); | 9205 verify([source]); |
| 9197 CompilationUnit unit = resolveCompilationUnit(source, library); | 9206 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9198 NodeList<CompilationUnitMember> declarations = unit.declarations; | 9207 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 9199 expect(declarations, hasLength(2)); | 9208 expect(declarations, hasLength(2)); |
| 9200 Element expectedElement = (declarations[ | 9209 Element expectedElement = (declarations[ |
| 9201 0] as TopLevelVariableDeclaration).variables.variables[ | 9210 0] as TopLevelVariableDeclaration).variables.variables[ |
| 9202 0].name.staticElement; | 9211 0].name.staticElement; |
| 9203 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, | 9212 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, |
| 9204 PropertyInducingElement, expectedElement); | 9213 PropertyInducingElement, expectedElement); |
| 9205 expectedElement = (expectedElement as PropertyInducingElement).getter; | 9214 expectedElement = (expectedElement as PropertyInducingElement).getter; |
| 9206 Element actualElement = | 9215 Element actualElement = |
| 9207 (declarations[1] as ClassDeclaration).metadata[0].name.staticElement; | 9216 (declarations[1] as ClassDeclaration).metadata[0].name.staticElement; |
| 9208 expect(actualElement, same(expectedElement)); | 9217 expect(actualElement, same(expectedElement)); |
| 9209 } | 9218 } |
| 9210 | 9219 |
| 9211 void test_metadata_field() { | 9220 void test_metadata_field() { |
| 9212 Source source = addSource(r''' | 9221 Source source = addSource(r''' |
| 9213 const A = null; | 9222 const A = null; |
| 9214 class C { | 9223 class C { |
| 9215 @A int f; | 9224 @A int f; |
| 9216 }'''); | 9225 }'''); |
| 9217 LibraryElement library = resolve(source); | 9226 LibraryElement library = resolve2(source); |
| 9218 expect(library, isNotNull); | 9227 expect(library, isNotNull); |
| 9219 CompilationUnitElement unit = library.definingCompilationUnit; | 9228 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9220 expect(unit, isNotNull); | 9229 expect(unit, isNotNull); |
| 9221 List<ClassElement> classes = unit.types; | 9230 List<ClassElement> classes = unit.types; |
| 9222 expect(classes, hasLength(1)); | 9231 expect(classes, hasLength(1)); |
| 9223 FieldElement field = classes[0].fields[0]; | 9232 FieldElement field = classes[0].fields[0]; |
| 9224 List<ElementAnnotation> annotations = field.metadata; | 9233 List<ElementAnnotation> annotations = field.metadata; |
| 9225 expect(annotations, hasLength(1)); | 9234 expect(annotations, hasLength(1)); |
| 9226 assertNoErrors(source); | 9235 assertNoErrors(source); |
| 9227 verify([source]); | 9236 verify([source]); |
| 9228 } | 9237 } |
| 9229 | 9238 |
| 9230 void test_metadata_fieldFormalParameter() { | 9239 void test_metadata_fieldFormalParameter() { |
| 9231 Source source = addSource(r''' | 9240 Source source = addSource(r''' |
| 9232 const A = null; | 9241 const A = null; |
| 9233 class C { | 9242 class C { |
| 9234 int f; | 9243 int f; |
| 9235 C(@A this.f); | 9244 C(@A this.f); |
| 9236 }'''); | 9245 }'''); |
| 9237 LibraryElement library = resolve(source); | 9246 LibraryElement library = resolve2(source); |
| 9238 expect(library, isNotNull); | 9247 expect(library, isNotNull); |
| 9239 CompilationUnitElement unit = library.definingCompilationUnit; | 9248 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9240 expect(unit, isNotNull); | 9249 expect(unit, isNotNull); |
| 9241 List<ClassElement> classes = unit.types; | 9250 List<ClassElement> classes = unit.types; |
| 9242 expect(classes, hasLength(1)); | 9251 expect(classes, hasLength(1)); |
| 9243 List<ConstructorElement> constructors = classes[0].constructors; | 9252 List<ConstructorElement> constructors = classes[0].constructors; |
| 9244 expect(constructors, hasLength(1)); | 9253 expect(constructors, hasLength(1)); |
| 9245 List<ParameterElement> parameters = constructors[0].parameters; | 9254 List<ParameterElement> parameters = constructors[0].parameters; |
| 9246 expect(parameters, hasLength(1)); | 9255 expect(parameters, hasLength(1)); |
| 9247 List<ElementAnnotation> annotations = parameters[0].metadata; | 9256 List<ElementAnnotation> annotations = parameters[0].metadata; |
| 9248 expect(annotations, hasLength(1)); | 9257 expect(annotations, hasLength(1)); |
| 9249 assertNoErrors(source); | 9258 assertNoErrors(source); |
| 9250 verify([source]); | 9259 verify([source]); |
| 9251 } | 9260 } |
| 9252 | 9261 |
| 9253 void test_metadata_function() { | 9262 void test_metadata_function() { |
| 9254 Source source = addSource(r''' | 9263 Source source = addSource(r''' |
| 9255 const A = null; | 9264 const A = null; |
| 9256 @A f() {}'''); | 9265 @A f() {}'''); |
| 9257 LibraryElement library = resolve(source); | 9266 LibraryElement library = resolve2(source); |
| 9258 expect(library, isNotNull); | 9267 expect(library, isNotNull); |
| 9259 CompilationUnitElement unit = library.definingCompilationUnit; | 9268 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9260 expect(unit, isNotNull); | 9269 expect(unit, isNotNull); |
| 9261 List<FunctionElement> functions = unit.functions; | 9270 List<FunctionElement> functions = unit.functions; |
| 9262 expect(functions, hasLength(1)); | 9271 expect(functions, hasLength(1)); |
| 9263 List<ElementAnnotation> annotations = functions[0].metadata; | 9272 List<ElementAnnotation> annotations = functions[0].metadata; |
| 9264 expect(annotations, hasLength(1)); | 9273 expect(annotations, hasLength(1)); |
| 9265 assertNoErrors(source); | 9274 assertNoErrors(source); |
| 9266 verify([source]); | 9275 verify([source]); |
| 9267 } | 9276 } |
| 9268 | 9277 |
| 9269 void test_metadata_functionTypedParameter() { | 9278 void test_metadata_functionTypedParameter() { |
| 9270 Source source = addSource(r''' | 9279 Source source = addSource(r''' |
| 9271 const A = null; | 9280 const A = null; |
| 9272 f(@A int p(int x)) {}'''); | 9281 f(@A int p(int x)) {}'''); |
| 9273 LibraryElement library = resolve(source); | 9282 LibraryElement library = resolve2(source); |
| 9274 expect(library, isNotNull); | 9283 expect(library, isNotNull); |
| 9275 CompilationUnitElement unit = library.definingCompilationUnit; | 9284 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9276 expect(unit, isNotNull); | 9285 expect(unit, isNotNull); |
| 9277 List<FunctionElement> functions = unit.functions; | 9286 List<FunctionElement> functions = unit.functions; |
| 9278 expect(functions, hasLength(1)); | 9287 expect(functions, hasLength(1)); |
| 9279 List<ParameterElement> parameters = functions[0].parameters; | 9288 List<ParameterElement> parameters = functions[0].parameters; |
| 9280 expect(parameters, hasLength(1)); | 9289 expect(parameters, hasLength(1)); |
| 9281 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 9290 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 9282 expect(annotations1, hasLength(1)); | 9291 expect(annotations1, hasLength(1)); |
| 9283 assertNoErrors(source); | 9292 assertNoErrors(source); |
| 9284 verify([source]); | 9293 verify([source]); |
| 9285 } | 9294 } |
| 9286 | 9295 |
| 9287 void test_metadata_libraryDirective() { | 9296 void test_metadata_libraryDirective() { |
| 9288 Source source = addSource(r''' | 9297 Source source = addSource(r''' |
| 9289 @A library lib; | 9298 @A library lib; |
| 9290 const A = null;'''); | 9299 const A = null;'''); |
| 9291 LibraryElement library = resolve(source); | 9300 LibraryElement library = resolve2(source); |
| 9292 expect(library, isNotNull); | 9301 expect(library, isNotNull); |
| 9293 List<ElementAnnotation> annotations = library.metadata; | 9302 List<ElementAnnotation> annotations = library.metadata; |
| 9294 expect(annotations, hasLength(1)); | 9303 expect(annotations, hasLength(1)); |
| 9295 assertNoErrors(source); | 9304 assertNoErrors(source); |
| 9296 verify([source]); | 9305 verify([source]); |
| 9297 } | 9306 } |
| 9298 | 9307 |
| 9299 void test_metadata_method() { | 9308 void test_metadata_method() { |
| 9300 Source source = addSource(r''' | 9309 Source source = addSource(r''' |
| 9301 const A = null; | 9310 const A = null; |
| 9302 class C { | 9311 class C { |
| 9303 @A void m() {} | 9312 @A void m() {} |
| 9304 }'''); | 9313 }'''); |
| 9305 LibraryElement library = resolve(source); | 9314 LibraryElement library = resolve2(source); |
| 9306 expect(library, isNotNull); | 9315 expect(library, isNotNull); |
| 9307 CompilationUnitElement unit = library.definingCompilationUnit; | 9316 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9308 expect(unit, isNotNull); | 9317 expect(unit, isNotNull); |
| 9309 List<ClassElement> classes = unit.types; | 9318 List<ClassElement> classes = unit.types; |
| 9310 expect(classes, hasLength(1)); | 9319 expect(classes, hasLength(1)); |
| 9311 MethodElement method = classes[0].methods[0]; | 9320 MethodElement method = classes[0].methods[0]; |
| 9312 List<ElementAnnotation> annotations = method.metadata; | 9321 List<ElementAnnotation> annotations = method.metadata; |
| 9313 expect(annotations, hasLength(1)); | 9322 expect(annotations, hasLength(1)); |
| 9314 assertNoErrors(source); | 9323 assertNoErrors(source); |
| 9315 verify([source]); | 9324 verify([source]); |
| 9316 } | 9325 } |
| 9317 | 9326 |
| 9318 void test_metadata_namedParameter() { | 9327 void test_metadata_namedParameter() { |
| 9319 Source source = addSource(r''' | 9328 Source source = addSource(r''' |
| 9320 const A = null; | 9329 const A = null; |
| 9321 f({@A int p : 0}) {}'''); | 9330 f({@A int p : 0}) {}'''); |
| 9322 LibraryElement library = resolve(source); | 9331 LibraryElement library = resolve2(source); |
| 9323 expect(library, isNotNull); | 9332 expect(library, isNotNull); |
| 9324 CompilationUnitElement unit = library.definingCompilationUnit; | 9333 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9325 expect(unit, isNotNull); | 9334 expect(unit, isNotNull); |
| 9326 List<FunctionElement> functions = unit.functions; | 9335 List<FunctionElement> functions = unit.functions; |
| 9327 expect(functions, hasLength(1)); | 9336 expect(functions, hasLength(1)); |
| 9328 List<ParameterElement> parameters = functions[0].parameters; | 9337 List<ParameterElement> parameters = functions[0].parameters; |
| 9329 expect(parameters, hasLength(1)); | 9338 expect(parameters, hasLength(1)); |
| 9330 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 9339 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 9331 expect(annotations1, hasLength(1)); | 9340 expect(annotations1, hasLength(1)); |
| 9332 assertNoErrors(source); | 9341 assertNoErrors(source); |
| 9333 verify([source]); | 9342 verify([source]); |
| 9334 } | 9343 } |
| 9335 | 9344 |
| 9336 void test_metadata_positionalParameter() { | 9345 void test_metadata_positionalParameter() { |
| 9337 Source source = addSource(r''' | 9346 Source source = addSource(r''' |
| 9338 const A = null; | 9347 const A = null; |
| 9339 f([@A int p = 0]) {}'''); | 9348 f([@A int p = 0]) {}'''); |
| 9340 LibraryElement library = resolve(source); | 9349 LibraryElement library = resolve2(source); |
| 9341 expect(library, isNotNull); | 9350 expect(library, isNotNull); |
| 9342 CompilationUnitElement unit = library.definingCompilationUnit; | 9351 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9343 expect(unit, isNotNull); | 9352 expect(unit, isNotNull); |
| 9344 List<FunctionElement> functions = unit.functions; | 9353 List<FunctionElement> functions = unit.functions; |
| 9345 expect(functions, hasLength(1)); | 9354 expect(functions, hasLength(1)); |
| 9346 List<ParameterElement> parameters = functions[0].parameters; | 9355 List<ParameterElement> parameters = functions[0].parameters; |
| 9347 expect(parameters, hasLength(1)); | 9356 expect(parameters, hasLength(1)); |
| 9348 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 9357 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 9349 expect(annotations1, hasLength(1)); | 9358 expect(annotations1, hasLength(1)); |
| 9350 assertNoErrors(source); | 9359 assertNoErrors(source); |
| 9351 verify([source]); | 9360 verify([source]); |
| 9352 } | 9361 } |
| 9353 | 9362 |
| 9354 void test_metadata_simpleParameter() { | 9363 void test_metadata_simpleParameter() { |
| 9355 Source source = addSource(r''' | 9364 Source source = addSource(r''' |
| 9356 const A = null; | 9365 const A = null; |
| 9357 f(@A p1, @A int p2) {}'''); | 9366 f(@A p1, @A int p2) {}'''); |
| 9358 LibraryElement library = resolve(source); | 9367 LibraryElement library = resolve2(source); |
| 9359 expect(library, isNotNull); | 9368 expect(library, isNotNull); |
| 9360 CompilationUnitElement unit = library.definingCompilationUnit; | 9369 CompilationUnitElement unit = library.definingCompilationUnit; |
| 9361 expect(unit, isNotNull); | 9370 expect(unit, isNotNull); |
| 9362 List<FunctionElement> functions = unit.functions; | 9371 List<FunctionElement> functions = unit.functions; |
| 9363 expect(functions, hasLength(1)); | 9372 expect(functions, hasLength(1)); |
| 9364 List<ParameterElement> parameters = functions[0].parameters; | 9373 List<ParameterElement> parameters = functions[0].parameters; |
| 9365 expect(parameters, hasLength(2)); | 9374 expect(parameters, hasLength(2)); |
| 9366 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 9375 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 9367 expect(annotations1, hasLength(1)); | 9376 expect(annotations1, hasLength(1)); |
| 9368 List<ElementAnnotation> annotations2 = parameters[1].metadata; | 9377 List<ElementAnnotation> annotations2 = parameters[1].metadata; |
| 9369 expect(annotations2, hasLength(1)); | 9378 expect(annotations2, hasLength(1)); |
| 9370 assertNoErrors(source); | 9379 assertNoErrors(source); |
| 9371 verify([source]); | 9380 verify([source]); |
| 9372 } | 9381 } |
| 9373 | 9382 |
| 9374 void test_metadata_typedef() { | 9383 void test_metadata_typedef() { |
| 9375 Source source = addSource(r''' | 9384 Source source = addSource(r''' |
| 9376 const A = null; | 9385 const A = null; |
| 9377 @A typedef F<A>();'''); | 9386 @A typedef F<A>();'''); |
| 9378 LibraryElement library = resolve(source); | 9387 LibraryElement library = resolve2(source); |
| 9379 expect(library, isNotNull); | 9388 expect(library, isNotNull); |
| 9380 CompilationUnitElement unitElement = library.definingCompilationUnit; | 9389 CompilationUnitElement unitElement = library.definingCompilationUnit; |
| 9381 expect(unitElement, isNotNull); | 9390 expect(unitElement, isNotNull); |
| 9382 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; | 9391 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; |
| 9383 expect(aliases, hasLength(1)); | 9392 expect(aliases, hasLength(1)); |
| 9384 List<ElementAnnotation> annotations = aliases[0].metadata; | 9393 List<ElementAnnotation> annotations = aliases[0].metadata; |
| 9385 expect(annotations, hasLength(1)); | 9394 expect(annotations, hasLength(1)); |
| 9386 assertNoErrors(source); | 9395 assertNoErrors(source); |
| 9387 verify([source]); | 9396 verify([source]); |
| 9388 CompilationUnit unit = resolveCompilationUnit(source, library); | 9397 CompilationUnit unit = resolveCompilationUnit(source, library); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 9405 bar() => 1; | 9414 bar() => 1; |
| 9406 } | 9415 } |
| 9407 class A { | 9416 class A { |
| 9408 foo() => 2; | 9417 foo() => 2; |
| 9409 } | 9418 } |
| 9410 | 9419 |
| 9411 class C extends B with A { | 9420 class C extends B with A { |
| 9412 bar() => super.bar(); | 9421 bar() => super.bar(); |
| 9413 foo() => super.foo(); | 9422 foo() => super.foo(); |
| 9414 }'''); | 9423 }'''); |
| 9415 resolve(source); | 9424 computeLibrarySourceErrors(source); |
| 9416 assertNoErrors(source); | 9425 assertNoErrors(source); |
| 9417 verify([source]); | 9426 verify([source]); |
| 9418 } | 9427 } |
| 9419 | 9428 |
| 9420 void test_method_fromMixins() { | 9429 void test_method_fromMixins() { |
| 9421 Source source = addSource(''' | 9430 Source source = addSource(''' |
| 9422 class B {} | 9431 class B {} |
| 9423 class M1 { | 9432 class M1 { |
| 9424 void f() {} | 9433 void f() {} |
| 9425 } | 9434 } |
| 9426 class M2 { | 9435 class M2 { |
| 9427 void f() {} | 9436 void f() {} |
| 9428 } | 9437 } |
| 9429 class C extends B with M1, M2 {} | 9438 class C extends B with M1, M2 {} |
| 9430 void main() { | 9439 void main() { |
| 9431 new C().f(); | 9440 new C().f(); |
| 9432 } | 9441 } |
| 9433 '''); | 9442 '''); |
| 9434 LibraryElement library = resolve(source); | 9443 LibraryElement library = resolve2(source); |
| 9435 assertNoErrors(source); | 9444 assertNoErrors(source); |
| 9436 verify([source]); | 9445 verify([source]); |
| 9437 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2. | 9446 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2. |
| 9438 FunctionDeclaration main = | 9447 FunctionDeclaration main = |
| 9439 library.definingCompilationUnit.functions[0].computeNode(); | 9448 library.definingCompilationUnit.functions[0].computeNode(); |
| 9440 BlockFunctionBody body = main.functionExpression.body; | 9449 BlockFunctionBody body = main.functionExpression.body; |
| 9441 ExpressionStatement stmt = body.block.statements[0]; | 9450 ExpressionStatement stmt = body.block.statements[0]; |
| 9442 MethodInvocation expr = stmt.expression; | 9451 MethodInvocation expr = stmt.expression; |
| 9443 expect(expr.methodName.staticElement.enclosingElement.name, 'M2'); | 9452 expect(expr.methodName.staticElement.enclosingElement.name, 'M2'); |
| 9444 } | 9453 } |
| 9445 | 9454 |
| 9446 void test_method_fromMixins_bare_identifier() { | 9455 void test_method_fromMixins_bare_identifier() { |
| 9447 Source source = addSource(''' | 9456 Source source = addSource(''' |
| 9448 class B {} | 9457 class B {} |
| 9449 class M1 { | 9458 class M1 { |
| 9450 void f() {} | 9459 void f() {} |
| 9451 } | 9460 } |
| 9452 class M2 { | 9461 class M2 { |
| 9453 void f() {} | 9462 void f() {} |
| 9454 } | 9463 } |
| 9455 class C extends B with M1, M2 { | 9464 class C extends B with M1, M2 { |
| 9456 void g() { | 9465 void g() { |
| 9457 f(); | 9466 f(); |
| 9458 } | 9467 } |
| 9459 } | 9468 } |
| 9460 '''); | 9469 '''); |
| 9461 LibraryElement library = resolve(source); | 9470 LibraryElement library = resolve2(source); |
| 9462 assertNoErrors(source); | 9471 assertNoErrors(source); |
| 9463 verify([source]); | 9472 verify([source]); |
| 9464 // Verify that the call to f() in C.g() refers to the method defined in M2. | 9473 // Verify that the call to f() in C.g() refers to the method defined in M2. |
| 9465 ClassElement classC = library.definingCompilationUnit.types[3]; | 9474 ClassElement classC = library.definingCompilationUnit.types[3]; |
| 9466 MethodDeclaration g = classC.getMethod('g').computeNode(); | 9475 MethodDeclaration g = classC.getMethod('g').computeNode(); |
| 9467 BlockFunctionBody body = g.body; | 9476 BlockFunctionBody body = g.body; |
| 9468 ExpressionStatement stmt = body.block.statements[0]; | 9477 ExpressionStatement stmt = body.block.statements[0]; |
| 9469 MethodInvocation invocation = stmt.expression; | 9478 MethodInvocation invocation = stmt.expression; |
| 9470 SimpleIdentifier methodName = invocation.methodName; | 9479 SimpleIdentifier methodName = invocation.methodName; |
| 9471 expect(methodName.staticElement.enclosingElement.name, 'M2'); | 9480 expect(methodName.staticElement.enclosingElement.name, 'M2'); |
| 9472 } | 9481 } |
| 9473 | 9482 |
| 9474 void test_method_fromMixins_invked_from_outside_class() { | 9483 void test_method_fromMixins_invked_from_outside_class() { |
| 9475 Source source = addSource(''' | 9484 Source source = addSource(''' |
| 9476 class B {} | 9485 class B {} |
| 9477 class M1 { | 9486 class M1 { |
| 9478 void f() {} | 9487 void f() {} |
| 9479 } | 9488 } |
| 9480 class M2 { | 9489 class M2 { |
| 9481 void f() {} | 9490 void f() {} |
| 9482 } | 9491 } |
| 9483 class C extends B with M1, M2 {} | 9492 class C extends B with M1, M2 {} |
| 9484 void main() { | 9493 void main() { |
| 9485 new C().f(); | 9494 new C().f(); |
| 9486 } | 9495 } |
| 9487 '''); | 9496 '''); |
| 9488 LibraryElement library = resolve(source); | 9497 LibraryElement library = resolve2(source); |
| 9489 assertNoErrors(source); | 9498 assertNoErrors(source); |
| 9490 verify([source]); | 9499 verify([source]); |
| 9491 // Verify that the call to f() in "new C().f()" refers to the method | 9500 // Verify that the call to f() in "new C().f()" refers to the method |
| 9492 // defined in M2. | 9501 // defined in M2. |
| 9493 FunctionDeclaration main = | 9502 FunctionDeclaration main = |
| 9494 library.definingCompilationUnit.functions[0].computeNode(); | 9503 library.definingCompilationUnit.functions[0].computeNode(); |
| 9495 BlockFunctionBody body = main.functionExpression.body; | 9504 BlockFunctionBody body = main.functionExpression.body; |
| 9496 ExpressionStatement stmt = body.block.statements[0]; | 9505 ExpressionStatement stmt = body.block.statements[0]; |
| 9497 MethodInvocation invocation = stmt.expression; | 9506 MethodInvocation invocation = stmt.expression; |
| 9498 expect(invocation.methodName.staticElement.enclosingElement.name, 'M2'); | 9507 expect(invocation.methodName.staticElement.enclosingElement.name, 'M2'); |
| 9499 } | 9508 } |
| 9500 | 9509 |
| 9501 void test_method_fromSuperclassMixin() { | 9510 void test_method_fromSuperclassMixin() { |
| 9502 Source source = addSource(r''' | 9511 Source source = addSource(r''' |
| 9503 class A { | 9512 class A { |
| 9504 void m1() {} | 9513 void m1() {} |
| 9505 } | 9514 } |
| 9506 class B extends Object with A { | 9515 class B extends Object with A { |
| 9507 } | 9516 } |
| 9508 class C extends B { | 9517 class C extends B { |
| 9509 } | 9518 } |
| 9510 f(C c) { | 9519 f(C c) { |
| 9511 c.m1(); | 9520 c.m1(); |
| 9512 }'''); | 9521 }'''); |
| 9513 resolve(source); | 9522 computeLibrarySourceErrors(source); |
| 9514 assertNoErrors(source); | 9523 assertNoErrors(source); |
| 9515 verify([source]); | 9524 verify([source]); |
| 9516 } | 9525 } |
| 9517 | 9526 |
| 9518 void test_methodCascades() { | 9527 void test_methodCascades() { |
| 9519 Source source = addSource(r''' | 9528 Source source = addSource(r''' |
| 9520 class A { | 9529 class A { |
| 9521 void m1() {} | 9530 void m1() {} |
| 9522 void m2() {} | 9531 void m2() {} |
| 9523 void m() { | 9532 void m() { |
| 9524 A a = new A(); | 9533 A a = new A(); |
| 9525 a..m1() | 9534 a..m1() |
| 9526 ..m2(); | 9535 ..m2(); |
| 9527 } | 9536 } |
| 9528 }'''); | 9537 }'''); |
| 9529 resolve(source); | 9538 computeLibrarySourceErrors(source); |
| 9530 assertNoErrors(source); | 9539 assertNoErrors(source); |
| 9531 verify([source]); | 9540 verify([source]); |
| 9532 } | 9541 } |
| 9533 | 9542 |
| 9534 void test_methodCascades_withSetter() { | 9543 void test_methodCascades_withSetter() { |
| 9535 Source source = addSource(r''' | 9544 Source source = addSource(r''' |
| 9536 class A { | 9545 class A { |
| 9537 String name; | 9546 String name; |
| 9538 void m1() {} | 9547 void m1() {} |
| 9539 void m2() {} | 9548 void m2() {} |
| 9540 void m() { | 9549 void m() { |
| 9541 A a = new A(); | 9550 A a = new A(); |
| 9542 a..m1() | 9551 a..m1() |
| 9543 ..name = 'name' | 9552 ..name = 'name' |
| 9544 ..m2(); | 9553 ..m2(); |
| 9545 } | 9554 } |
| 9546 }'''); | 9555 }'''); |
| 9547 resolve(source); | 9556 computeLibrarySourceErrors(source); |
| 9548 // failing with error code: INVOCATION_OF_NON_FUNCTION | 9557 // failing with error code: INVOCATION_OF_NON_FUNCTION |
| 9549 assertNoErrors(source); | 9558 assertNoErrors(source); |
| 9550 verify([source]); | 9559 verify([source]); |
| 9551 } | 9560 } |
| 9552 | 9561 |
| 9553 void test_resolveAgainstNull() { | 9562 void test_resolveAgainstNull() { |
| 9554 Source source = addSource(r''' | 9563 Source source = addSource(r''' |
| 9555 f(var p) { | 9564 f(var p) { |
| 9556 return null == p; | 9565 return null == p; |
| 9557 }'''); | 9566 }'''); |
| 9558 resolve(source); | 9567 computeLibrarySourceErrors(source); |
| 9559 assertNoErrors(source); | 9568 assertNoErrors(source); |
| 9560 } | 9569 } |
| 9561 | 9570 |
| 9562 void test_setter_fromMixins_bare_identifier() { | 9571 void test_setter_fromMixins_bare_identifier() { |
| 9563 Source source = addSource(''' | 9572 Source source = addSource(''' |
| 9564 class B {} | 9573 class B {} |
| 9565 class M1 { | 9574 class M1 { |
| 9566 set x(value) {} | 9575 set x(value) {} |
| 9567 } | 9576 } |
| 9568 class M2 { | 9577 class M2 { |
| 9569 set x(value) {} | 9578 set x(value) {} |
| 9570 } | 9579 } |
| 9571 class C extends B with M1, M2 { | 9580 class C extends B with M1, M2 { |
| 9572 void f() { | 9581 void f() { |
| 9573 x = 1; | 9582 x = 1; |
| 9574 } | 9583 } |
| 9575 } | 9584 } |
| 9576 '''); | 9585 '''); |
| 9577 LibraryElement library = resolve(source); | 9586 LibraryElement library = resolve2(source); |
| 9578 assertNoErrors(source); | 9587 assertNoErrors(source); |
| 9579 verify([source]); | 9588 verify([source]); |
| 9580 // Verify that the setter for "x" in C.f() refers to the setter defined in | 9589 // Verify that the setter for "x" in C.f() refers to the setter defined in |
| 9581 // M2. | 9590 // M2. |
| 9582 ClassElement classC = library.definingCompilationUnit.types[3]; | 9591 ClassElement classC = library.definingCompilationUnit.types[3]; |
| 9583 MethodDeclaration f = classC.getMethod('f').computeNode(); | 9592 MethodDeclaration f = classC.getMethod('f').computeNode(); |
| 9584 BlockFunctionBody body = f.body; | 9593 BlockFunctionBody body = f.body; |
| 9585 ExpressionStatement stmt = body.block.statements[0]; | 9594 ExpressionStatement stmt = body.block.statements[0]; |
| 9586 AssignmentExpression assignment = stmt.expression; | 9595 AssignmentExpression assignment = stmt.expression; |
| 9587 SimpleIdentifier leftHandSide = assignment.leftHandSide; | 9596 SimpleIdentifier leftHandSide = assignment.leftHandSide; |
| 9588 expect(leftHandSide.staticElement.enclosingElement.name, 'M2'); | 9597 expect(leftHandSide.staticElement.enclosingElement.name, 'M2'); |
| 9589 } | 9598 } |
| 9590 | 9599 |
| 9591 void test_setter_fromMixins_property_access() { | 9600 void test_setter_fromMixins_property_access() { |
| 9592 Source source = addSource(''' | 9601 Source source = addSource(''' |
| 9593 class B {} | 9602 class B {} |
| 9594 class M1 { | 9603 class M1 { |
| 9595 set x(value) {} | 9604 set x(value) {} |
| 9596 } | 9605 } |
| 9597 class M2 { | 9606 class M2 { |
| 9598 set x(value) {} | 9607 set x(value) {} |
| 9599 } | 9608 } |
| 9600 class C extends B with M1, M2 {} | 9609 class C extends B with M1, M2 {} |
| 9601 void main() { | 9610 void main() { |
| 9602 new C().x = 1; | 9611 new C().x = 1; |
| 9603 } | 9612 } |
| 9604 '''); | 9613 '''); |
| 9605 LibraryElement library = resolve(source); | 9614 LibraryElement library = resolve2(source); |
| 9606 assertNoErrors(source); | 9615 assertNoErrors(source); |
| 9607 verify([source]); | 9616 verify([source]); |
| 9608 // Verify that the setter for "x" in "new C().x" refers to the setter | 9617 // Verify that the setter for "x" in "new C().x" refers to the setter |
| 9609 // defined in M2. | 9618 // defined in M2. |
| 9610 FunctionDeclaration main = | 9619 FunctionDeclaration main = |
| 9611 library.definingCompilationUnit.functions[0].computeNode(); | 9620 library.definingCompilationUnit.functions[0].computeNode(); |
| 9612 BlockFunctionBody body = main.functionExpression.body; | 9621 BlockFunctionBody body = main.functionExpression.body; |
| 9613 ExpressionStatement stmt = body.block.statements[0]; | 9622 ExpressionStatement stmt = body.block.statements[0]; |
| 9614 AssignmentExpression assignment = stmt.expression; | 9623 AssignmentExpression assignment = stmt.expression; |
| 9615 PropertyAccess propertyAccess = assignment.leftHandSide; | 9624 PropertyAccess propertyAccess = assignment.leftHandSide; |
| 9616 expect( | 9625 expect( |
| 9617 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); | 9626 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); |
| 9618 } | 9627 } |
| 9619 | 9628 |
| 9620 void test_setter_inherited() { | 9629 void test_setter_inherited() { |
| 9621 Source source = addSource(r''' | 9630 Source source = addSource(r''' |
| 9622 class A { | 9631 class A { |
| 9623 int get x => 0; | 9632 int get x => 0; |
| 9624 set x(int p) {} | 9633 set x(int p) {} |
| 9625 } | 9634 } |
| 9626 class B extends A { | 9635 class B extends A { |
| 9627 int get x => super.x == null ? 0 : super.x; | 9636 int get x => super.x == null ? 0 : super.x; |
| 9628 int f() => x = 1; | 9637 int f() => x = 1; |
| 9629 }'''); | 9638 }'''); |
| 9630 resolve(source); | 9639 computeLibrarySourceErrors(source); |
| 9631 assertNoErrors(source); | 9640 assertNoErrors(source); |
| 9632 verify([source]); | 9641 verify([source]); |
| 9633 } | 9642 } |
| 9634 | 9643 |
| 9635 void test_setter_static() { | 9644 void test_setter_static() { |
| 9636 Source source = addSource(r''' | 9645 Source source = addSource(r''' |
| 9637 set s(x) { | 9646 set s(x) { |
| 9638 } | 9647 } |
| 9639 | 9648 |
| 9640 main() { | 9649 main() { |
| 9641 s = 123; | 9650 s = 123; |
| 9642 }'''); | 9651 }'''); |
| 9643 resolve(source); | 9652 computeLibrarySourceErrors(source); |
| 9644 assertNoErrors(source); | 9653 assertNoErrors(source); |
| 9645 verify([source]); | 9654 verify([source]); |
| 9646 } | 9655 } |
| 9647 | 9656 |
| 9648 /** | 9657 /** |
| 9649 * Resolve the given source and verify that the arguments in a specific method
invocation were | 9658 * Resolve the given source and verify that the arguments in a specific method
invocation were |
| 9650 * correctly resolved. | 9659 * correctly resolved. |
| 9651 * | 9660 * |
| 9652 * The source is expected to be source for a compilation unit, the first decla
ration is expected | 9661 * The source is expected to be source for a compilation unit, the first decla
ration is expected |
| 9653 * to be a class, the first member of which is expected to be a method with a
block body, and the | 9662 * to be a class, the first member of which is expected to be a method with a
block body, and the |
| 9654 * first statement in the body is expected to be an expression statement whose
expression is a | 9663 * first statement in the body is expected to be an expression statement whose
expression is a |
| 9655 * method invocation. It is the arguments to that method invocation that are t
ested. The method | 9664 * method invocation. It is the arguments to that method invocation that are t
ested. The method |
| 9656 * invocation can contain errors. | 9665 * invocation can contain errors. |
| 9657 * | 9666 * |
| 9658 * The arguments were resolved correctly if the number of expressions in the l
ist matches the | 9667 * The arguments were resolved correctly if the number of expressions in the l
ist matches the |
| 9659 * length of the array of indices and if, for each index in the array of indic
es, the parameter to | 9668 * length of the array of indices and if, for each index in the array of indic
es, the parameter to |
| 9660 * which the argument expression was resolved is the parameter in the invoked
method's list of | 9669 * which the argument expression was resolved is the parameter in the invoked
method's list of |
| 9661 * parameters at that index. Arguments that should not be resolved to a parame
ter because of an | 9670 * parameters at that index. Arguments that should not be resolved to a parame
ter because of an |
| 9662 * error can be denoted by including a negative index in the array of indices. | 9671 * error can be denoted by including a negative index in the array of indices. |
| 9663 * | 9672 * |
| 9664 * @param source the source to be resolved | 9673 * @param source the source to be resolved |
| 9665 * @param indices the array of indices used to associate arguments with parame
ters | 9674 * @param indices the array of indices used to associate arguments with parame
ters |
| 9666 * @throws Exception if the source could not be resolved or if the structure o
f the source is not | 9675 * @throws Exception if the source could not be resolved or if the structure o
f the source is not |
| 9667 * valid | 9676 * valid |
| 9668 */ | 9677 */ |
| 9669 void _validateArgumentResolution(Source source, List<int> indices) { | 9678 void _validateArgumentResolution(Source source, List<int> indices) { |
| 9670 LibraryElement library = resolve(source); | 9679 LibraryElement library = resolve2(source); |
| 9671 expect(library, isNotNull); | 9680 expect(library, isNotNull); |
| 9672 ClassElement classElement = library.definingCompilationUnit.types[0]; | 9681 ClassElement classElement = library.definingCompilationUnit.types[0]; |
| 9673 List<ParameterElement> parameters = classElement.methods[1].parameters; | 9682 List<ParameterElement> parameters = classElement.methods[1].parameters; |
| 9674 CompilationUnit unit = resolveCompilationUnit(source, library); | 9683 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9675 expect(unit, isNotNull); | 9684 expect(unit, isNotNull); |
| 9676 ClassDeclaration classDeclaration = | 9685 ClassDeclaration classDeclaration = |
| 9677 unit.declarations[0] as ClassDeclaration; | 9686 unit.declarations[0] as ClassDeclaration; |
| 9678 MethodDeclaration methodDeclaration = | 9687 MethodDeclaration methodDeclaration = |
| 9679 classDeclaration.members[0] as MethodDeclaration; | 9688 classDeclaration.members[0] as MethodDeclaration; |
| 9680 Block block = (methodDeclaration.body as BlockFunctionBody).block; | 9689 Block block = (methodDeclaration.body as BlockFunctionBody).block; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9804 | 9813 |
| 9805 SimpleIdentifier _findIdentifier(String search) { | 9814 SimpleIdentifier _findIdentifier(String search) { |
| 9806 SimpleIdentifier identifier = EngineTestCase.findNode( | 9815 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 9807 testUnit, testCode, search, (node) => node is SimpleIdentifier); | 9816 testUnit, testCode, search, (node) => node is SimpleIdentifier); |
| 9808 return identifier; | 9817 return identifier; |
| 9809 } | 9818 } |
| 9810 | 9819 |
| 9811 void _resolveTestUnit(String code) { | 9820 void _resolveTestUnit(String code) { |
| 9812 testCode = code; | 9821 testCode = code; |
| 9813 testSource = addSource(testCode); | 9822 testSource = addSource(testCode); |
| 9814 LibraryElement library = resolve(testSource); | 9823 LibraryElement library = resolve2(testSource); |
| 9815 assertNoErrors(testSource); | 9824 assertNoErrors(testSource); |
| 9816 verify([testSource]); | 9825 verify([testSource]); |
| 9817 testUnit = resolveCompilationUnit(testSource, library); | 9826 testUnit = resolveCompilationUnit(testSource, library); |
| 9818 } | 9827 } |
| 9819 } | 9828 } |
| 9820 | 9829 |
| 9821 @reflectiveTest | 9830 @reflectiveTest |
| 9822 class StaticTypeAnalyzerTest extends EngineTestCase { | 9831 class StaticTypeAnalyzerTest extends EngineTestCase { |
| 9823 /** | 9832 /** |
| 9824 * The error listener to which errors will be reported. | 9833 * The error listener to which errors will be reported. |
| (...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11404 @reflectiveTest | 11413 @reflectiveTest |
| 11405 class StrictModeTest extends ResolverTestCase { | 11414 class StrictModeTest extends ResolverTestCase { |
| 11406 void fail_for() { | 11415 void fail_for() { |
| 11407 Source source = addSource(r''' | 11416 Source source = addSource(r''' |
| 11408 int f(List<int> list) { | 11417 int f(List<int> list) { |
| 11409 num sum = 0; | 11418 num sum = 0; |
| 11410 for (num i = 0; i < list.length; i++) { | 11419 for (num i = 0; i < list.length; i++) { |
| 11411 sum += list[i]; | 11420 sum += list[i]; |
| 11412 } | 11421 } |
| 11413 }'''); | 11422 }'''); |
| 11414 resolve(source); | 11423 computeLibrarySourceErrors(source); |
| 11415 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11424 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11416 } | 11425 } |
| 11417 | 11426 |
| 11418 @override | 11427 @override |
| 11419 void setUp() { | 11428 void setUp() { |
| 11420 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 11429 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 11421 options.hint = false; | 11430 options.hint = false; |
| 11422 resetWithOptions(options); | 11431 resetWithOptions(options); |
| 11423 } | 11432 } |
| 11424 | 11433 |
| 11425 void test_assert_is() { | 11434 void test_assert_is() { |
| 11426 Source source = addSource(r''' | 11435 Source source = addSource(r''' |
| 11427 int f(num n) { | 11436 int f(num n) { |
| 11428 assert (n is int); | 11437 assert (n is int); |
| 11429 return n & 0x0F; | 11438 return n & 0x0F; |
| 11430 }'''); | 11439 }'''); |
| 11431 resolve(source); | 11440 computeLibrarySourceErrors(source); |
| 11432 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11441 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11433 } | 11442 } |
| 11434 | 11443 |
| 11435 void test_conditional_and_is() { | 11444 void test_conditional_and_is() { |
| 11436 Source source = addSource(r''' | 11445 Source source = addSource(r''' |
| 11437 int f(num n) { | 11446 int f(num n) { |
| 11438 return (n is int && n > 0) ? n & 0x0F : 0; | 11447 return (n is int && n > 0) ? n & 0x0F : 0; |
| 11439 }'''); | 11448 }'''); |
| 11440 resolve(source); | 11449 computeLibrarySourceErrors(source); |
| 11441 assertNoErrors(source); | 11450 assertNoErrors(source); |
| 11442 } | 11451 } |
| 11443 | 11452 |
| 11444 void test_conditional_is() { | 11453 void test_conditional_is() { |
| 11445 Source source = addSource(r''' | 11454 Source source = addSource(r''' |
| 11446 int f(num n) { | 11455 int f(num n) { |
| 11447 return (n is int) ? n & 0x0F : 0; | 11456 return (n is int) ? n & 0x0F : 0; |
| 11448 }'''); | 11457 }'''); |
| 11449 resolve(source); | 11458 computeLibrarySourceErrors(source); |
| 11450 assertNoErrors(source); | 11459 assertNoErrors(source); |
| 11451 } | 11460 } |
| 11452 | 11461 |
| 11453 void test_conditional_isNot() { | 11462 void test_conditional_isNot() { |
| 11454 Source source = addSource(r''' | 11463 Source source = addSource(r''' |
| 11455 int f(num n) { | 11464 int f(num n) { |
| 11456 return (n is! int) ? 0 : n & 0x0F; | 11465 return (n is! int) ? 0 : n & 0x0F; |
| 11457 }'''); | 11466 }'''); |
| 11458 resolve(source); | 11467 computeLibrarySourceErrors(source); |
| 11459 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11468 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11460 } | 11469 } |
| 11461 | 11470 |
| 11462 void test_conditional_or_is() { | 11471 void test_conditional_or_is() { |
| 11463 Source source = addSource(r''' | 11472 Source source = addSource(r''' |
| 11464 int f(num n) { | 11473 int f(num n) { |
| 11465 return (n is! int || n < 0) ? 0 : n & 0x0F; | 11474 return (n is! int || n < 0) ? 0 : n & 0x0F; |
| 11466 }'''); | 11475 }'''); |
| 11467 resolve(source); | 11476 computeLibrarySourceErrors(source); |
| 11468 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11477 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11469 } | 11478 } |
| 11470 | 11479 |
| 11471 void test_forEach() { | 11480 void test_forEach() { |
| 11472 Source source = addSource(r''' | 11481 Source source = addSource(r''' |
| 11473 int f(List<int> list) { | 11482 int f(List<int> list) { |
| 11474 num sum = 0; | 11483 num sum = 0; |
| 11475 for (num n in list) { | 11484 for (num n in list) { |
| 11476 sum += n & 0x0F; | 11485 sum += n & 0x0F; |
| 11477 } | 11486 } |
| 11478 }'''); | 11487 }'''); |
| 11479 resolve(source); | 11488 computeLibrarySourceErrors(source); |
| 11480 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11489 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11481 } | 11490 } |
| 11482 | 11491 |
| 11483 void test_if_and_is() { | 11492 void test_if_and_is() { |
| 11484 Source source = addSource(r''' | 11493 Source source = addSource(r''' |
| 11485 int f(num n) { | 11494 int f(num n) { |
| 11486 if (n is int && n > 0) { | 11495 if (n is int && n > 0) { |
| 11487 return n & 0x0F; | 11496 return n & 0x0F; |
| 11488 } | 11497 } |
| 11489 return 0; | 11498 return 0; |
| 11490 }'''); | 11499 }'''); |
| 11491 resolve(source); | 11500 computeLibrarySourceErrors(source); |
| 11492 assertNoErrors(source); | 11501 assertNoErrors(source); |
| 11493 } | 11502 } |
| 11494 | 11503 |
| 11495 void test_if_is() { | 11504 void test_if_is() { |
| 11496 Source source = addSource(r''' | 11505 Source source = addSource(r''' |
| 11497 int f(num n) { | 11506 int f(num n) { |
| 11498 if (n is int) { | 11507 if (n is int) { |
| 11499 return n & 0x0F; | 11508 return n & 0x0F; |
| 11500 } | 11509 } |
| 11501 return 0; | 11510 return 0; |
| 11502 }'''); | 11511 }'''); |
| 11503 resolve(source); | 11512 computeLibrarySourceErrors(source); |
| 11504 assertNoErrors(source); | 11513 assertNoErrors(source); |
| 11505 } | 11514 } |
| 11506 | 11515 |
| 11507 void test_if_isNot() { | 11516 void test_if_isNot() { |
| 11508 Source source = addSource(r''' | 11517 Source source = addSource(r''' |
| 11509 int f(num n) { | 11518 int f(num n) { |
| 11510 if (n is! int) { | 11519 if (n is! int) { |
| 11511 return 0; | 11520 return 0; |
| 11512 } else { | 11521 } else { |
| 11513 return n & 0x0F; | 11522 return n & 0x0F; |
| 11514 } | 11523 } |
| 11515 }'''); | 11524 }'''); |
| 11516 resolve(source); | 11525 computeLibrarySourceErrors(source); |
| 11517 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11526 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11518 } | 11527 } |
| 11519 | 11528 |
| 11520 void test_if_isNot_abrupt() { | 11529 void test_if_isNot_abrupt() { |
| 11521 Source source = addSource(r''' | 11530 Source source = addSource(r''' |
| 11522 int f(num n) { | 11531 int f(num n) { |
| 11523 if (n is! int) { | 11532 if (n is! int) { |
| 11524 return 0; | 11533 return 0; |
| 11525 } | 11534 } |
| 11526 return n & 0x0F; | 11535 return n & 0x0F; |
| 11527 }'''); | 11536 }'''); |
| 11528 resolve(source); | 11537 computeLibrarySourceErrors(source); |
| 11529 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11538 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11530 } | 11539 } |
| 11531 | 11540 |
| 11532 void test_if_or_is() { | 11541 void test_if_or_is() { |
| 11533 Source source = addSource(r''' | 11542 Source source = addSource(r''' |
| 11534 int f(num n) { | 11543 int f(num n) { |
| 11535 if (n is! int || n < 0) { | 11544 if (n is! int || n < 0) { |
| 11536 return 0; | 11545 return 0; |
| 11537 } else { | 11546 } else { |
| 11538 return n & 0x0F; | 11547 return n & 0x0F; |
| 11539 } | 11548 } |
| 11540 }'''); | 11549 }'''); |
| 11541 resolve(source); | 11550 computeLibrarySourceErrors(source); |
| 11542 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11551 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11543 } | 11552 } |
| 11544 | 11553 |
| 11545 void test_localVar() { | 11554 void test_localVar() { |
| 11546 Source source = addSource(r''' | 11555 Source source = addSource(r''' |
| 11547 int f() { | 11556 int f() { |
| 11548 num n = 1234; | 11557 num n = 1234; |
| 11549 return n & 0x0F; | 11558 return n & 0x0F; |
| 11550 }'''); | 11559 }'''); |
| 11551 resolve(source); | 11560 computeLibrarySourceErrors(source); |
| 11552 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); | 11561 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); |
| 11553 } | 11562 } |
| 11554 } | 11563 } |
| 11555 | 11564 |
| 11556 @reflectiveTest | 11565 @reflectiveTest |
| 11557 class SubtypeManagerTest extends EngineTestCase { | 11566 class SubtypeManagerTest extends EngineTestCase { |
| 11558 /** | 11567 /** |
| 11559 * The inheritance manager being tested. | 11568 * The inheritance manager being tested. |
| 11560 */ | 11569 */ |
| 11561 SubtypeManager _subtypeManager; | 11570 SubtypeManager _subtypeManager; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11949 class A { | 11958 class A { |
| 11950 bool get g => true; | 11959 bool get g => true; |
| 11951 } | 11960 } |
| 11952 A f(var p) { | 11961 A f(var p) { |
| 11953 if ((p as A).g) { | 11962 if ((p as A).g) { |
| 11954 return p; | 11963 return p; |
| 11955 } else { | 11964 } else { |
| 11956 return null; | 11965 return null; |
| 11957 } | 11966 } |
| 11958 }'''); | 11967 }'''); |
| 11959 LibraryElement library = resolve(source); | 11968 LibraryElement library = resolve2(source); |
| 11960 assertNoErrors(source); | 11969 assertNoErrors(source); |
| 11961 verify([source]); | 11970 verify([source]); |
| 11962 CompilationUnit unit = resolveCompilationUnit(source, library); | 11971 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 11963 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 11972 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 11964 InterfaceType typeA = classA.element.type; | 11973 InterfaceType typeA = classA.element.type; |
| 11965 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 11974 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 11966 BlockFunctionBody body = | 11975 BlockFunctionBody body = |
| 11967 function.functionExpression.body as BlockFunctionBody; | 11976 function.functionExpression.body as BlockFunctionBody; |
| 11968 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 11977 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 11969 ReturnStatement statement = | 11978 ReturnStatement statement = |
| 11970 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 11979 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 11971 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 11980 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 11972 expect(variableName.propagatedType, same(typeA)); | 11981 expect(variableName.propagatedType, same(typeA)); |
| 11973 } | 11982 } |
| 11974 | 11983 |
| 11975 void test_assert() { | 11984 void test_assert() { |
| 11976 Source source = addSource(r''' | 11985 Source source = addSource(r''' |
| 11977 class A {} | 11986 class A {} |
| 11978 A f(var p) { | 11987 A f(var p) { |
| 11979 assert (p is A); | 11988 assert (p is A); |
| 11980 return p; | 11989 return p; |
| 11981 }'''); | 11990 }'''); |
| 11982 LibraryElement library = resolve(source); | 11991 LibraryElement library = resolve2(source); |
| 11983 assertNoErrors(source); | 11992 assertNoErrors(source); |
| 11984 verify([source]); | 11993 verify([source]); |
| 11985 CompilationUnit unit = resolveCompilationUnit(source, library); | 11994 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 11986 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 11995 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 11987 InterfaceType typeA = classA.element.type; | 11996 InterfaceType typeA = classA.element.type; |
| 11988 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 11997 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 11989 BlockFunctionBody body = | 11998 BlockFunctionBody body = |
| 11990 function.functionExpression.body as BlockFunctionBody; | 11999 function.functionExpression.body as BlockFunctionBody; |
| 11991 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12000 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 11992 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12001 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 11993 expect(variableName.propagatedType, same(typeA)); | 12002 expect(variableName.propagatedType, same(typeA)); |
| 11994 } | 12003 } |
| 11995 | 12004 |
| 11996 void test_assignment() { | 12005 void test_assignment() { |
| 11997 Source source = addSource(r''' | 12006 Source source = addSource(r''' |
| 11998 f() { | 12007 f() { |
| 11999 var v; | 12008 var v; |
| 12000 v = 0; | 12009 v = 0; |
| 12001 return v; | 12010 return v; |
| 12002 }'''); | 12011 }'''); |
| 12003 LibraryElement library = resolve(source); | 12012 LibraryElement library = resolve2(source); |
| 12004 assertNoErrors(source); | 12013 assertNoErrors(source); |
| 12005 verify([source]); | 12014 verify([source]); |
| 12006 CompilationUnit unit = resolveCompilationUnit(source, library); | 12015 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12007 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12016 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12008 BlockFunctionBody body = | 12017 BlockFunctionBody body = |
| 12009 function.functionExpression.body as BlockFunctionBody; | 12018 function.functionExpression.body as BlockFunctionBody; |
| 12010 ReturnStatement statement = body.block.statements[2] as ReturnStatement; | 12019 ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| 12011 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12020 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12012 expect(variableName.propagatedType, same(typeProvider.intType)); | 12021 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 12013 } | 12022 } |
| 12014 | 12023 |
| 12015 void test_assignment_afterInitializer() { | 12024 void test_assignment_afterInitializer() { |
| 12016 Source source = addSource(r''' | 12025 Source source = addSource(r''' |
| 12017 f() { | 12026 f() { |
| 12018 var v = 0; | 12027 var v = 0; |
| 12019 v = 1.0; | 12028 v = 1.0; |
| 12020 return v; | 12029 return v; |
| 12021 }'''); | 12030 }'''); |
| 12022 LibraryElement library = resolve(source); | 12031 LibraryElement library = resolve2(source); |
| 12023 assertNoErrors(source); | 12032 assertNoErrors(source); |
| 12024 verify([source]); | 12033 verify([source]); |
| 12025 CompilationUnit unit = resolveCompilationUnit(source, library); | 12034 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12026 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12035 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12027 BlockFunctionBody body = | 12036 BlockFunctionBody body = |
| 12028 function.functionExpression.body as BlockFunctionBody; | 12037 function.functionExpression.body as BlockFunctionBody; |
| 12029 ReturnStatement statement = body.block.statements[2] as ReturnStatement; | 12038 ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| 12030 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12039 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12031 expect(variableName.propagatedType, same(typeProvider.doubleType)); | 12040 expect(variableName.propagatedType, same(typeProvider.doubleType)); |
| 12032 } | 12041 } |
| 12033 | 12042 |
| 12034 void test_assignment_null() { | 12043 void test_assignment_null() { |
| 12035 String code = r''' | 12044 String code = r''' |
| 12036 main() { | 12045 main() { |
| 12037 int v; // declare | 12046 int v; // declare |
| 12038 v = null; | 12047 v = null; |
| 12039 return v; // return | 12048 return v; // return |
| 12040 }'''; | 12049 }'''; |
| 12041 CompilationUnit unit; | 12050 CompilationUnit unit; |
| 12042 { | 12051 { |
| 12043 Source source = addSource(code); | 12052 Source source = addSource(code); |
| 12044 LibraryElement library = resolve(source); | 12053 LibraryElement library = resolve2(source); |
| 12045 assertNoErrors(source); | 12054 assertNoErrors(source); |
| 12046 verify([source]); | 12055 verify([source]); |
| 12047 unit = resolveCompilationUnit(source, library); | 12056 unit = resolveCompilationUnit(source, library); |
| 12048 } | 12057 } |
| 12049 { | 12058 { |
| 12050 SimpleIdentifier identifier = EngineTestCase.findNode( | 12059 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 12051 unit, code, "v; // declare", (node) => node is SimpleIdentifier); | 12060 unit, code, "v; // declare", (node) => node is SimpleIdentifier); |
| 12052 expect(identifier.staticType, same(typeProvider.intType)); | 12061 expect(identifier.staticType, same(typeProvider.intType)); |
| 12053 expect(identifier.propagatedType, same(null)); | 12062 expect(identifier.propagatedType, same(null)); |
| 12054 } | 12063 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 12066 } | 12075 } |
| 12067 } | 12076 } |
| 12068 | 12077 |
| 12069 void test_CanvasElement_getContext() { | 12078 void test_CanvasElement_getContext() { |
| 12070 String code = r''' | 12079 String code = r''' |
| 12071 import 'dart:html'; | 12080 import 'dart:html'; |
| 12072 main(CanvasElement canvas) { | 12081 main(CanvasElement canvas) { |
| 12073 var context = canvas.getContext('2d'); | 12082 var context = canvas.getContext('2d'); |
| 12074 }'''; | 12083 }'''; |
| 12075 Source source = addSource(code); | 12084 Source source = addSource(code); |
| 12076 LibraryElement library = resolve(source); | 12085 LibraryElement library = resolve2(source); |
| 12077 assertNoErrors(source); | 12086 assertNoErrors(source); |
| 12078 verify([source]); | 12087 verify([source]); |
| 12079 CompilationUnit unit = resolveCompilationUnit(source, library); | 12088 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12080 SimpleIdentifier identifier = EngineTestCase.findNode( | 12089 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 12081 unit, code, "context", (node) => node is SimpleIdentifier); | 12090 unit, code, "context", (node) => node is SimpleIdentifier); |
| 12082 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); | 12091 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); |
| 12083 } | 12092 } |
| 12084 | 12093 |
| 12085 void test_forEach() { | 12094 void test_forEach() { |
| 12086 String code = r''' | 12095 String code = r''' |
| 12087 main() { | 12096 main() { |
| 12088 var list = <String> []; | 12097 var list = <String> []; |
| 12089 for (var e in list) { | 12098 for (var e in list) { |
| 12090 e; | 12099 e; |
| 12091 } | 12100 } |
| 12092 }'''; | 12101 }'''; |
| 12093 Source source = addSource(code); | 12102 Source source = addSource(code); |
| 12094 LibraryElement library = resolve(source); | 12103 LibraryElement library = resolve2(source); |
| 12095 assertNoErrors(source); | 12104 assertNoErrors(source); |
| 12096 verify([source]); | 12105 verify([source]); |
| 12097 CompilationUnit unit = resolveCompilationUnit(source, library); | 12106 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12098 InterfaceType stringType = typeProvider.stringType; | 12107 InterfaceType stringType = typeProvider.stringType; |
| 12099 // in the declaration | 12108 // in the declaration |
| 12100 { | 12109 { |
| 12101 SimpleIdentifier identifier = EngineTestCase.findNode( | 12110 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 12102 unit, code, "e in", (node) => node is SimpleIdentifier); | 12111 unit, code, "e in", (node) => node is SimpleIdentifier); |
| 12103 expect(identifier.propagatedType, same(stringType)); | 12112 expect(identifier.propagatedType, same(stringType)); |
| 12104 } | 12113 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 12115 class MyMap<K, V> { | 12124 class MyMap<K, V> { |
| 12116 forEach(f(K key, V value)) {} | 12125 forEach(f(K key, V value)) {} |
| 12117 } | 12126 } |
| 12118 f(MyMap<int, String> m) { | 12127 f(MyMap<int, String> m) { |
| 12119 m.forEach((k, v) { | 12128 m.forEach((k, v) { |
| 12120 k; | 12129 k; |
| 12121 v; | 12130 v; |
| 12122 }); | 12131 }); |
| 12123 }'''; | 12132 }'''; |
| 12124 Source source = addSource(code); | 12133 Source source = addSource(code); |
| 12125 LibraryElement library = resolve(source); | 12134 LibraryElement library = resolve2(source); |
| 12126 assertNoErrors(source); | 12135 assertNoErrors(source); |
| 12127 verify([source]); | 12136 verify([source]); |
| 12128 CompilationUnit unit = resolveCompilationUnit(source, library); | 12137 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12129 // k | 12138 // k |
| 12130 DartType intType = typeProvider.intType; | 12139 DartType intType = typeProvider.intType; |
| 12131 FormalParameter kParameter = EngineTestCase.findNode( | 12140 FormalParameter kParameter = EngineTestCase.findNode( |
| 12132 unit, code, "k, ", (node) => node is SimpleFormalParameter); | 12141 unit, code, "k, ", (node) => node is SimpleFormalParameter); |
| 12133 expect(kParameter.identifier.propagatedType, same(intType)); | 12142 expect(kParameter.identifier.propagatedType, same(intType)); |
| 12134 SimpleIdentifier kIdentifier = EngineTestCase.findNode( | 12143 SimpleIdentifier kIdentifier = EngineTestCase.findNode( |
| 12135 unit, code, "k;", (node) => node is SimpleIdentifier); | 12144 unit, code, "k;", (node) => node is SimpleIdentifier); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 12149 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { | 12158 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { |
| 12150 String code = r''' | 12159 String code = r''' |
| 12151 class MyMap<K, V> { | 12160 class MyMap<K, V> { |
| 12152 forEach(f(K key, V value)) {} | 12161 forEach(f(K key, V value)) {} |
| 12153 } | 12162 } |
| 12154 f(MyMap<int, String> m) { | 12163 f(MyMap<int, String> m) { |
| 12155 var m2 = m; | 12164 var m2 = m; |
| 12156 m2.forEach((k, v) {}); | 12165 m2.forEach((k, v) {}); |
| 12157 }'''; | 12166 }'''; |
| 12158 Source source = addSource(code); | 12167 Source source = addSource(code); |
| 12159 LibraryElement library = resolve(source); | 12168 LibraryElement library = resolve2(source); |
| 12160 assertNoErrors(source); | 12169 assertNoErrors(source); |
| 12161 verify([source]); | 12170 verify([source]); |
| 12162 CompilationUnit unit = resolveCompilationUnit(source, library); | 12171 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12163 // k | 12172 // k |
| 12164 DartType intType = typeProvider.intType; | 12173 DartType intType = typeProvider.intType; |
| 12165 FormalParameter kParameter = EngineTestCase.findNode( | 12174 FormalParameter kParameter = EngineTestCase.findNode( |
| 12166 unit, code, "k, ", (node) => node is SimpleFormalParameter); | 12175 unit, code, "k, ", (node) => node is SimpleFormalParameter); |
| 12167 expect(kParameter.identifier.propagatedType, same(intType)); | 12176 expect(kParameter.identifier.propagatedType, same(intType)); |
| 12168 // v | 12177 // v |
| 12169 DartType stringType = typeProvider.stringType; | 12178 DartType stringType = typeProvider.stringType; |
| 12170 FormalParameter vParameter = EngineTestCase.findNode( | 12179 FormalParameter vParameter = EngineTestCase.findNode( |
| 12171 unit, code, "v)", (node) => node is SimpleFormalParameter); | 12180 unit, code, "v)", (node) => node is SimpleFormalParameter); |
| 12172 expect(vParameter.identifier.propagatedType, same(stringType)); | 12181 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 12173 } | 12182 } |
| 12174 | 12183 |
| 12175 void test_functionExpression_asInvocationArgument_functionExpressionInvocation
() { | 12184 void test_functionExpression_asInvocationArgument_functionExpressionInvocation
() { |
| 12176 String code = r''' | 12185 String code = r''' |
| 12177 main() { | 12186 main() { |
| 12178 (f(String value)) {} ((v) { | 12187 (f(String value)) {} ((v) { |
| 12179 v; | 12188 v; |
| 12180 }); | 12189 }); |
| 12181 }'''; | 12190 }'''; |
| 12182 Source source = addSource(code); | 12191 Source source = addSource(code); |
| 12183 LibraryElement library = resolve(source); | 12192 LibraryElement library = resolve2(source); |
| 12184 assertNoErrors(source); | 12193 assertNoErrors(source); |
| 12185 verify([source]); | 12194 verify([source]); |
| 12186 CompilationUnit unit = resolveCompilationUnit(source, library); | 12195 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12187 // v | 12196 // v |
| 12188 DartType dynamicType = typeProvider.dynamicType; | 12197 DartType dynamicType = typeProvider.dynamicType; |
| 12189 DartType stringType = typeProvider.stringType; | 12198 DartType stringType = typeProvider.stringType; |
| 12190 FormalParameter vParameter = EngineTestCase.findNode( | 12199 FormalParameter vParameter = EngineTestCase.findNode( |
| 12191 unit, code, "v)", (node) => node is FormalParameter); | 12200 unit, code, "v)", (node) => node is FormalParameter); |
| 12192 expect(vParameter.identifier.propagatedType, same(stringType)); | 12201 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 12193 expect(vParameter.identifier.staticType, same(dynamicType)); | 12202 expect(vParameter.identifier.staticType, same(dynamicType)); |
| 12194 SimpleIdentifier vIdentifier = EngineTestCase.findNode( | 12203 SimpleIdentifier vIdentifier = EngineTestCase.findNode( |
| 12195 unit, code, "v;", (node) => node is SimpleIdentifier); | 12204 unit, code, "v;", (node) => node is SimpleIdentifier); |
| 12196 expect(vIdentifier.propagatedType, same(stringType)); | 12205 expect(vIdentifier.propagatedType, same(stringType)); |
| 12197 expect(vIdentifier.staticType, same(dynamicType)); | 12206 expect(vIdentifier.staticType, same(dynamicType)); |
| 12198 } | 12207 } |
| 12199 | 12208 |
| 12200 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { | 12209 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { |
| 12201 String code = r''' | 12210 String code = r''' |
| 12202 class MyList { | 12211 class MyList { |
| 12203 forEach(f(Object value)) {} | 12212 forEach(f(Object value)) {} |
| 12204 } | 12213 } |
| 12205 f(MyList list) { | 12214 f(MyList list) { |
| 12206 list.forEach((int v) { | 12215 list.forEach((int v) { |
| 12207 v; | 12216 v; |
| 12208 }); | 12217 }); |
| 12209 }'''; | 12218 }'''; |
| 12210 Source source = addSource(code); | 12219 Source source = addSource(code); |
| 12211 LibraryElement library = resolve(source); | 12220 LibraryElement library = resolve2(source); |
| 12212 assertNoErrors(source); | 12221 assertNoErrors(source); |
| 12213 verify([source]); | 12222 verify([source]); |
| 12214 CompilationUnit unit = resolveCompilationUnit(source, library); | 12223 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12215 // v | 12224 // v |
| 12216 DartType intType = typeProvider.intType; | 12225 DartType intType = typeProvider.intType; |
| 12217 FormalParameter vParameter = EngineTestCase.findNode( | 12226 FormalParameter vParameter = EngineTestCase.findNode( |
| 12218 unit, code, "v)", (node) => node is SimpleFormalParameter); | 12227 unit, code, "v)", (node) => node is SimpleFormalParameter); |
| 12219 expect(vParameter.identifier.propagatedType, same(null)); | 12228 expect(vParameter.identifier.propagatedType, same(null)); |
| 12220 expect(vParameter.identifier.staticType, same(intType)); | 12229 expect(vParameter.identifier.staticType, same(intType)); |
| 12221 SimpleIdentifier vIdentifier = EngineTestCase.findNode( | 12230 SimpleIdentifier vIdentifier = EngineTestCase.findNode( |
| 12222 unit, code, "v;", (node) => node is SimpleIdentifier); | 12231 unit, code, "v;", (node) => node is SimpleIdentifier); |
| 12223 expect(vIdentifier.staticType, same(intType)); | 12232 expect(vIdentifier.staticType, same(intType)); |
| 12224 expect(vIdentifier.propagatedType, same(null)); | 12233 expect(vIdentifier.propagatedType, same(null)); |
| 12225 } | 12234 } |
| 12226 | 12235 |
| 12227 void test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() { | 12236 void test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() { |
| 12228 String code = r''' | 12237 String code = r''' |
| 12229 class A { | 12238 class A { |
| 12230 m(void f(int i)) {} | 12239 m(void f(int i)) {} |
| 12231 } | 12240 } |
| 12232 x() { | 12241 x() { |
| 12233 A a = new A(); | 12242 A a = new A(); |
| 12234 a.m(() => 0); | 12243 a.m(() => 0); |
| 12235 }'''; | 12244 }'''; |
| 12236 Source source = addSource(code); | 12245 Source source = addSource(code); |
| 12237 LibraryElement library = resolve(source); | 12246 LibraryElement library = resolve2(source); |
| 12238 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 12247 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 12239 verify([source]); | 12248 verify([source]); |
| 12240 CompilationUnit unit = resolveCompilationUnit(source, library); | 12249 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12241 // () => 0 | 12250 // () => 0 |
| 12242 FunctionExpression functionExpression = EngineTestCase.findNode( | 12251 FunctionExpression functionExpression = EngineTestCase.findNode( |
| 12243 unit, code, "() => 0)", (node) => node is FunctionExpression); | 12252 unit, code, "() => 0)", (node) => node is FunctionExpression); |
| 12244 expect((functionExpression.staticType as FunctionType).parameters.length, | 12253 expect((functionExpression.staticType as FunctionType).parameters.length, |
| 12245 same(0)); | 12254 same(0)); |
| 12246 expect(functionExpression.propagatedType, same(null)); | 12255 expect(functionExpression.propagatedType, same(null)); |
| 12247 } | 12256 } |
| 12248 | 12257 |
| 12249 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { | 12258 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { |
| 12250 String code = r''' | 12259 String code = r''' |
| 12251 class MyList<E> { | 12260 class MyList<E> { |
| 12252 forEach(f(E value)) {} | 12261 forEach(f(E value)) {} |
| 12253 } | 12262 } |
| 12254 f(MyList<String> list) { | 12263 f(MyList<String> list) { |
| 12255 list.forEach((Object v) { | 12264 list.forEach((Object v) { |
| 12256 v; | 12265 v; |
| 12257 }); | 12266 }); |
| 12258 }'''; | 12267 }'''; |
| 12259 Source source = addSource(code); | 12268 Source source = addSource(code); |
| 12260 LibraryElement library = resolve(source); | 12269 LibraryElement library = resolve2(source); |
| 12261 assertNoErrors(source); | 12270 assertNoErrors(source); |
| 12262 verify([source]); | 12271 verify([source]); |
| 12263 CompilationUnit unit = resolveCompilationUnit(source, library); | 12272 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12264 // v | 12273 // v |
| 12265 DartType stringType = typeProvider.stringType; | 12274 DartType stringType = typeProvider.stringType; |
| 12266 FormalParameter vParameter = EngineTestCase.findNode( | 12275 FormalParameter vParameter = EngineTestCase.findNode( |
| 12267 unit, code, "v)", (node) => node is SimpleFormalParameter); | 12276 unit, code, "v)", (node) => node is SimpleFormalParameter); |
| 12268 expect(vParameter.identifier.propagatedType, same(stringType)); | 12277 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 12269 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); | 12278 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); |
| 12270 SimpleIdentifier vIdentifier = EngineTestCase.findNode( | 12279 SimpleIdentifier vIdentifier = EngineTestCase.findNode( |
| 12271 unit, code, "v;", (node) => node is SimpleIdentifier); | 12280 unit, code, "v;", (node) => node is SimpleIdentifier); |
| 12272 expect(vIdentifier.propagatedType, same(stringType)); | 12281 expect(vIdentifier.propagatedType, same(stringType)); |
| 12273 } | 12282 } |
| 12274 | 12283 |
| 12275 void test_Future_then() { | 12284 void test_Future_then() { |
| 12276 String code = r''' | 12285 String code = r''' |
| 12277 import 'dart:async'; | 12286 import 'dart:async'; |
| 12278 main(Future<int> firstFuture) { | 12287 main(Future<int> firstFuture) { |
| 12279 firstFuture.then((p1) { | 12288 firstFuture.then((p1) { |
| 12280 return 1.0; | 12289 return 1.0; |
| 12281 }).then((p2) { | 12290 }).then((p2) { |
| 12282 return new Future<String>.value('str'); | 12291 return new Future<String>.value('str'); |
| 12283 }).then((p3) { | 12292 }).then((p3) { |
| 12284 }); | 12293 }); |
| 12285 }'''; | 12294 }'''; |
| 12286 Source source = addSource(code); | 12295 Source source = addSource(code); |
| 12287 LibraryElement library = resolve(source); | 12296 LibraryElement library = resolve2(source); |
| 12288 assertNoErrors(source); | 12297 assertNoErrors(source); |
| 12289 verify([source]); | 12298 verify([source]); |
| 12290 CompilationUnit unit = resolveCompilationUnit(source, library); | 12299 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12291 // p1 | 12300 // p1 |
| 12292 FormalParameter p1 = EngineTestCase.findNode( | 12301 FormalParameter p1 = EngineTestCase.findNode( |
| 12293 unit, code, "p1) {", (node) => node is SimpleFormalParameter); | 12302 unit, code, "p1) {", (node) => node is SimpleFormalParameter); |
| 12294 expect(p1.identifier.propagatedType, same(typeProvider.intType)); | 12303 expect(p1.identifier.propagatedType, same(typeProvider.intType)); |
| 12295 // p2 | 12304 // p2 |
| 12296 FormalParameter p2 = EngineTestCase.findNode( | 12305 FormalParameter p2 = EngineTestCase.findNode( |
| 12297 unit, code, "p2) {", (node) => node is SimpleFormalParameter); | 12306 unit, code, "p2) {", (node) => node is SimpleFormalParameter); |
| 12298 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); | 12307 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); |
| 12299 // p3 | 12308 // p3 |
| 12300 FormalParameter p3 = EngineTestCase.findNode( | 12309 FormalParameter p3 = EngineTestCase.findNode( |
| 12301 unit, code, "p3) {", (node) => node is SimpleFormalParameter); | 12310 unit, code, "p3) {", (node) => node is SimpleFormalParameter); |
| 12302 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); | 12311 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); |
| 12303 } | 12312 } |
| 12304 | 12313 |
| 12305 void test_initializer() { | 12314 void test_initializer() { |
| 12306 Source source = addSource(r''' | 12315 Source source = addSource(r''' |
| 12307 f() { | 12316 f() { |
| 12308 var v = 0; | 12317 var v = 0; |
| 12309 return v; | 12318 return v; |
| 12310 }'''); | 12319 }'''); |
| 12311 LibraryElement library = resolve(source); | 12320 LibraryElement library = resolve2(source); |
| 12312 assertNoErrors(source); | 12321 assertNoErrors(source); |
| 12313 verify([source]); | 12322 verify([source]); |
| 12314 CompilationUnit unit = resolveCompilationUnit(source, library); | 12323 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12315 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12324 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12316 BlockFunctionBody body = | 12325 BlockFunctionBody body = |
| 12317 function.functionExpression.body as BlockFunctionBody; | 12326 function.functionExpression.body as BlockFunctionBody; |
| 12318 NodeList<Statement> statements = body.block.statements; | 12327 NodeList<Statement> statements = body.block.statements; |
| 12319 // Type of 'v' in declaration. | 12328 // Type of 'v' in declaration. |
| 12320 { | 12329 { |
| 12321 VariableDeclarationStatement statement = | 12330 VariableDeclarationStatement statement = |
| 12322 statements[0] as VariableDeclarationStatement; | 12331 statements[0] as VariableDeclarationStatement; |
| 12323 SimpleIdentifier variableName = statement.variables.variables[0].name; | 12332 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 12324 expect(variableName.staticType, same(typeProvider.dynamicType)); | 12333 expect(variableName.staticType, same(typeProvider.dynamicType)); |
| 12325 expect(variableName.propagatedType, same(typeProvider.intType)); | 12334 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 12326 } | 12335 } |
| 12327 // Type of 'v' in reference. | 12336 // Type of 'v' in reference. |
| 12328 { | 12337 { |
| 12329 ReturnStatement statement = statements[1] as ReturnStatement; | 12338 ReturnStatement statement = statements[1] as ReturnStatement; |
| 12330 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12339 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12331 expect(variableName.propagatedType, same(typeProvider.intType)); | 12340 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 12332 } | 12341 } |
| 12333 } | 12342 } |
| 12334 | 12343 |
| 12335 void test_initializer_dereference() { | 12344 void test_initializer_dereference() { |
| 12336 Source source = addSource(r''' | 12345 Source source = addSource(r''' |
| 12337 f() { | 12346 f() { |
| 12338 var v = 'String'; | 12347 var v = 'String'; |
| 12339 v. | 12348 v. |
| 12340 }'''); | 12349 }'''); |
| 12341 LibraryElement library = resolve(source); | 12350 LibraryElement library = resolve2(source); |
| 12342 CompilationUnit unit = resolveCompilationUnit(source, library); | 12351 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12343 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12352 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12344 BlockFunctionBody body = | 12353 BlockFunctionBody body = |
| 12345 function.functionExpression.body as BlockFunctionBody; | 12354 function.functionExpression.body as BlockFunctionBody; |
| 12346 ExpressionStatement statement = | 12355 ExpressionStatement statement = |
| 12347 body.block.statements[1] as ExpressionStatement; | 12356 body.block.statements[1] as ExpressionStatement; |
| 12348 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; | 12357 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; |
| 12349 SimpleIdentifier variableName = invocation.prefix; | 12358 SimpleIdentifier variableName = invocation.prefix; |
| 12350 expect(variableName.propagatedType, same(typeProvider.stringType)); | 12359 expect(variableName.propagatedType, same(typeProvider.stringType)); |
| 12351 } | 12360 } |
| 12352 | 12361 |
| 12353 void test_initializer_hasStaticType() { | 12362 void test_initializer_hasStaticType() { |
| 12354 Source source = addSource(r''' | 12363 Source source = addSource(r''' |
| 12355 f() { | 12364 f() { |
| 12356 int v = 0; | 12365 int v = 0; |
| 12357 return v; | 12366 return v; |
| 12358 }'''); | 12367 }'''); |
| 12359 LibraryElement library = resolve(source); | 12368 LibraryElement library = resolve2(source); |
| 12360 assertNoErrors(source); | 12369 assertNoErrors(source); |
| 12361 verify([source]); | 12370 verify([source]); |
| 12362 CompilationUnit unit = resolveCompilationUnit(source, library); | 12371 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12363 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12372 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12364 BlockFunctionBody body = | 12373 BlockFunctionBody body = |
| 12365 function.functionExpression.body as BlockFunctionBody; | 12374 function.functionExpression.body as BlockFunctionBody; |
| 12366 NodeList<Statement> statements = body.block.statements; | 12375 NodeList<Statement> statements = body.block.statements; |
| 12367 // Type of 'v' in declaration. | 12376 // Type of 'v' in declaration. |
| 12368 { | 12377 { |
| 12369 VariableDeclarationStatement statement = | 12378 VariableDeclarationStatement statement = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 12380 expect(variableName.propagatedType, isNull); | 12389 expect(variableName.propagatedType, isNull); |
| 12381 } | 12390 } |
| 12382 } | 12391 } |
| 12383 | 12392 |
| 12384 void test_initializer_hasStaticType_parameterized() { | 12393 void test_initializer_hasStaticType_parameterized() { |
| 12385 Source source = addSource(r''' | 12394 Source source = addSource(r''' |
| 12386 f() { | 12395 f() { |
| 12387 List<int> v = <int>[]; | 12396 List<int> v = <int>[]; |
| 12388 return v; | 12397 return v; |
| 12389 }'''); | 12398 }'''); |
| 12390 LibraryElement library = resolve(source); | 12399 LibraryElement library = resolve2(source); |
| 12391 assertNoErrors(source); | 12400 assertNoErrors(source); |
| 12392 verify([source]); | 12401 verify([source]); |
| 12393 CompilationUnit unit = resolveCompilationUnit(source, library); | 12402 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12394 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12403 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12395 BlockFunctionBody body = | 12404 BlockFunctionBody body = |
| 12396 function.functionExpression.body as BlockFunctionBody; | 12405 function.functionExpression.body as BlockFunctionBody; |
| 12397 NodeList<Statement> statements = body.block.statements; | 12406 NodeList<Statement> statements = body.block.statements; |
| 12398 // Type of 'v' in declaration. | 12407 // Type of 'v' in declaration. |
| 12399 { | 12408 { |
| 12400 VariableDeclarationStatement statement = | 12409 VariableDeclarationStatement statement = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 12414 | 12423 |
| 12415 void test_initializer_null() { | 12424 void test_initializer_null() { |
| 12416 String code = r''' | 12425 String code = r''' |
| 12417 main() { | 12426 main() { |
| 12418 int v = null; | 12427 int v = null; |
| 12419 return v; // marker | 12428 return v; // marker |
| 12420 }'''; | 12429 }'''; |
| 12421 CompilationUnit unit; | 12430 CompilationUnit unit; |
| 12422 { | 12431 { |
| 12423 Source source = addSource(code); | 12432 Source source = addSource(code); |
| 12424 LibraryElement library = resolve(source); | 12433 LibraryElement library = resolve2(source); |
| 12425 assertNoErrors(source); | 12434 assertNoErrors(source); |
| 12426 verify([source]); | 12435 verify([source]); |
| 12427 unit = resolveCompilationUnit(source, library); | 12436 unit = resolveCompilationUnit(source, library); |
| 12428 } | 12437 } |
| 12429 { | 12438 { |
| 12430 SimpleIdentifier identifier = EngineTestCase.findNode( | 12439 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 12431 unit, code, "v = null;", (node) => node is SimpleIdentifier); | 12440 unit, code, "v = null;", (node) => node is SimpleIdentifier); |
| 12432 expect(identifier.staticType, same(typeProvider.intType)); | 12441 expect(identifier.staticType, same(typeProvider.intType)); |
| 12433 expect(identifier.propagatedType, same(null)); | 12442 expect(identifier.propagatedType, same(null)); |
| 12434 } | 12443 } |
| 12435 { | 12444 { |
| 12436 SimpleIdentifier identifier = EngineTestCase.findNode( | 12445 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 12437 unit, code, "v; // marker", (node) => node is SimpleIdentifier); | 12446 unit, code, "v; // marker", (node) => node is SimpleIdentifier); |
| 12438 expect(identifier.staticType, same(typeProvider.intType)); | 12447 expect(identifier.staticType, same(typeProvider.intType)); |
| 12439 expect(identifier.propagatedType, same(null)); | 12448 expect(identifier.propagatedType, same(null)); |
| 12440 } | 12449 } |
| 12441 } | 12450 } |
| 12442 | 12451 |
| 12443 void test_is_conditional() { | 12452 void test_is_conditional() { |
| 12444 Source source = addSource(r''' | 12453 Source source = addSource(r''' |
| 12445 class A {} | 12454 class A {} |
| 12446 A f(var p) { | 12455 A f(var p) { |
| 12447 return (p is A) ? p : null; | 12456 return (p is A) ? p : null; |
| 12448 }'''); | 12457 }'''); |
| 12449 LibraryElement library = resolve(source); | 12458 LibraryElement library = resolve2(source); |
| 12450 assertNoErrors(source); | 12459 assertNoErrors(source); |
| 12451 verify([source]); | 12460 verify([source]); |
| 12452 CompilationUnit unit = resolveCompilationUnit(source, library); | 12461 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12453 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12462 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12454 InterfaceType typeA = classA.element.type; | 12463 InterfaceType typeA = classA.element.type; |
| 12455 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12464 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12456 BlockFunctionBody body = | 12465 BlockFunctionBody body = |
| 12457 function.functionExpression.body as BlockFunctionBody; | 12466 function.functionExpression.body as BlockFunctionBody; |
| 12458 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 12467 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 12459 ConditionalExpression conditional = | 12468 ConditionalExpression conditional = |
| 12460 statement.expression as ConditionalExpression; | 12469 statement.expression as ConditionalExpression; |
| 12461 SimpleIdentifier variableName = | 12470 SimpleIdentifier variableName = |
| 12462 conditional.thenExpression as SimpleIdentifier; | 12471 conditional.thenExpression as SimpleIdentifier; |
| 12463 expect(variableName.propagatedType, same(typeA)); | 12472 expect(variableName.propagatedType, same(typeA)); |
| 12464 } | 12473 } |
| 12465 | 12474 |
| 12466 void test_is_if() { | 12475 void test_is_if() { |
| 12467 Source source = addSource(r''' | 12476 Source source = addSource(r''' |
| 12468 class A {} | 12477 class A {} |
| 12469 A f(var p) { | 12478 A f(var p) { |
| 12470 if (p is A) { | 12479 if (p is A) { |
| 12471 return p; | 12480 return p; |
| 12472 } else { | 12481 } else { |
| 12473 return null; | 12482 return null; |
| 12474 } | 12483 } |
| 12475 }'''); | 12484 }'''); |
| 12476 LibraryElement library = resolve(source); | 12485 LibraryElement library = resolve2(source); |
| 12477 assertNoErrors(source); | 12486 assertNoErrors(source); |
| 12478 verify([source]); | 12487 verify([source]); |
| 12479 CompilationUnit unit = resolveCompilationUnit(source, library); | 12488 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12480 // prepare A | 12489 // prepare A |
| 12481 InterfaceType typeA; | 12490 InterfaceType typeA; |
| 12482 { | 12491 { |
| 12483 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12492 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12484 typeA = classA.element.type; | 12493 typeA = classA.element.type; |
| 12485 } | 12494 } |
| 12486 // verify "f" | 12495 // verify "f" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 12506 void test_is_if_lessSpecific() { | 12515 void test_is_if_lessSpecific() { |
| 12507 Source source = addSource(r''' | 12516 Source source = addSource(r''' |
| 12508 class A {} | 12517 class A {} |
| 12509 A f(A p) { | 12518 A f(A p) { |
| 12510 if (p is String) { | 12519 if (p is String) { |
| 12511 return p; | 12520 return p; |
| 12512 } else { | 12521 } else { |
| 12513 return null; | 12522 return null; |
| 12514 } | 12523 } |
| 12515 }'''); | 12524 }'''); |
| 12516 LibraryElement library = resolve(source); | 12525 LibraryElement library = resolve2(source); |
| 12517 assertNoErrors(source); | 12526 assertNoErrors(source); |
| 12518 verify([source]); | 12527 verify([source]); |
| 12519 CompilationUnit unit = resolveCompilationUnit(source, library); | 12528 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12520 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0)
; | 12529 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0)
; |
| 12521 // InterfaceType typeA = classA.getElement().getType(); | 12530 // InterfaceType typeA = classA.getElement().getType(); |
| 12522 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12531 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12523 BlockFunctionBody body = | 12532 BlockFunctionBody body = |
| 12524 function.functionExpression.body as BlockFunctionBody; | 12533 function.functionExpression.body as BlockFunctionBody; |
| 12525 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12534 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12526 ReturnStatement statement = | 12535 ReturnStatement statement = |
| 12527 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 12536 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 12528 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12537 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12529 expect(variableName.propagatedType, same(null)); | 12538 expect(variableName.propagatedType, same(null)); |
| 12530 } | 12539 } |
| 12531 | 12540 |
| 12532 void test_is_if_logicalAnd() { | 12541 void test_is_if_logicalAnd() { |
| 12533 Source source = addSource(r''' | 12542 Source source = addSource(r''' |
| 12534 class A {} | 12543 class A {} |
| 12535 A f(var p) { | 12544 A f(var p) { |
| 12536 if (p is A && p != null) { | 12545 if (p is A && p != null) { |
| 12537 return p; | 12546 return p; |
| 12538 } else { | 12547 } else { |
| 12539 return null; | 12548 return null; |
| 12540 } | 12549 } |
| 12541 }'''); | 12550 }'''); |
| 12542 LibraryElement library = resolve(source); | 12551 LibraryElement library = resolve2(source); |
| 12543 assertNoErrors(source); | 12552 assertNoErrors(source); |
| 12544 verify([source]); | 12553 verify([source]); |
| 12545 CompilationUnit unit = resolveCompilationUnit(source, library); | 12554 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12546 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12555 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12547 InterfaceType typeA = classA.element.type; | 12556 InterfaceType typeA = classA.element.type; |
| 12548 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12557 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12549 BlockFunctionBody body = | 12558 BlockFunctionBody body = |
| 12550 function.functionExpression.body as BlockFunctionBody; | 12559 function.functionExpression.body as BlockFunctionBody; |
| 12551 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12560 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12552 ReturnStatement statement = | 12561 ReturnStatement statement = |
| 12553 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 12562 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 12554 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12563 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12555 expect(variableName.propagatedType, same(typeA)); | 12564 expect(variableName.propagatedType, same(typeA)); |
| 12556 } | 12565 } |
| 12557 | 12566 |
| 12558 void test_is_postConditional() { | 12567 void test_is_postConditional() { |
| 12559 Source source = addSource(r''' | 12568 Source source = addSource(r''' |
| 12560 class A {} | 12569 class A {} |
| 12561 A f(var p) { | 12570 A f(var p) { |
| 12562 A a = (p is A) ? p : throw null; | 12571 A a = (p is A) ? p : throw null; |
| 12563 return p; | 12572 return p; |
| 12564 }'''); | 12573 }'''); |
| 12565 LibraryElement library = resolve(source); | 12574 LibraryElement library = resolve2(source); |
| 12566 assertNoErrors(source); | 12575 assertNoErrors(source); |
| 12567 verify([source]); | 12576 verify([source]); |
| 12568 CompilationUnit unit = resolveCompilationUnit(source, library); | 12577 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12569 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12578 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12570 InterfaceType typeA = classA.element.type; | 12579 InterfaceType typeA = classA.element.type; |
| 12571 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12580 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12572 BlockFunctionBody body = | 12581 BlockFunctionBody body = |
| 12573 function.functionExpression.body as BlockFunctionBody; | 12582 function.functionExpression.body as BlockFunctionBody; |
| 12574 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12583 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12575 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12584 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12576 expect(variableName.propagatedType, same(typeA)); | 12585 expect(variableName.propagatedType, same(typeA)); |
| 12577 } | 12586 } |
| 12578 | 12587 |
| 12579 void test_is_postIf() { | 12588 void test_is_postIf() { |
| 12580 Source source = addSource(r''' | 12589 Source source = addSource(r''' |
| 12581 class A {} | 12590 class A {} |
| 12582 A f(var p) { | 12591 A f(var p) { |
| 12583 if (p is A) { | 12592 if (p is A) { |
| 12584 A a = p; | 12593 A a = p; |
| 12585 } else { | 12594 } else { |
| 12586 return null; | 12595 return null; |
| 12587 } | 12596 } |
| 12588 return p; | 12597 return p; |
| 12589 }'''); | 12598 }'''); |
| 12590 LibraryElement library = resolve(source); | 12599 LibraryElement library = resolve2(source); |
| 12591 assertNoErrors(source); | 12600 assertNoErrors(source); |
| 12592 verify([source]); | 12601 verify([source]); |
| 12593 CompilationUnit unit = resolveCompilationUnit(source, library); | 12602 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12594 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12603 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12595 InterfaceType typeA = classA.element.type; | 12604 InterfaceType typeA = classA.element.type; |
| 12596 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12605 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12597 BlockFunctionBody body = | 12606 BlockFunctionBody body = |
| 12598 function.functionExpression.body as BlockFunctionBody; | 12607 function.functionExpression.body as BlockFunctionBody; |
| 12599 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12608 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12600 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12609 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12601 expect(variableName.propagatedType, same(typeA)); | 12610 expect(variableName.propagatedType, same(typeA)); |
| 12602 } | 12611 } |
| 12603 | 12612 |
| 12604 void test_is_subclass() { | 12613 void test_is_subclass() { |
| 12605 Source source = addSource(r''' | 12614 Source source = addSource(r''' |
| 12606 class A {} | 12615 class A {} |
| 12607 class B extends A { | 12616 class B extends A { |
| 12608 B m() => this; | 12617 B m() => this; |
| 12609 } | 12618 } |
| 12610 A f(A p) { | 12619 A f(A p) { |
| 12611 if (p is B) { | 12620 if (p is B) { |
| 12612 return p.m(); | 12621 return p.m(); |
| 12613 } | 12622 } |
| 12614 return p; | 12623 return p; |
| 12615 }'''); | 12624 }'''); |
| 12616 LibraryElement library = resolve(source); | 12625 LibraryElement library = resolve2(source); |
| 12617 assertNoErrors(source); | 12626 assertNoErrors(source); |
| 12618 CompilationUnit unit = resolveCompilationUnit(source, library); | 12627 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12619 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; | 12628 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; |
| 12620 BlockFunctionBody body = | 12629 BlockFunctionBody body = |
| 12621 function.functionExpression.body as BlockFunctionBody; | 12630 function.functionExpression.body as BlockFunctionBody; |
| 12622 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12631 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12623 ReturnStatement statement = | 12632 ReturnStatement statement = |
| 12624 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 12633 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 12625 MethodInvocation invocation = statement.expression as MethodInvocation; | 12634 MethodInvocation invocation = statement.expression as MethodInvocation; |
| 12626 expect(invocation.methodName.staticElement, isNotNull); | 12635 expect(invocation.methodName.staticElement, isNotNull); |
| 12627 expect(invocation.methodName.propagatedElement, isNull); | 12636 expect(invocation.methodName.propagatedElement, isNull); |
| 12628 } | 12637 } |
| 12629 | 12638 |
| 12630 void test_is_while() { | 12639 void test_is_while() { |
| 12631 Source source = addSource(r''' | 12640 Source source = addSource(r''' |
| 12632 class A {} | 12641 class A {} |
| 12633 A f(var p) { | 12642 A f(var p) { |
| 12634 while (p is A) { | 12643 while (p is A) { |
| 12635 return p; | 12644 return p; |
| 12636 } | 12645 } |
| 12637 return p; | 12646 return p; |
| 12638 }'''); | 12647 }'''); |
| 12639 LibraryElement library = resolve(source); | 12648 LibraryElement library = resolve2(source); |
| 12640 assertNoErrors(source); | 12649 assertNoErrors(source); |
| 12641 verify([source]); | 12650 verify([source]); |
| 12642 CompilationUnit unit = resolveCompilationUnit(source, library); | 12651 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12643 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12652 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12644 InterfaceType typeA = classA.element.type; | 12653 InterfaceType typeA = classA.element.type; |
| 12645 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12654 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12646 BlockFunctionBody body = | 12655 BlockFunctionBody body = |
| 12647 function.functionExpression.body as BlockFunctionBody; | 12656 function.functionExpression.body as BlockFunctionBody; |
| 12648 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; | 12657 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; |
| 12649 ReturnStatement statement = | 12658 ReturnStatement statement = |
| 12650 (whileStatement.body as Block).statements[0] as ReturnStatement; | 12659 (whileStatement.body as Block).statements[0] as ReturnStatement; |
| 12651 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12660 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12652 expect(variableName.propagatedType, same(typeA)); | 12661 expect(variableName.propagatedType, same(typeA)); |
| 12653 } | 12662 } |
| 12654 | 12663 |
| 12655 void test_isNot_conditional() { | 12664 void test_isNot_conditional() { |
| 12656 Source source = addSource(r''' | 12665 Source source = addSource(r''' |
| 12657 class A {} | 12666 class A {} |
| 12658 A f(var p) { | 12667 A f(var p) { |
| 12659 return (p is! A) ? null : p; | 12668 return (p is! A) ? null : p; |
| 12660 }'''); | 12669 }'''); |
| 12661 LibraryElement library = resolve(source); | 12670 LibraryElement library = resolve2(source); |
| 12662 assertNoErrors(source); | 12671 assertNoErrors(source); |
| 12663 verify([source]); | 12672 verify([source]); |
| 12664 CompilationUnit unit = resolveCompilationUnit(source, library); | 12673 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12665 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12674 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12666 InterfaceType typeA = classA.element.type; | 12675 InterfaceType typeA = classA.element.type; |
| 12667 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12676 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12668 BlockFunctionBody body = | 12677 BlockFunctionBody body = |
| 12669 function.functionExpression.body as BlockFunctionBody; | 12678 function.functionExpression.body as BlockFunctionBody; |
| 12670 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 12679 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 12671 ConditionalExpression conditional = | 12680 ConditionalExpression conditional = |
| 12672 statement.expression as ConditionalExpression; | 12681 statement.expression as ConditionalExpression; |
| 12673 SimpleIdentifier variableName = | 12682 SimpleIdentifier variableName = |
| 12674 conditional.elseExpression as SimpleIdentifier; | 12683 conditional.elseExpression as SimpleIdentifier; |
| 12675 expect(variableName.propagatedType, same(typeA)); | 12684 expect(variableName.propagatedType, same(typeA)); |
| 12676 } | 12685 } |
| 12677 | 12686 |
| 12678 void test_isNot_if() { | 12687 void test_isNot_if() { |
| 12679 Source source = addSource(r''' | 12688 Source source = addSource(r''' |
| 12680 class A {} | 12689 class A {} |
| 12681 A f(var p) { | 12690 A f(var p) { |
| 12682 if (p is! A) { | 12691 if (p is! A) { |
| 12683 return null; | 12692 return null; |
| 12684 } else { | 12693 } else { |
| 12685 return p; | 12694 return p; |
| 12686 } | 12695 } |
| 12687 }'''); | 12696 }'''); |
| 12688 LibraryElement library = resolve(source); | 12697 LibraryElement library = resolve2(source); |
| 12689 assertNoErrors(source); | 12698 assertNoErrors(source); |
| 12690 verify([source]); | 12699 verify([source]); |
| 12691 CompilationUnit unit = resolveCompilationUnit(source, library); | 12700 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12692 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12701 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12693 InterfaceType typeA = classA.element.type; | 12702 InterfaceType typeA = classA.element.type; |
| 12694 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12703 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12695 BlockFunctionBody body = | 12704 BlockFunctionBody body = |
| 12696 function.functionExpression.body as BlockFunctionBody; | 12705 function.functionExpression.body as BlockFunctionBody; |
| 12697 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12706 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12698 ReturnStatement statement = | 12707 ReturnStatement statement = |
| 12699 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; | 12708 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; |
| 12700 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12709 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12701 expect(variableName.propagatedType, same(typeA)); | 12710 expect(variableName.propagatedType, same(typeA)); |
| 12702 } | 12711 } |
| 12703 | 12712 |
| 12704 void test_isNot_if_logicalOr() { | 12713 void test_isNot_if_logicalOr() { |
| 12705 Source source = addSource(r''' | 12714 Source source = addSource(r''' |
| 12706 class A {} | 12715 class A {} |
| 12707 A f(var p) { | 12716 A f(var p) { |
| 12708 if (p is! A || null == p) { | 12717 if (p is! A || null == p) { |
| 12709 return null; | 12718 return null; |
| 12710 } else { | 12719 } else { |
| 12711 return p; | 12720 return p; |
| 12712 } | 12721 } |
| 12713 }'''); | 12722 }'''); |
| 12714 LibraryElement library = resolve(source); | 12723 LibraryElement library = resolve2(source); |
| 12715 assertNoErrors(source); | 12724 assertNoErrors(source); |
| 12716 CompilationUnit unit = resolveCompilationUnit(source, library); | 12725 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12717 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12726 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12718 InterfaceType typeA = classA.element.type; | 12727 InterfaceType typeA = classA.element.type; |
| 12719 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12728 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12720 BlockFunctionBody body = | 12729 BlockFunctionBody body = |
| 12721 function.functionExpression.body as BlockFunctionBody; | 12730 function.functionExpression.body as BlockFunctionBody; |
| 12722 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 12731 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 12723 ReturnStatement statement = | 12732 ReturnStatement statement = |
| 12724 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; | 12733 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; |
| 12725 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12734 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12726 expect(variableName.propagatedType, same(typeA)); | 12735 expect(variableName.propagatedType, same(typeA)); |
| 12727 } | 12736 } |
| 12728 | 12737 |
| 12729 void test_isNot_postConditional() { | 12738 void test_isNot_postConditional() { |
| 12730 Source source = addSource(r''' | 12739 Source source = addSource(r''' |
| 12731 class A {} | 12740 class A {} |
| 12732 A f(var p) { | 12741 A f(var p) { |
| 12733 A a = (p is! A) ? throw null : p; | 12742 A a = (p is! A) ? throw null : p; |
| 12734 return p; | 12743 return p; |
| 12735 }'''); | 12744 }'''); |
| 12736 LibraryElement library = resolve(source); | 12745 LibraryElement library = resolve2(source); |
| 12737 assertNoErrors(source); | 12746 assertNoErrors(source); |
| 12738 verify([source]); | 12747 verify([source]); |
| 12739 CompilationUnit unit = resolveCompilationUnit(source, library); | 12748 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12740 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12749 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12741 InterfaceType typeA = classA.element.type; | 12750 InterfaceType typeA = classA.element.type; |
| 12742 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12751 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12743 BlockFunctionBody body = | 12752 BlockFunctionBody body = |
| 12744 function.functionExpression.body as BlockFunctionBody; | 12753 function.functionExpression.body as BlockFunctionBody; |
| 12745 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12754 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12746 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12755 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 12747 expect(variableName.propagatedType, same(typeA)); | 12756 expect(variableName.propagatedType, same(typeA)); |
| 12748 } | 12757 } |
| 12749 | 12758 |
| 12750 void test_isNot_postIf() { | 12759 void test_isNot_postIf() { |
| 12751 Source source = addSource(r''' | 12760 Source source = addSource(r''' |
| 12752 class A {} | 12761 class A {} |
| 12753 A f(var p) { | 12762 A f(var p) { |
| 12754 if (p is! A) { | 12763 if (p is! A) { |
| 12755 return null; | 12764 return null; |
| 12756 } | 12765 } |
| 12757 return p; | 12766 return p; |
| 12758 }'''); | 12767 }'''); |
| 12759 LibraryElement library = resolve(source); | 12768 LibraryElement library = resolve2(source); |
| 12760 assertNoErrors(source); | 12769 assertNoErrors(source); |
| 12761 verify([source]); | 12770 verify([source]); |
| 12762 CompilationUnit unit = resolveCompilationUnit(source, library); | 12771 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12763 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 12772 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 12764 InterfaceType typeA = classA.element.type; | 12773 InterfaceType typeA = classA.element.type; |
| 12765 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 12774 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 12766 BlockFunctionBody body = | 12775 BlockFunctionBody body = |
| 12767 function.functionExpression.body as BlockFunctionBody; | 12776 function.functionExpression.body as BlockFunctionBody; |
| 12768 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12777 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12769 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 12778 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12823 DartType tB = _findMarkedIdentifier(code, "; // B").propagatedType; | 12832 DartType tB = _findMarkedIdentifier(code, "; // B").propagatedType; |
| 12824 _assertTypeOfMarkedExpression(code, null, tB); | 12833 _assertTypeOfMarkedExpression(code, null, tB); |
| 12825 } | 12834 } |
| 12826 | 12835 |
| 12827 void test_listLiteral_different() { | 12836 void test_listLiteral_different() { |
| 12828 Source source = addSource(r''' | 12837 Source source = addSource(r''' |
| 12829 f() { | 12838 f() { |
| 12830 var v = [0, '1', 2]; | 12839 var v = [0, '1', 2]; |
| 12831 return v[2]; | 12840 return v[2]; |
| 12832 }'''); | 12841 }'''); |
| 12833 LibraryElement library = resolve(source); | 12842 LibraryElement library = resolve2(source); |
| 12834 assertNoErrors(source); | 12843 assertNoErrors(source); |
| 12835 verify([source]); | 12844 verify([source]); |
| 12836 CompilationUnit unit = resolveCompilationUnit(source, library); | 12845 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12837 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12846 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12838 BlockFunctionBody body = | 12847 BlockFunctionBody body = |
| 12839 function.functionExpression.body as BlockFunctionBody; | 12848 function.functionExpression.body as BlockFunctionBody; |
| 12840 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12849 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12841 IndexExpression indexExpression = statement.expression as IndexExpression; | 12850 IndexExpression indexExpression = statement.expression as IndexExpression; |
| 12842 expect(indexExpression.propagatedType, isNull); | 12851 expect(indexExpression.propagatedType, isNull); |
| 12843 } | 12852 } |
| 12844 | 12853 |
| 12845 void test_listLiteral_same() { | 12854 void test_listLiteral_same() { |
| 12846 Source source = addSource(r''' | 12855 Source source = addSource(r''' |
| 12847 f() { | 12856 f() { |
| 12848 var v = [0, 1, 2]; | 12857 var v = [0, 1, 2]; |
| 12849 return v[2]; | 12858 return v[2]; |
| 12850 }'''); | 12859 }'''); |
| 12851 LibraryElement library = resolve(source); | 12860 LibraryElement library = resolve2(source); |
| 12852 assertNoErrors(source); | 12861 assertNoErrors(source); |
| 12853 verify([source]); | 12862 verify([source]); |
| 12854 CompilationUnit unit = resolveCompilationUnit(source, library); | 12863 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12855 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12864 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12856 BlockFunctionBody body = | 12865 BlockFunctionBody body = |
| 12857 function.functionExpression.body as BlockFunctionBody; | 12866 function.functionExpression.body as BlockFunctionBody; |
| 12858 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12867 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12859 IndexExpression indexExpression = statement.expression as IndexExpression; | 12868 IndexExpression indexExpression = statement.expression as IndexExpression; |
| 12860 expect(indexExpression.propagatedType, isNull); | 12869 expect(indexExpression.propagatedType, isNull); |
| 12861 Expression v = indexExpression.target; | 12870 Expression v = indexExpression.target; |
| 12862 InterfaceType propagatedType = v.propagatedType as InterfaceType; | 12871 InterfaceType propagatedType = v.propagatedType as InterfaceType; |
| 12863 expect(propagatedType.element, same(typeProvider.listType.element)); | 12872 expect(propagatedType.element, same(typeProvider.listType.element)); |
| 12864 List<DartType> typeArguments = propagatedType.typeArguments; | 12873 List<DartType> typeArguments = propagatedType.typeArguments; |
| 12865 expect(typeArguments, hasLength(1)); | 12874 expect(typeArguments, hasLength(1)); |
| 12866 expect(typeArguments[0], same(typeProvider.dynamicType)); | 12875 expect(typeArguments[0], same(typeProvider.dynamicType)); |
| 12867 } | 12876 } |
| 12868 | 12877 |
| 12869 void test_mapLiteral_different() { | 12878 void test_mapLiteral_different() { |
| 12870 Source source = addSource(r''' | 12879 Source source = addSource(r''' |
| 12871 f() { | 12880 f() { |
| 12872 var v = {'0' : 0, 1 : '1', '2' : 2}; | 12881 var v = {'0' : 0, 1 : '1', '2' : 2}; |
| 12873 return v; | 12882 return v; |
| 12874 }'''); | 12883 }'''); |
| 12875 LibraryElement library = resolve(source); | 12884 LibraryElement library = resolve2(source); |
| 12876 assertNoErrors(source); | 12885 assertNoErrors(source); |
| 12877 verify([source]); | 12886 verify([source]); |
| 12878 CompilationUnit unit = resolveCompilationUnit(source, library); | 12887 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12879 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12888 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12880 BlockFunctionBody body = | 12889 BlockFunctionBody body = |
| 12881 function.functionExpression.body as BlockFunctionBody; | 12890 function.functionExpression.body as BlockFunctionBody; |
| 12882 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12891 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12883 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | 12892 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 12884 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; | 12893 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| 12885 expect(propagatedType.element, same(typeProvider.mapType.element)); | 12894 expect(propagatedType.element, same(typeProvider.mapType.element)); |
| 12886 List<DartType> typeArguments = propagatedType.typeArguments; | 12895 List<DartType> typeArguments = propagatedType.typeArguments; |
| 12887 expect(typeArguments, hasLength(2)); | 12896 expect(typeArguments, hasLength(2)); |
| 12888 expect(typeArguments[0], same(typeProvider.dynamicType)); | 12897 expect(typeArguments[0], same(typeProvider.dynamicType)); |
| 12889 expect(typeArguments[1], same(typeProvider.dynamicType)); | 12898 expect(typeArguments[1], same(typeProvider.dynamicType)); |
| 12890 } | 12899 } |
| 12891 | 12900 |
| 12892 void test_mapLiteral_same() { | 12901 void test_mapLiteral_same() { |
| 12893 Source source = addSource(r''' | 12902 Source source = addSource(r''' |
| 12894 f() { | 12903 f() { |
| 12895 var v = {'a' : 0, 'b' : 1, 'c' : 2}; | 12904 var v = {'a' : 0, 'b' : 1, 'c' : 2}; |
| 12896 return v; | 12905 return v; |
| 12897 }'''); | 12906 }'''); |
| 12898 LibraryElement library = resolve(source); | 12907 LibraryElement library = resolve2(source); |
| 12899 assertNoErrors(source); | 12908 assertNoErrors(source); |
| 12900 verify([source]); | 12909 verify([source]); |
| 12901 CompilationUnit unit = resolveCompilationUnit(source, library); | 12910 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 12902 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 12911 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 12903 BlockFunctionBody body = | 12912 BlockFunctionBody body = |
| 12904 function.functionExpression.body as BlockFunctionBody; | 12913 function.functionExpression.body as BlockFunctionBody; |
| 12905 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 12914 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 12906 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | 12915 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 12907 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; | 12916 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| 12908 expect(propagatedType.element, same(typeProvider.mapType.element)); | 12917 expect(propagatedType.element, same(typeProvider.mapType.element)); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13003 } | 13012 } |
| 13004 } | 13013 } |
| 13005 | 13014 |
| 13006 void g() { | 13015 void g() { |
| 13007 Base x = null; | 13016 Base x = null; |
| 13008 if (x is Derived) { | 13017 if (x is Derived) { |
| 13009 print(x.y); // GOOD | 13018 print(x.y); // GOOD |
| 13010 } | 13019 } |
| 13011 x = null; | 13020 x = null; |
| 13012 }'''); | 13021 }'''); |
| 13013 resolve(source); | 13022 computeLibrarySourceErrors(source); |
| 13014 assertNoErrors(source); | 13023 assertNoErrors(source); |
| 13015 } | 13024 } |
| 13016 | 13025 |
| 13017 void test_objectMethodOnDynamicExpression_doubleEquals() { | 13026 void test_objectMethodOnDynamicExpression_doubleEquals() { |
| 13018 // https://code.google.com/p/dart/issues/detail?id=20342 | 13027 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 13019 // | 13028 // |
| 13020 // This was not actually part of Issue 20342, since the spec specifies a | 13029 // This was not actually part of Issue 20342, since the spec specifies a |
| 13021 // static type of [bool] for [==] comparison and the implementation | 13030 // static type of [bool] for [==] comparison and the implementation |
| 13022 // was already consistent with the spec there. But, it's another | 13031 // was already consistent with the spec there. But, it's another |
| 13023 // [Object] method, so it's included here. | 13032 // [Object] method, so it's included here. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13144 var v6 = query('input#id'); | 13153 var v6 = query('input#id'); |
| 13145 var v7 = query('select#id'); | 13154 var v7 = query('select#id'); |
| 13146 // invocation of method | 13155 // invocation of method |
| 13147 var m1 = document.query('div'); | 13156 var m1 = document.query('div'); |
| 13148 // unsupported currently | 13157 // unsupported currently |
| 13149 var b1 = query('noSuchTag'); | 13158 var b1 = query('noSuchTag'); |
| 13150 var b2 = query('DART_EDITOR_NO_SUCH_TYPE'); | 13159 var b2 = query('DART_EDITOR_NO_SUCH_TYPE'); |
| 13151 var b3 = query('body div'); | 13160 var b3 = query('body div'); |
| 13152 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; | 13161 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; |
| 13153 }'''); | 13162 }'''); |
| 13154 LibraryElement library = resolve(source); | 13163 LibraryElement library = resolve2(source); |
| 13155 assertNoErrors(source); | 13164 assertNoErrors(source); |
| 13156 verify([source]); | 13165 verify([source]); |
| 13157 CompilationUnit unit = resolveCompilationUnit(source, library); | 13166 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 13158 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; | 13167 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; |
| 13159 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; | 13168 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; |
| 13160 ReturnStatement statement = body.block.statements[11] as ReturnStatement; | 13169 ReturnStatement statement = body.block.statements[11] as ReturnStatement; |
| 13161 NodeList<Expression> elements = | 13170 NodeList<Expression> elements = |
| 13162 (statement.expression as ListLiteral).elements; | 13171 (statement.expression as ListLiteral).elements; |
| 13163 expect(elements[0].propagatedType.name, "AnchorElement"); | 13172 expect(elements[0].propagatedType.name, "AnchorElement"); |
| 13164 expect(elements[1].propagatedType.name, "AnchorElement"); | 13173 expect(elements[1].propagatedType.name, "AnchorElement"); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13206 * errors and be verifiable. | 13215 * errors and be verifiable. |
| 13207 * | 13216 * |
| 13208 * @param code source code to analyze. | 13217 * @param code source code to analyze. |
| 13209 * @param marker marker identifying sought after expression in source code. | 13218 * @param marker marker identifying sought after expression in source code. |
| 13210 * @return expression marked by the marker. | 13219 * @return expression marked by the marker. |
| 13211 * @throws Exception | 13220 * @throws Exception |
| 13212 */ | 13221 */ |
| 13213 SimpleIdentifier _findMarkedIdentifier(String code, String marker) { | 13222 SimpleIdentifier _findMarkedIdentifier(String code, String marker) { |
| 13214 try { | 13223 try { |
| 13215 Source source = addSource(code); | 13224 Source source = addSource(code); |
| 13216 LibraryElement library = resolve(source); | 13225 LibraryElement library = resolve2(source); |
| 13217 assertNoErrors(source); | 13226 assertNoErrors(source); |
| 13218 verify([source]); | 13227 verify([source]); |
| 13219 CompilationUnit unit = resolveCompilationUnit(source, library); | 13228 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 13220 // Could generalize this further by making [SimpleIdentifier.class] a | 13229 // Could generalize this further by making [SimpleIdentifier.class] a |
| 13221 // parameter. | 13230 // parameter. |
| 13222 return EngineTestCase.findNode( | 13231 return EngineTestCase.findNode( |
| 13223 unit, code, marker, (node) => node is SimpleIdentifier); | 13232 unit, code, marker, (node) => node is SimpleIdentifier); |
| 13224 } catch (exception) { | 13233 } catch (exception) { |
| 13225 // Is there a better exception to throw here? The point is that an | 13234 // Is there a better exception to throw here? The point is that an |
| 13226 // assertion failure here should be a failure, in both "test_*" and | 13235 // assertion failure here should be a failure, in both "test_*" and |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13875 // check propagated type | 13884 // check propagated type |
| 13876 FunctionType propagatedType = node.propagatedType as FunctionType; | 13885 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 13877 expect(propagatedType.returnType, test.typeProvider.stringType); | 13886 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 13878 } on AnalysisException catch (e, stackTrace) { | 13887 } on AnalysisException catch (e, stackTrace) { |
| 13879 thrownException[0] = new CaughtException(e, stackTrace); | 13888 thrownException[0] = new CaughtException(e, stackTrace); |
| 13880 } | 13889 } |
| 13881 } | 13890 } |
| 13882 return null; | 13891 return null; |
| 13883 } | 13892 } |
| 13884 } | 13893 } |
| OLD | NEW |