| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.simple_resolver_test; | 5 library analyzer.test.generated.simple_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; | 12 import 'package:analyzer/src/generated/error.dart'; |
| 13 import 'package:analyzer/src/generated/java_engine.dart'; | 13 import 'package:analyzer/src/generated/java_engine.dart'; |
| 14 import 'package:analyzer/src/generated/source_io.dart'; | 14 import 'package:analyzer/src/generated/source_io.dart'; |
| 15 import 'package:unittest/unittest.dart'; | 15 import 'package:unittest/unittest.dart'; |
| 16 | 16 |
| 17 import '../reflective_tests.dart'; | 17 import '../reflective_tests.dart'; |
| 18 import '../utils.dart'; | 18 import '../utils.dart'; |
| 19 import 'resolver_test_case.dart'; | 19 import 'resolver_test_case.dart'; |
| 20 import 'test_support.dart'; | 20 import 'test_support.dart'; |
| 21 | 21 |
| 22 main() { | 22 main() { |
| 23 initializeTestEnvironment(); | 23 initializeTestEnvironment(); |
| 24 runReflectiveTests(SimpleResolverTest); | 24 runReflectiveTests(SimpleResolverTest); |
| 25 } | 25 } |
| 26 | 26 |
| 27 @reflectiveTest | 27 @reflectiveTest |
| 28 class SimpleResolverTest extends ResolverTestCase { | 28 class SimpleResolverTest extends ResolverTestCase { |
| 29 void fail_getter_and_setter_fromMixins_property_access() { | |
| 30 // TODO(paulberry): it appears that auxiliaryElements isn't properly set on | |
| 31 // a SimpleIdentifier that's inside a property access. This bug should be | |
| 32 // fixed. | |
| 33 Source source = addSource(''' | |
| 34 class B {} | |
| 35 class M1 { | |
| 36 get x => null; | |
| 37 set x(value) {} | |
| 38 } | |
| 39 class M2 { | |
| 40 get x => null; | |
| 41 set x(value) {} | |
| 42 } | |
| 43 class C extends B with M1, M2 {} | |
| 44 void main() { | |
| 45 new C().x += 1; | |
| 46 } | |
| 47 '''); | |
| 48 LibraryElement library = resolve2(source); | |
| 49 assertNoErrors(source); | |
| 50 verify([source]); | |
| 51 // Verify that both the getter and setter for "x" in "new C().x" refer to | |
| 52 // the accessors defined in M2. | |
| 53 FunctionDeclaration main = | |
| 54 library.definingCompilationUnit.functions[0].computeNode(); | |
| 55 BlockFunctionBody body = main.functionExpression.body; | |
| 56 ExpressionStatement stmt = body.block.statements[0]; | |
| 57 AssignmentExpression assignment = stmt.expression; | |
| 58 PropertyAccess propertyAccess = assignment.leftHandSide; | |
| 59 expect( | |
| 60 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); | |
| 61 expect( | |
| 62 propertyAccess | |
| 63 .propertyName.auxiliaryElements.staticElement.enclosingElement.name, | |
| 64 'M2'); | |
| 65 } | |
| 66 | |
| 67 void fail_staticInvocation() { | |
| 68 Source source = addSource(r''' | |
| 69 class A { | |
| 70 static int get g => (a,b) => 0; | |
| 71 } | |
| 72 class B { | |
| 73 f() { | |
| 74 A.g(1,0); | |
| 75 } | |
| 76 }'''); | |
| 77 computeLibrarySourceErrors(source); | |
| 78 assertNoErrors(source); | |
| 79 verify([source]); | |
| 80 } | |
| 81 | |
| 82 void test_argumentResolution_required_matching() { | 29 void test_argumentResolution_required_matching() { |
| 83 Source source = addSource(r''' | 30 Source source = addSource(r''' |
| 84 class A { | 31 class A { |
| 85 void f() { | 32 void f() { |
| 86 g(1, 2, 3); | 33 g(1, 2, 3); |
| 87 } | 34 } |
| 88 void g(a, b, c) {} | 35 void g(a, b, c) {} |
| 89 }'''); | 36 }'''); |
| 90 _validateArgumentResolution(source, [0, 1, 2]); | 37 _validateArgumentResolution(source, [0, 1, 2]); |
| 91 } | 38 } |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 MethodDeclaration f = classC.getMethod('f').computeNode(); | 731 MethodDeclaration f = classC.getMethod('f').computeNode(); |
| 785 BlockFunctionBody body = f.body; | 732 BlockFunctionBody body = f.body; |
| 786 ExpressionStatement stmt = body.block.statements[0]; | 733 ExpressionStatement stmt = body.block.statements[0]; |
| 787 AssignmentExpression assignment = stmt.expression; | 734 AssignmentExpression assignment = stmt.expression; |
| 788 SimpleIdentifier leftHandSide = assignment.leftHandSide; | 735 SimpleIdentifier leftHandSide = assignment.leftHandSide; |
| 789 expect(leftHandSide.staticElement.enclosingElement.name, 'M2'); | 736 expect(leftHandSide.staticElement.enclosingElement.name, 'M2'); |
| 790 expect(leftHandSide.auxiliaryElements.staticElement.enclosingElement.name, | 737 expect(leftHandSide.auxiliaryElements.staticElement.enclosingElement.name, |
| 791 'M2'); | 738 'M2'); |
| 792 } | 739 } |
| 793 | 740 |
| 741 @failingTest |
| 742 void test_getter_and_setter_fromMixins_property_access() { |
| 743 // TODO(paulberry): it appears that auxiliaryElements isn't properly set on |
| 744 // a SimpleIdentifier that's inside a property access. This bug should be |
| 745 // fixed. |
| 746 Source source = addSource(''' |
| 747 class B {} |
| 748 class M1 { |
| 749 get x => null; |
| 750 set x(value) {} |
| 751 } |
| 752 class M2 { |
| 753 get x => null; |
| 754 set x(value) {} |
| 755 } |
| 756 class C extends B with M1, M2 {} |
| 757 void main() { |
| 758 new C().x += 1; |
| 759 } |
| 760 '''); |
| 761 LibraryElement library = resolve2(source); |
| 762 assertNoErrors(source); |
| 763 verify([source]); |
| 764 // Verify that both the getter and setter for "x" in "new C().x" refer to |
| 765 // the accessors defined in M2. |
| 766 FunctionDeclaration main = |
| 767 library.definingCompilationUnit.functions[0].computeNode(); |
| 768 BlockFunctionBody body = main.functionExpression.body; |
| 769 ExpressionStatement stmt = body.block.statements[0]; |
| 770 AssignmentExpression assignment = stmt.expression; |
| 771 PropertyAccess propertyAccess = assignment.leftHandSide; |
| 772 expect( |
| 773 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); |
| 774 expect( |
| 775 propertyAccess |
| 776 .propertyName.auxiliaryElements.staticElement.enclosingElement.name, |
| 777 'M2'); |
| 778 } |
| 779 |
| 794 void test_getter_fromMixins_bare_identifier() { | 780 void test_getter_fromMixins_bare_identifier() { |
| 795 Source source = addSource(''' | 781 Source source = addSource(''' |
| 796 class B {} | 782 class B {} |
| 797 class M1 { | 783 class M1 { |
| 798 get x => null; | 784 get x => null; |
| 799 } | 785 } |
| 800 class M2 { | 786 class M2 { |
| 801 get x => null; | 787 get x => null; |
| 802 } | 788 } |
| 803 class C extends B with M1, M2 { | 789 class C extends B with M1, M2 { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 library one; | 905 library one; |
| 920 import 'two.dart' as _two; | 906 import 'two.dart' as _two; |
| 921 main() { | 907 main() { |
| 922 _two.f(0); | 908 _two.f(0); |
| 923 }'''); | 909 }'''); |
| 924 computeLibrarySourceErrors(source); | 910 computeLibrarySourceErrors(source); |
| 925 assertNoErrors(source); | 911 assertNoErrors(source); |
| 926 verify([source]); | 912 verify([source]); |
| 927 } | 913 } |
| 928 | 914 |
| 915 void test_import_prefix_doesNotExist() { |
| 916 // |
| 917 // The primary purpose of this test is to ensure that we are only getting a |
| 918 // single error generated when the only problem is that an imported file |
| 919 // does not exist. |
| 920 // |
| 921 Source source = addNamedSource( |
| 922 "/a.dart", |
| 923 r''' |
| 924 import 'missing.dart' as p; |
| 925 int a = p.q + p.r.s; |
| 926 String b = p.t(a) + p.u(v: 0); |
| 927 p.T c = new p.T(); |
| 928 class D<E> extends p.T { |
| 929 D(int i) : super(i); |
| 930 p.U f = new p.V(); |
| 931 } |
| 932 class F implements p.T { |
| 933 p.T m(p.U u) => null; |
| 934 } |
| 935 class G extends Object with p.V {} |
| 936 class H extends D<p.W> { |
| 937 H(int i) : super(i); |
| 938 } |
| 939 '''); |
| 940 computeLibrarySourceErrors(source); |
| 941 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 942 verify([source]); |
| 943 } |
| 944 |
| 945 void test_import_show_doesNotExist() { |
| 946 // |
| 947 // The primary purpose of this test is to ensure that we are only getting a |
| 948 // single error generated when the only problem is that an imported file |
| 949 // does not exist. |
| 950 // |
| 951 Source source = addNamedSource( |
| 952 "/a.dart", |
| 953 r''' |
| 954 import 'missing.dart' show q, r, t, u, T, U, V, W; |
| 955 int a = q + r.s; |
| 956 String b = t(a) + u(v: 0); |
| 957 T c = new T(); |
| 958 class D<E> extends T { |
| 959 D(int i) : super(i); |
| 960 U f = new V(); |
| 961 } |
| 962 class F implements T { |
| 963 T m(U u) => null; |
| 964 } |
| 965 class G extends Object with V {} |
| 966 class H extends D<W> { |
| 967 H(int i) : super(i); |
| 968 } |
| 969 '''); |
| 970 computeLibrarySourceErrors(source); |
| 971 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 972 verify([source]); |
| 973 } |
| 974 |
| 929 void test_import_spaceInUri() { | 975 void test_import_spaceInUri() { |
| 930 addNamedSource( | 976 addNamedSource( |
| 931 "/sub folder/lib.dart", | 977 "/sub folder/lib.dart", |
| 932 r''' | 978 r''' |
| 933 library lib; | 979 library lib; |
| 934 foo() {}'''); | 980 foo() {}'''); |
| 935 Source source = addNamedSource( | 981 Source source = addNamedSource( |
| 936 "/app.dart", | 982 "/app.dart", |
| 937 r''' | 983 r''' |
| 938 import 'sub folder/lib.dart'; | 984 import 'sub folder/lib.dart'; |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 } | 1718 } |
| 1673 | 1719 |
| 1674 main() { | 1720 main() { |
| 1675 s = 123; | 1721 s = 123; |
| 1676 }'''); | 1722 }'''); |
| 1677 computeLibrarySourceErrors(source); | 1723 computeLibrarySourceErrors(source); |
| 1678 assertNoErrors(source); | 1724 assertNoErrors(source); |
| 1679 verify([source]); | 1725 verify([source]); |
| 1680 } | 1726 } |
| 1681 | 1727 |
| 1728 @failingTest |
| 1729 void test_staticInvocation() { |
| 1730 Source source = addSource(r''' |
| 1731 class A { |
| 1732 static int get g => (a,b) => 0; |
| 1733 } |
| 1734 class B { |
| 1735 f() { |
| 1736 A.g(1,0); |
| 1737 } |
| 1738 }'''); |
| 1739 computeLibrarySourceErrors(source); |
| 1740 assertNoErrors(source); |
| 1741 verify([source]); |
| 1742 } |
| 1743 |
| 1682 /** | 1744 /** |
| 1683 * Resolve the given source and verify that the arguments in a specific method
invocation were | 1745 * Resolve the given source and verify that the arguments in a specific method
invocation were |
| 1684 * correctly resolved. | 1746 * correctly resolved. |
| 1685 * | 1747 * |
| 1686 * The source is expected to be source for a compilation unit, the first decla
ration is expected | 1748 * The source is expected to be source for a compilation unit, the first decla
ration is expected |
| 1687 * to be a class, the first member of which is expected to be a method with a
block body, and the | 1749 * to be a class, the first member of which is expected to be a method with a
block body, and the |
| 1688 * first statement in the body is expected to be an expression statement whose
expression is a | 1750 * first statement in the body is expected to be an expression statement whose
expression is a |
| 1689 * method invocation. It is the arguments to that method invocation that are t
ested. The method | 1751 * method invocation. It is the arguments to that method invocation that are t
ested. The method |
| 1690 * invocation can contain errors. | 1752 * invocation can contain errors. |
| 1691 * | 1753 * |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 // check propagated type | 1815 // check propagated type |
| 1754 FunctionType propagatedType = node.propagatedType as FunctionType; | 1816 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 1755 expect(propagatedType.returnType, test.typeProvider.stringType); | 1817 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 1756 } on AnalysisException catch (e, stackTrace) { | 1818 } on AnalysisException catch (e, stackTrace) { |
| 1757 thrownException[0] = new CaughtException(e, stackTrace); | 1819 thrownException[0] = new CaughtException(e, stackTrace); |
| 1758 } | 1820 } |
| 1759 } | 1821 } |
| 1760 return null; | 1822 return null; |
| 1761 } | 1823 } |
| 1762 } | 1824 } |
| OLD | NEW |