Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1854863002: Issue 26096. Explicitly compute the result that ensures that directives are resolved in units. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.src.task.dart_test; 5 library analyzer.test.src.task.dart_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/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 runReflectiveTests(GenerateLintsTaskTest); 59 runReflectiveTests(GenerateLintsTaskTest);
60 runReflectiveTests(InferInstanceMembersInUnitTaskTest); 60 runReflectiveTests(InferInstanceMembersInUnitTaskTest);
61 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); 61 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest);
62 runReflectiveTests(InferStaticVariableTypeTaskTest); 62 runReflectiveTests(InferStaticVariableTypeTaskTest);
63 runReflectiveTests(LibraryErrorsReadyTaskTest); 63 runReflectiveTests(LibraryErrorsReadyTaskTest);
64 runReflectiveTests(LibraryUnitErrorsTaskTest); 64 runReflectiveTests(LibraryUnitErrorsTaskTest);
65 runReflectiveTests(ParseDartTaskTest); 65 runReflectiveTests(ParseDartTaskTest);
66 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); 66 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest);
67 runReflectiveTests(PropagateVariableTypesInUnitTaskTest); 67 runReflectiveTests(PropagateVariableTypesInUnitTaskTest);
68 runReflectiveTests(PropagateVariableTypeTaskTest); 68 runReflectiveTests(PropagateVariableTypeTaskTest);
69 runReflectiveTests(ResolveDirectiveElementsTaskTest);
69 runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); 70 runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest);
70 runReflectiveTests(ResolveLibraryTaskTest); 71 runReflectiveTests(ResolveLibraryTaskTest);
71 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); 72 runReflectiveTests(ResolveLibraryTypeNamesTaskTest);
72 runReflectiveTests(ResolveUnitTaskTest); 73 runReflectiveTests(ResolveUnitTaskTest);
73 runReflectiveTests(ResolveUnitTypeNamesTaskTest); 74 runReflectiveTests(ResolveUnitTypeNamesTaskTest);
74 runReflectiveTests(ResolveVariableReferencesTaskTest); 75 runReflectiveTests(ResolveVariableReferencesTaskTest);
75 runReflectiveTests(ScanDartTaskTest); 76 runReflectiveTests(ScanDartTaskTest);
76 runReflectiveTests(StrongModeInferenceTest); 77 runReflectiveTests(StrongModeInferenceTest);
77 runReflectiveTests(StrongModeVerifyUnitTaskTest); 78 runReflectiveTests(StrongModeVerifyUnitTaskTest);
78 runReflectiveTests(VerifyUnitTaskTest); 79 runReflectiveTests(VerifyUnitTaskTest);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 new isInstanceOf<LibraryErrorsReadyTask>(); 124 new isInstanceOf<LibraryErrorsReadyTask>();
124 isInstanceOf isLibraryUnitErrorsTask = 125 isInstanceOf isLibraryUnitErrorsTask =
125 new isInstanceOf<LibraryUnitErrorsTask>(); 126 new isInstanceOf<LibraryUnitErrorsTask>();
126 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); 127 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>();
127 isInstanceOf isPartiallyResolveUnitReferencesTask = 128 isInstanceOf isPartiallyResolveUnitReferencesTask =
128 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); 129 new isInstanceOf<PartiallyResolveUnitReferencesTask>();
129 isInstanceOf isPropagateVariableTypesInUnitTask = 130 isInstanceOf isPropagateVariableTypesInUnitTask =
130 new isInstanceOf<PropagateVariableTypesInUnitTask>(); 131 new isInstanceOf<PropagateVariableTypesInUnitTask>();
131 isInstanceOf isPropagateVariableTypeTask = 132 isInstanceOf isPropagateVariableTypeTask =
132 new isInstanceOf<PropagateVariableTypeTask>(); 133 new isInstanceOf<PropagateVariableTypeTask>();
134 isInstanceOf isResolveDirectiveElementsTask =
135 new isInstanceOf<ResolveDirectiveElementsTask>();
133 isInstanceOf isResolveLibraryTask = new isInstanceOf<ResolveLibraryTask>(); 136 isInstanceOf isResolveLibraryTask = new isInstanceOf<ResolveLibraryTask>();
134 isInstanceOf isResolveLibraryTypeNamesTask = 137 isInstanceOf isResolveLibraryTypeNamesTask =
135 new isInstanceOf<ResolveLibraryTypeNamesTask>(); 138 new isInstanceOf<ResolveLibraryTypeNamesTask>();
136 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>(); 139 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>();
137 isInstanceOf isResolveUnitTypeNamesTask = 140 isInstanceOf isResolveUnitTypeNamesTask =
138 new isInstanceOf<ResolveUnitTypeNamesTask>(); 141 new isInstanceOf<ResolveUnitTypeNamesTask>();
139 isInstanceOf isResolveVariableReferencesTask = 142 isInstanceOf isResolveVariableReferencesTask =
140 new isInstanceOf<ResolveVariableReferencesTask>(); 143 new isInstanceOf<ResolveVariableReferencesTask>();
141 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); 144 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>();
142 isInstanceOf isStrongModeVerifyUnitTask = 145 isInstanceOf isStrongModeVerifyUnitTask =
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 @reflectiveTest 558 @reflectiveTest
556 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { 559 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest {
557 test_created_resolved_unit() { 560 test_created_resolved_unit() {
558 Source source = newSource( 561 Source source = newSource(
559 '/test.dart', 562 '/test.dart',
560 r''' 563 r'''
561 library lib; 564 library lib;
562 class A {} 565 class A {}
563 '''); 566 ''');
564 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 567 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
565 computeResult(target, RESOLVED_UNIT2); 568 computeResult(target, RESOLVED_UNIT3);
566 expect(outputs[RESOLVED_UNIT2], isNotNull); 569 expect(outputs[RESOLVED_UNIT3], isNotNull);
567 expect(outputs[CREATED_RESOLVED_UNIT2], isTrue); 570 expect(outputs[CREATED_RESOLVED_UNIT3], isTrue);
568 } 571 }
569 572
570 test_perform() { 573 test_perform() {
571 Source source = newSource( 574 Source source = newSource(
572 '/test.dart', 575 '/test.dart',
573 ''' 576 '''
574 enum MyEnum { 577 enum MyEnum {
575 A, B 578 A, B
576 } 579 }
577 '''); 580 ''');
578 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2, 581 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT3,
579 matcher: isBuildEnumMemberElementsTask); 582 matcher: isBuildEnumMemberElementsTask);
580 CompilationUnit unit = outputs[RESOLVED_UNIT2]; 583 CompilationUnit unit = outputs[RESOLVED_UNIT3];
581 // validate Element 584 // validate Element
582 ClassElement enumElement = unit.element.getEnum('MyEnum'); 585 ClassElement enumElement = unit.element.getEnum('MyEnum');
583 List<FieldElement> fields = enumElement.fields; 586 List<FieldElement> fields = enumElement.fields;
584 expect(fields, hasLength(4)); 587 expect(fields, hasLength(4));
585 { 588 {
586 FieldElementImpl index = fields[0]; 589 FieldElementImpl index = fields[0];
587 expect(index, isNotNull); 590 expect(index, isNotNull);
588 expect(index.name, 'index'); 591 expect(index.name, 'index');
589 expect(index.isStatic, isFalse); 592 expect(index.isStatic, isFalse);
590 expect(index.evaluationResult, isNull); 593 expect(index.evaluationResult, isNull);
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 1205
1203 test_enumConstant() { 1206 test_enumConstant() {
1204 Source source = newSource( 1207 Source source = newSource(
1205 '/test.dart', 1208 '/test.dart',
1206 ''' 1209 '''
1207 enum E {A, B, C} 1210 enum E {A, B, C}
1208 '''); 1211 ''');
1209 // First compute the resolved unit for the source. 1212 // First compute the resolved unit for the source.
1210 LibrarySpecificUnit librarySpecificUnit = 1213 LibrarySpecificUnit librarySpecificUnit =
1211 new LibrarySpecificUnit(source, source); 1214 new LibrarySpecificUnit(source, source);
1212 computeResult(librarySpecificUnit, RESOLVED_UNIT2); 1215 computeResult(librarySpecificUnit, RESOLVED_UNIT3);
1213 CompilationUnit unit = outputs[RESOLVED_UNIT2]; 1216 CompilationUnit unit = outputs[RESOLVED_UNIT3];
1214 // Find the element for 'A' 1217 // Find the element for 'A'
1215 EnumDeclaration enumDeclaration = unit.declarations[0]; 1218 EnumDeclaration enumDeclaration = unit.declarations[0];
1216 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0]; 1219 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0];
1217 FieldElement constantElement = constantDeclaration.element; 1220 FieldElement constantElement = constantDeclaration.element;
1218 // Now compute the dependencies for the constant and check that there are 1221 // Now compute the dependencies for the constant and check that there are
1219 // none. 1222 // none.
1220 computeResult(constantElement, CONSTANT_DEPENDENCIES, 1223 computeResult(constantElement, CONSTANT_DEPENDENCIES,
1221 matcher: isComputeConstantDependenciesTask); 1224 matcher: isComputeConstantDependenciesTask);
1222 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty); 1225 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty);
1223 } 1226 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 } 1492 }
1490 1493
1491 test_created_resolved_unit() { 1494 test_created_resolved_unit() {
1492 Source source = newSource( 1495 Source source = newSource(
1493 '/test.dart', 1496 '/test.dart',
1494 r''' 1497 r'''
1495 library lib; 1498 library lib;
1496 class A {} 1499 class A {}
1497 '''); 1500 ''');
1498 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1501 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1499 computeResult(target, RESOLVED_UNIT5); 1502 computeResult(target, RESOLVED_UNIT6);
1500 expect(outputs[RESOLVED_UNIT5], isNotNull); 1503 expect(outputs[RESOLVED_UNIT6], isNotNull);
1501 expect(outputs[CREATED_RESOLVED_UNIT5], isTrue); 1504 expect(outputs[CREATED_RESOLVED_UNIT6], isTrue);
1502 } 1505 }
1503 1506
1504 test_perform() { 1507 test_perform() {
1505 AnalysisTarget source = newSource( 1508 AnalysisTarget source = newSource(
1506 '/test.dart', 1509 '/test.dart',
1507 ''' 1510 '''
1508 const a = b; 1511 const a = b;
1509 const b = 0; 1512 const b = 0;
1510 '''); 1513 ''');
1511 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1514 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1512 computeResult(target, RESOLVED_UNIT5); 1515 computeResult(target, RESOLVED_UNIT6);
1513 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 1516 CompilationUnit unit = outputs[RESOLVED_UNIT6];
1514 TopLevelVariableElement elementA = unit.element.topLevelVariables[0]; 1517 TopLevelVariableElement elementA = unit.element.topLevelVariables[0];
1515 TopLevelVariableElement elementB = unit.element.topLevelVariables[1]; 1518 TopLevelVariableElement elementB = unit.element.topLevelVariables[1];
1516 1519
1517 computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES, 1520 computeResult(elementA, INFERABLE_STATIC_VARIABLE_DEPENDENCIES,
1518 matcher: isComputeInferableStaticVariableDependenciesTask); 1521 matcher: isComputeInferableStaticVariableDependenciesTask);
1519 expect(outputs, hasLength(1)); 1522 expect(outputs, hasLength(1));
1520 List<VariableElement> dependencies = outputs[ 1523 List<VariableElement> dependencies = outputs[
1521 INFERABLE_STATIC_VARIABLE_DEPENDENCIES] as List<VariableElement>; 1524 INFERABLE_STATIC_VARIABLE_DEPENDENCIES] as List<VariableElement>;
1522 expect(dependencies, unorderedEquals([elementB])); 1525 expect(dependencies, unorderedEquals([elementB]));
1523 } 1526 }
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 var a4 = 4; 2018 var a4 = 4;
2016 } 2019 }
2017 class B { 2020 class B {
2018 static const b1 = 1; 2021 static const b1 = 1;
2019 static final b2 = 2; 2022 static final b2 = 2;
2020 static final b3; 2023 static final b3;
2021 static var b4 = 4; 2024 static var b4 = 4;
2022 } 2025 }
2023 '''); 2026 ''');
2024 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2027 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2025 computeResult(target, RESOLVED_UNIT5); 2028 computeResult(target, RESOLVED_UNIT6);
2026 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2029 CompilationUnit unit = outputs[RESOLVED_UNIT6];
2027 FieldElement elementA = AstFinder.getFieldInClassElement(unit, 'A', 'a'); 2030 FieldElement elementA = AstFinder.getFieldInClassElement(unit, 'A', 'a');
2028 // compute 2031 // compute
2029 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, 2032 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES,
2030 matcher: isComputePropagableVariableDependenciesTask); 2033 matcher: isComputePropagableVariableDependenciesTask);
2031 // verify 2034 // verify
2032 expect(outputs, hasLength(1)); 2035 expect(outputs, hasLength(1));
2033 List<VariableElement> dependencies = 2036 List<VariableElement> dependencies =
2034 getPropagableVariableDependencies(outputs); 2037 getPropagableVariableDependencies(outputs);
2035 expect( 2038 expect(
2036 dependencies, 2039 dependencies,
2037 unorderedEquals([ 2040 unorderedEquals([
2038 AstFinder.getFieldInClassElement(unit, 'A', 'a1'), 2041 AstFinder.getFieldInClassElement(unit, 'A', 'a1'),
2039 AstFinder.getFieldInClassElement(unit, 'A', 'a2'), 2042 AstFinder.getFieldInClassElement(unit, 'A', 'a2'),
2040 AstFinder.getFieldInClassElement(unit, 'B', 'b1'), 2043 AstFinder.getFieldInClassElement(unit, 'B', 'b1'),
2041 AstFinder.getFieldInClassElement(unit, 'B', 'b2') 2044 AstFinder.getFieldInClassElement(unit, 'B', 'b2')
2042 ])); 2045 ]));
2043 } 2046 }
2044 2047
2045 test_perform_topLevel() { 2048 test_perform_topLevel() {
2046 AnalysisTarget source = newSource( 2049 AnalysisTarget source = newSource(
2047 '/test.dart', 2050 '/test.dart',
2048 ''' 2051 '''
2049 const a = d1 + d2 + d3 + d4; 2052 const a = d1 + d2 + d3 + d4;
2050 const d1 = 1; 2053 const d1 = 1;
2051 final d2 = 2; 2054 final d2 = 2;
2052 final d3; 2055 final d3;
2053 var d4 = 4; 2056 var d4 = 4;
2054 '''); 2057 ''');
2055 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2058 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2056 computeResult(target, RESOLVED_UNIT5); 2059 computeResult(target, RESOLVED_UNIT6);
2057 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2060 CompilationUnit unit = outputs[RESOLVED_UNIT6];
2058 TopLevelVariableElement elementA = 2061 TopLevelVariableElement elementA =
2059 AstFinder.getTopLevelVariableElement(unit, 'a'); 2062 AstFinder.getTopLevelVariableElement(unit, 'a');
2060 // compute 2063 // compute
2061 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, 2064 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES,
2062 matcher: isComputePropagableVariableDependenciesTask); 2065 matcher: isComputePropagableVariableDependenciesTask);
2063 // verify 2066 // verify
2064 expect(outputs, hasLength(1)); 2067 expect(outputs, hasLength(1));
2065 List<VariableElement> dependencies = 2068 List<VariableElement> dependencies =
2066 getPropagableVariableDependencies(outputs); 2069 getPropagableVariableDependencies(outputs);
2067 expect( 2070 expect(
2068 dependencies, 2071 dependencies,
2069 unorderedEquals([ 2072 unorderedEquals([
2070 AstFinder.getTopLevelVariableElement(unit, 'd1'), 2073 AstFinder.getTopLevelVariableElement(unit, 'd1'),
2071 AstFinder.getTopLevelVariableElement(unit, 'd2') 2074 AstFinder.getTopLevelVariableElement(unit, 'd2')
2072 ])); 2075 ]));
2073 } 2076 }
2074 2077
2075 test_perform_topLevel_ignoreLocal() { 2078 test_perform_topLevel_ignoreLocal() {
2076 AnalysisTarget source = newSource( 2079 AnalysisTarget source = newSource(
2077 '/test.dart', 2080 '/test.dart',
2078 ''' 2081 '''
2079 final a = () { 2082 final a = () {
2080 const b = 2; 2083 const b = 2;
2081 const c = 3; 2084 const c = 3;
2082 return b + c; 2085 return b + c;
2083 }() + d; 2086 }() + d;
2084 final d = 4; 2087 final d = 4;
2085 '''); 2088 ''');
2086 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2089 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2087 computeResult(target, RESOLVED_UNIT5); 2090 computeResult(target, RESOLVED_UNIT6);
2088 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2091 CompilationUnit unit = outputs[RESOLVED_UNIT6];
2089 TopLevelVariableElement elementA = 2092 TopLevelVariableElement elementA =
2090 AstFinder.getTopLevelVariableElement(unit, 'a'); 2093 AstFinder.getTopLevelVariableElement(unit, 'a');
2091 // compute 2094 // compute
2092 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, 2095 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES,
2093 matcher: isComputePropagableVariableDependenciesTask); 2096 matcher: isComputePropagableVariableDependenciesTask);
2094 // verify 2097 // verify
2095 expect(outputs, hasLength(1)); 2098 expect(outputs, hasLength(1));
2096 List<VariableElement> dependencies = 2099 List<VariableElement> dependencies =
2097 getPropagableVariableDependencies(outputs); 2100 getPropagableVariableDependencies(outputs);
2098 expect(dependencies, 2101 expect(dependencies,
2099 unorderedEquals([AstFinder.getTopLevelVariableElement(unit, 'd')])); 2102 unorderedEquals([AstFinder.getTopLevelVariableElement(unit, 'd')]));
2100 } 2103 }
2101 2104
2102 test_perform_topLevel_withoutSpaceAfterType() { 2105 test_perform_topLevel_withoutSpaceAfterType() {
2103 AnalysisTarget source = newSource( 2106 AnalysisTarget source = newSource(
2104 '/test.dart', 2107 '/test.dart',
2105 ''' 2108 '''
2106 const List<int>a=[b, c]; 2109 const List<int>a=[b, c];
2107 const b = 1; 2110 const b = 1;
2108 const c = 2; 2111 const c = 2;
2109 '''); 2112 ''');
2110 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2113 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2111 computeResult(target, RESOLVED_UNIT5); 2114 computeResult(target, RESOLVED_UNIT6);
2112 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2115 CompilationUnit unit = outputs[RESOLVED_UNIT6];
2113 TopLevelVariableElement elementA = 2116 TopLevelVariableElement elementA =
2114 AstFinder.getTopLevelVariableElement(unit, 'a'); 2117 AstFinder.getTopLevelVariableElement(unit, 'a');
2115 // compute 2118 // compute
2116 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES, 2119 computeResult(elementA, PROPAGABLE_VARIABLE_DEPENDENCIES,
2117 matcher: isComputePropagableVariableDependenciesTask); 2120 matcher: isComputePropagableVariableDependenciesTask);
2118 // verify 2121 // verify
2119 expect(outputs, hasLength(1)); 2122 expect(outputs, hasLength(1));
2120 List<VariableElement> dependencies = 2123 List<VariableElement> dependencies =
2121 getPropagableVariableDependencies(outputs); 2124 getPropagableVariableDependencies(outputs);
2122 expect( 2125 expect(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 @reflectiveTest 2212 @reflectiveTest
2210 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { 2213 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest {
2211 test_created_resolved_unit() { 2214 test_created_resolved_unit() {
2212 Source source = newSource( 2215 Source source = newSource(
2213 '/test.dart', 2216 '/test.dart',
2214 r''' 2217 r'''
2215 library lib; 2218 library lib;
2216 class A {} 2219 class A {}
2217 '''); 2220 ''');
2218 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2221 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2219 computeResult(target, RESOLVED_UNIT11); 2222 computeResult(target, RESOLVED_UNIT12);
2220 expect(outputs[RESOLVED_UNIT11], isNotNull); 2223 expect(outputs[RESOLVED_UNIT12], isNotNull);
2221 expect(outputs[CREATED_RESOLVED_UNIT11], isTrue); 2224 expect(outputs[CREATED_RESOLVED_UNIT12], isTrue);
2222 } 2225 }
2223 2226
2224 test_perform() { 2227 test_perform() {
2225 Source source = newSource( 2228 Source source = newSource(
2226 '/test.dart', 2229 '/test.dart',
2227 ''' 2230 '''
2228 class C { 2231 class C {
2229 const C(); 2232 const C();
2230 } 2233 }
2231 2234
2232 @x 2235 @x
2233 f() {} 2236 f() {}
2234 2237
2235 const x = const C(); 2238 const x = const C();
2236 '''); 2239 ''');
2237 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2240 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2238 computeResult(target, RESOLVED_UNIT11, 2241 computeResult(target, RESOLVED_UNIT12,
2239 matcher: isEvaluateUnitConstantsTask); 2242 matcher: isEvaluateUnitConstantsTask);
2240 CompilationUnit unit = outputs[RESOLVED_UNIT11]; 2243 CompilationUnit unit = outputs[RESOLVED_UNIT12];
2241 CompilationUnitElement unitElement = unit.element; 2244 CompilationUnitElement unitElement = unit.element;
2242 expect( 2245 expect(
2243 (unitElement.types[0].constructors[0] as ConstructorElementImpl) 2246 (unitElement.types[0].constructors[0] as ConstructorElementImpl)
2244 .isCycleFree, 2247 .isCycleFree,
2245 isTrue); 2248 isTrue);
2246 expect( 2249 expect(
2247 (unitElement.functions[0].metadata[0] as ElementAnnotationImpl) 2250 (unitElement.functions[0].metadata[0] as ElementAnnotationImpl)
2248 .evaluationResult, 2251 .evaluationResult,
2249 isNotNull); 2252 isNotNull);
2250 expect( 2253 expect(
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
2737 @reflectiveTest 2740 @reflectiveTest
2738 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest { 2741 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest {
2739 test_created_resolved_unit() { 2742 test_created_resolved_unit() {
2740 Source source = newSource( 2743 Source source = newSource(
2741 '/test.dart', 2744 '/test.dart',
2742 r''' 2745 r'''
2743 library lib; 2746 library lib;
2744 class A {} 2747 class A {}
2745 '''); 2748 ''');
2746 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2749 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2747 computeResult(target, RESOLVED_UNIT9); 2750 computeResult(target, RESOLVED_UNIT10);
2748 expect(outputs[RESOLVED_UNIT9], isNotNull); 2751 expect(outputs[RESOLVED_UNIT10], isNotNull);
2749 expect(outputs[CREATED_RESOLVED_UNIT9], isTrue); 2752 expect(outputs[CREATED_RESOLVED_UNIT10], isTrue);
2750 } 2753 }
2751 2754
2752 void test_perform() { 2755 void test_perform() {
2753 enableStrongMode(); 2756 enableStrongMode();
2754 AnalysisTarget source = newSource( 2757 AnalysisTarget source = newSource(
2755 '/test.dart', 2758 '/test.dart',
2756 ''' 2759 '''
2757 class A { 2760 class A {
2758 X f; 2761 X f;
2759 Y m(Z x) {} 2762 Y m(Z x) {}
2760 } 2763 }
2761 class B extends A { 2764 class B extends A {
2762 var f; 2765 var f;
2763 m(x) {} 2766 m(x) {}
2764 } 2767 }
2765 class X {} 2768 class X {}
2766 class Y {} 2769 class Y {}
2767 class Z {} 2770 class Z {}
2768 '''); 2771 ''');
2769 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9, 2772 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10,
2770 matcher: isInferInstanceMembersInUnitTask); 2773 matcher: isInferInstanceMembersInUnitTask);
2771 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 2774 CompilationUnit unit = outputs[RESOLVED_UNIT10];
2772 VariableDeclaration field = AstFinder.getFieldInClass(unit, 'B', 'f'); 2775 VariableDeclaration field = AstFinder.getFieldInClass(unit, 'B', 'f');
2773 MethodDeclaration method = AstFinder.getMethodInClass(unit, 'B', 'm'); 2776 MethodDeclaration method = AstFinder.getMethodInClass(unit, 'B', 'm');
2774 DartType typeX = AstFinder.getClass(unit, 'X').element.type; 2777 DartType typeX = AstFinder.getClass(unit, 'X').element.type;
2775 DartType typeY = AstFinder.getClass(unit, 'Y').element.type; 2778 DartType typeY = AstFinder.getClass(unit, 'Y').element.type;
2776 DartType typeZ = AstFinder.getClass(unit, 'Z').element.type; 2779 DartType typeZ = AstFinder.getClass(unit, 'Z').element.type;
2777 2780
2778 expect(field.element.type, typeX); 2781 expect(field.element.type, typeX);
2779 expect(method.element.returnType, typeY); 2782 expect(method.element.returnType, typeY);
2780 expect(method.element.parameters[0].type, typeZ); 2783 expect(method.element.parameters[0].type, typeZ);
2781 } 2784 }
(...skipping 11 matching lines...) Expand all
2793 '/second.dart', 2796 '/second.dart',
2794 ''' 2797 '''
2795 import 'first.dart'; 2798 import 'first.dart';
2796 2799
2797 const b = a; 2800 const b = a;
2798 class M { 2801 class M {
2799 String c = a; 2802 String c = a;
2800 } 2803 }
2801 '''); 2804 ''');
2802 computeResult( 2805 computeResult(
2803 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9, 2806 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10,
2804 matcher: isInferInstanceMembersInUnitTask); 2807 matcher: isInferInstanceMembersInUnitTask);
2805 CompilationUnit firstUnit = outputs[RESOLVED_UNIT9]; 2808 CompilationUnit firstUnit = outputs[RESOLVED_UNIT10];
2806 computeResult( 2809 computeResult(
2807 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9); 2810 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10);
2808 CompilationUnit secondUnit = outputs[RESOLVED_UNIT9]; 2811 CompilationUnit secondUnit = outputs[RESOLVED_UNIT10];
2809 2812
2810 VariableDeclaration variableA = 2813 VariableDeclaration variableA =
2811 AstFinder.getTopLevelVariable(firstUnit, 'a'); 2814 AstFinder.getTopLevelVariable(firstUnit, 'a');
2812 VariableDeclaration variableB = 2815 VariableDeclaration variableB =
2813 AstFinder.getTopLevelVariable(secondUnit, 'b'); 2816 AstFinder.getTopLevelVariable(secondUnit, 'b');
2814 VariableDeclaration variableC = 2817 VariableDeclaration variableC =
2815 AstFinder.getFieldInClass(secondUnit, 'M', 'c'); 2818 AstFinder.getFieldInClass(secondUnit, 'M', 'c');
2816 InterfaceType stringType = context.typeProvider.stringType; 2819 InterfaceType stringType = context.typeProvider.stringType;
2817 2820
2818 expect(variableA.element.type, stringType); 2821 expect(variableA.element.type, stringType);
2819 expect(variableB.element.type, stringType); 2822 expect(variableB.element.type, stringType);
2820 expect(variableB.initializer.staticType, stringType); 2823 expect(variableB.initializer.staticType, stringType);
2821 expect(variableC.element.type, stringType); 2824 expect(variableC.element.type, stringType);
2822 expect(variableC.initializer.staticType, stringType); 2825 expect(variableC.initializer.staticType, stringType);
2823 } 2826 }
2824 2827
2825 void test_perform_reresolution() { 2828 void test_perform_reresolution() {
2826 enableStrongMode(); 2829 enableStrongMode();
2827 AnalysisTarget source = newSource( 2830 AnalysisTarget source = newSource(
2828 '/test.dart', 2831 '/test.dart',
2829 ''' 2832 '''
2830 const topLevel = ''; 2833 const topLevel = '';
2831 class C { 2834 class C {
2832 String field = topLevel; 2835 String field = topLevel;
2833 } 2836 }
2834 '''); 2837 ''');
2835 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9); 2838 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10);
2836 CompilationUnit unit = outputs[RESOLVED_UNIT9]; 2839 CompilationUnit unit = outputs[RESOLVED_UNIT10];
2837 VariableDeclaration topLevelDecl = 2840 VariableDeclaration topLevelDecl =
2838 AstFinder.getTopLevelVariable(unit, 'topLevel'); 2841 AstFinder.getTopLevelVariable(unit, 'topLevel');
2839 VariableDeclaration fieldDecl = 2842 VariableDeclaration fieldDecl =
2840 AstFinder.getFieldInClass(unit, 'C', 'field'); 2843 AstFinder.getFieldInClass(unit, 'C', 'field');
2841 VariableElement topLevel = topLevelDecl.name.staticElement; 2844 VariableElement topLevel = topLevelDecl.name.staticElement;
2842 VariableElement field = fieldDecl.name.staticElement; 2845 VariableElement field = fieldDecl.name.staticElement;
2843 2846
2844 InterfaceType stringType = context.typeProvider.stringType; 2847 InterfaceType stringType = context.typeProvider.stringType;
2845 expect(topLevel.type, stringType); 2848 expect(topLevel.type, stringType);
2846 expect(field.type, stringType); 2849 expect(field.type, stringType);
(...skipping 10 matching lines...) Expand all
2857 } 2860 }
2858 2861
2859 test_created_resolved_unit() { 2862 test_created_resolved_unit() {
2860 Source source = newSource( 2863 Source source = newSource(
2861 '/test.dart', 2864 '/test.dart',
2862 r''' 2865 r'''
2863 library lib; 2866 library lib;
2864 class A {} 2867 class A {}
2865 '''); 2868 ''');
2866 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2869 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2867 computeResult(target, RESOLVED_UNIT7); 2870 computeResult(target, RESOLVED_UNIT8);
2868 expect(outputs[RESOLVED_UNIT7], isNotNull); 2871 expect(outputs[RESOLVED_UNIT8], isNotNull);
2869 expect(outputs[CREATED_RESOLVED_UNIT7], isTrue); 2872 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue);
2870 } 2873 }
2871 2874
2872 void test_perform_const_field() { 2875 void test_perform_const_field() {
2873 enableStrongMode(); 2876 enableStrongMode();
2874 AnalysisTarget source = newSource( 2877 AnalysisTarget source = newSource(
2875 '/test.dart', 2878 '/test.dart',
2876 ''' 2879 '''
2877 class M { 2880 class M {
2878 static const X = ""; 2881 static const X = "";
2879 } 2882 }
2880 '''); 2883 ''');
2881 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7, 2884 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
2882 matcher: isInferStaticVariableTypesInUnitTask); 2885 matcher: isInferStaticVariableTypesInUnitTask);
2883 CompilationUnit unit = outputs[RESOLVED_UNIT7]; 2886 CompilationUnit unit = outputs[RESOLVED_UNIT8];
2884 VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X'); 2887 VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X');
2885 InterfaceType stringType = context.typeProvider.stringType; 2888 InterfaceType stringType = context.typeProvider.stringType;
2886 expect(declaration.element.type, stringType); 2889 expect(declaration.element.type, stringType);
2887 } 2890 }
2888 2891
2889 test_perform_hasParseError() { 2892 test_perform_hasParseError() {
2890 Source source = newSource( 2893 Source source = newSource(
2891 '/test.dart', 2894 '/test.dart',
2892 r''' 2895 r'''
2893 @(i $= 2896 @(i $=
2894 '''); 2897 ''');
2895 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2898 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2896 computeResult(target, RESOLVED_UNIT7); 2899 computeResult(target, RESOLVED_UNIT8);
2897 expect(outputs[RESOLVED_UNIT7], isNotNull); 2900 expect(outputs[RESOLVED_UNIT8], isNotNull);
2898 expect(outputs[CREATED_RESOLVED_UNIT7], isTrue); 2901 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue);
2899 } 2902 }
2900 2903
2901 void test_perform_nestedDeclarations() { 2904 void test_perform_nestedDeclarations() {
2902 enableStrongMode(); 2905 enableStrongMode();
2903 AnalysisTarget source = newSource( 2906 AnalysisTarget source = newSource(
2904 '/test.dart', 2907 '/test.dart',
2905 ''' 2908 '''
2906 var f = (int x) { 2909 var f = (int x) {
2907 int squared(int value) => value * value; 2910 int squared(int value) => value * value;
2908 var xSquared = squared(x); 2911 var xSquared = squared(x);
2909 return xSquared; 2912 return xSquared;
2910 }; 2913 };
2911 '''); 2914 ''');
2912 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7, 2915 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
2913 matcher: isInferStaticVariableTypesInUnitTask); 2916 matcher: isInferStaticVariableTypesInUnitTask);
2914 } 2917 }
2915 2918
2916 void test_perform_recursive() { 2919 void test_perform_recursive() {
2917 enableStrongMode(); 2920 enableStrongMode();
2918 AnalysisTarget firstSource = newSource( 2921 AnalysisTarget firstSource = newSource(
2919 '/first.dart', 2922 '/first.dart',
2920 ''' 2923 '''
2921 import 'second.dart'; 2924 import 'second.dart';
2922 2925
2923 var a = new M(); 2926 var a = new M();
2924 var c = b; 2927 var c = b;
2925 '''); 2928 ''');
2926 AnalysisTarget secondSource = newSource( 2929 AnalysisTarget secondSource = newSource(
2927 '/second.dart', 2930 '/second.dart',
2928 ''' 2931 '''
2929 import 'first.dart'; 2932 import 'first.dart';
2930 2933
2931 var b = a; 2934 var b = a;
2932 class M {} 2935 class M {}
2933 '''); 2936 ''');
2934 computeResult( 2937 computeResult(
2935 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT7, 2938 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8,
2936 matcher: isInferStaticVariableTypesInUnitTask); 2939 matcher: isInferStaticVariableTypesInUnitTask);
2937 CompilationUnit firstUnit = outputs[RESOLVED_UNIT7]; 2940 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8];
2938 computeResult( 2941 computeResult(
2939 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT7); 2942 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8);
2940 CompilationUnit secondUnit = outputs[RESOLVED_UNIT7]; 2943 CompilationUnit secondUnit = outputs[RESOLVED_UNIT8];
2941 2944
2942 VariableDeclaration variableA = 2945 VariableDeclaration variableA =
2943 AstFinder.getTopLevelVariable(firstUnit, 'a'); 2946 AstFinder.getTopLevelVariable(firstUnit, 'a');
2944 VariableDeclaration variableB = 2947 VariableDeclaration variableB =
2945 AstFinder.getTopLevelVariable(secondUnit, 'b'); 2948 AstFinder.getTopLevelVariable(secondUnit, 'b');
2946 VariableDeclaration variableC = 2949 VariableDeclaration variableC =
2947 AstFinder.getTopLevelVariable(firstUnit, 'c'); 2950 AstFinder.getTopLevelVariable(firstUnit, 'c');
2948 ClassDeclaration classM = AstFinder.getClass(secondUnit, 'M'); 2951 ClassDeclaration classM = AstFinder.getClass(secondUnit, 'M');
2949 DartType typeM = classM.element.type; 2952 DartType typeM = classM.element.type;
2950 2953
2951 expect(variableA.element.type, typeM); 2954 expect(variableA.element.type, typeM);
2952 expect(variableB.element.type, typeM); 2955 expect(variableB.element.type, typeM);
2953 expect(variableB.initializer.staticType, typeM); 2956 expect(variableB.initializer.staticType, typeM);
2954 expect(variableC.element.type, typeM); 2957 expect(variableC.element.type, typeM);
2955 expect(variableC.initializer.staticType, typeM); 2958 expect(variableC.initializer.staticType, typeM);
2956 } 2959 }
2957 2960
2958 void test_perform_simple() { 2961 void test_perform_simple() {
2959 enableStrongMode(); 2962 enableStrongMode();
2960 AnalysisTarget source = newSource( 2963 AnalysisTarget source = newSource(
2961 '/test.dart', 2964 '/test.dart',
2962 ''' 2965 '''
2963 var X = 1; 2966 var X = 1;
2964 2967
2965 var Y = () { 2968 var Y = () {
2966 return 1 + X; 2969 return 1 + X;
2967 }; 2970 };
2968 '''); 2971 ''');
2969 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7, 2972 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
2970 matcher: isInferStaticVariableTypesInUnitTask); 2973 matcher: isInferStaticVariableTypesInUnitTask);
2971 CompilationUnit unit = outputs[RESOLVED_UNIT7]; 2974 CompilationUnit unit = outputs[RESOLVED_UNIT8];
2972 TopLevelVariableDeclaration declaration = unit.declarations[1]; 2975 TopLevelVariableDeclaration declaration = unit.declarations[1];
2973 FunctionExpression function = 2976 FunctionExpression function =
2974 declaration.variables.variables[0].initializer; 2977 declaration.variables.variables[0].initializer;
2975 BlockFunctionBody body = function.body; 2978 BlockFunctionBody body = function.body;
2976 ReturnStatement statement = body.block.statements[0]; 2979 ReturnStatement statement = body.block.statements[0];
2977 Expression expression = statement.expression; 2980 Expression expression = statement.expression;
2978 InterfaceType intType = context.typeProvider.intType; 2981 InterfaceType intType = context.typeProvider.intType;
2979 expect(expression.staticType, intType); 2982 expect(expression.staticType, intType);
2980 } 2983 }
2981 } 2984 }
2982 2985
2983 @reflectiveTest 2986 @reflectiveTest
2984 class InferStaticVariableTypeTaskTest extends _AbstractDartTaskTest { 2987 class InferStaticVariableTypeTaskTest extends _AbstractDartTaskTest {
2985 void test_getDeclaration_staticField() { 2988 void test_getDeclaration_staticField() {
2986 AnalysisTarget source = newSource( 2989 AnalysisTarget source = newSource(
2987 '/test.dart', 2990 '/test.dart',
2988 ''' 2991 '''
2989 class C { 2992 class C {
2990 var field = ''; 2993 var field = '';
2991 } 2994 }
2992 '''); 2995 ''');
2993 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2996 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
2994 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2997 CompilationUnit unit = outputs[RESOLVED_UNIT6];
2995 VariableDeclaration declaration = 2998 VariableDeclaration declaration =
2996 AstFinder.getFieldInClass(unit, 'C', 'field'); 2999 AstFinder.getFieldInClass(unit, 'C', 'field');
2997 VariableElement variable = declaration.name.staticElement; 3000 VariableElement variable = declaration.name.staticElement;
2998 InferStaticVariableTypeTask inferTask = 3001 InferStaticVariableTypeTask inferTask =
2999 new InferStaticVariableTypeTask(task.context, variable); 3002 new InferStaticVariableTypeTask(task.context, variable);
3000 expect(inferTask.getDeclaration(unit), declaration); 3003 expect(inferTask.getDeclaration(unit), declaration);
3001 } 3004 }
3002 3005
3003 void test_getDeclaration_topLevel() { 3006 void test_getDeclaration_topLevel() {
3004 AnalysisTarget source = newSource( 3007 AnalysisTarget source = newSource(
3005 '/test.dart', 3008 '/test.dart',
3006 ''' 3009 '''
3007 var topLevel = ''; 3010 var topLevel = '';
3008 '''); 3011 ''');
3009 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3012 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3010 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3013 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3011 VariableDeclaration declaration = 3014 VariableDeclaration declaration =
3012 AstFinder.getTopLevelVariable(unit, 'topLevel'); 3015 AstFinder.getTopLevelVariable(unit, 'topLevel');
3013 VariableElement variable = declaration.name.staticElement; 3016 VariableElement variable = declaration.name.staticElement;
3014 InferStaticVariableTypeTask inferTask = 3017 InferStaticVariableTypeTask inferTask =
3015 new InferStaticVariableTypeTask(task.context, variable); 3018 new InferStaticVariableTypeTask(task.context, variable);
3016 expect(inferTask.getDeclaration(unit), declaration); 3019 expect(inferTask.getDeclaration(unit), declaration);
3017 } 3020 }
3018 3021
3019 void test_perform() { 3022 void test_perform() {
3020 enableStrongMode(); 3023 enableStrongMode();
3021 AnalysisTarget source = newSource( 3024 AnalysisTarget source = newSource(
3022 '/test3.dart', 3025 '/test3.dart',
3023 ''' 3026 '''
3024 var topLevel3 = ''; 3027 var topLevel3 = '';
3025 class C { 3028 class C {
3026 var field3 = topLevel3; 3029 var field3 = topLevel3;
3027 } 3030 }
3028 '''); 3031 ''');
3029 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3032 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3030 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3033 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3031 VariableDeclaration topLevelDecl = 3034 VariableDeclaration topLevelDecl =
3032 AstFinder.getTopLevelVariable(unit, 'topLevel3'); 3035 AstFinder.getTopLevelVariable(unit, 'topLevel3');
3033 VariableDeclaration fieldDecl = 3036 VariableDeclaration fieldDecl =
3034 AstFinder.getFieldInClass(unit, 'C', 'field3'); 3037 AstFinder.getFieldInClass(unit, 'C', 'field3');
3035 VariableElement topLevel = topLevelDecl.name.staticElement; 3038 VariableElement topLevel = topLevelDecl.name.staticElement;
3036 VariableElement field = fieldDecl.name.staticElement; 3039 VariableElement field = fieldDecl.name.staticElement;
3037 3040
3038 computeResult(field, INFERRED_STATIC_VARIABLE, 3041 computeResult(field, INFERRED_STATIC_VARIABLE,
3039 matcher: isInferStaticVariableTypeTask); 3042 matcher: isInferStaticVariableTypeTask);
3040 InterfaceType stringType = context.typeProvider.stringType; 3043 InterfaceType stringType = context.typeProvider.stringType;
3041 expect(topLevel.type, stringType); 3044 expect(topLevel.type, stringType);
3042 expect(field.type, stringType); 3045 expect(field.type, stringType);
3043 expect(fieldDecl.initializer.staticType, stringType); 3046 expect(fieldDecl.initializer.staticType, stringType);
3044 } 3047 }
3045 3048
3046 void test_perform_const() { 3049 void test_perform_const() {
3047 enableStrongMode(); 3050 enableStrongMode();
3048 AnalysisTarget source = newSource( 3051 AnalysisTarget source = newSource(
3049 '/test.dart', 3052 '/test.dart',
3050 ''' 3053 '''
3051 const topLevel = "hello"; 3054 const topLevel = "hello";
3052 class C { 3055 class C {
3053 var field = topLevel; 3056 var field = topLevel;
3054 } 3057 }
3055 '''); 3058 ''');
3056 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3059 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3057 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3060 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3058 VariableElement topLevel = 3061 VariableElement topLevel =
3059 AstFinder.getTopLevelVariable(unit, 'topLevel').name.staticElement; 3062 AstFinder.getTopLevelVariable(unit, 'topLevel').name.staticElement;
3060 VariableElement field = 3063 VariableElement field =
3061 AstFinder.getFieldInClass(unit, 'C', 'field').name.staticElement; 3064 AstFinder.getFieldInClass(unit, 'C', 'field').name.staticElement;
3062 3065
3063 computeResult(field, INFERRED_STATIC_VARIABLE, 3066 computeResult(field, INFERRED_STATIC_VARIABLE,
3064 matcher: isInferStaticVariableTypeTask); 3067 matcher: isInferStaticVariableTypeTask);
3065 InterfaceType stringType = context.typeProvider.stringType; 3068 InterfaceType stringType = context.typeProvider.stringType;
3066 expect(topLevel.type, stringType); 3069 expect(topLevel.type, stringType);
3067 expect(field.type, stringType); 3070 expect(field.type, stringType);
3068 } 3071 }
3069 3072
3070 void test_perform_cycle() { 3073 void test_perform_cycle() {
3071 enableStrongMode(); 3074 enableStrongMode();
3072 AnalysisTarget source = newSource( 3075 AnalysisTarget source = newSource(
3073 '/test.dart', 3076 '/test.dart',
3074 ''' 3077 '''
3075 var piFirst = true; 3078 var piFirst = true;
3076 var pi = piFirst ? 3.14 : tau / 2; 3079 var pi = piFirst ? 3.14 : tau / 2;
3077 var tau = piFirst ? pi * 2 : 6.28; 3080 var tau = piFirst ? pi * 2 : 6.28;
3078 '''); 3081 ''');
3079 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3082 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3080 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3083 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3081 VariableElement piFirst = 3084 VariableElement piFirst =
3082 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; 3085 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement;
3083 VariableElement pi = 3086 VariableElement pi =
3084 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; 3087 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement;
3085 VariableElement tau = 3088 VariableElement tau =
3086 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; 3089 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement;
3087 3090
3088 computeResult(piFirst, INFERRED_STATIC_VARIABLE, 3091 computeResult(piFirst, INFERRED_STATIC_VARIABLE,
3089 matcher: isInferStaticVariableTypeTask); 3092 matcher: isInferStaticVariableTypeTask);
3090 expect(piFirst.type, context.typeProvider.boolType); 3093 expect(piFirst.type, context.typeProvider.boolType);
3091 expect(pi.type.isDynamic, isTrue); 3094 expect(pi.type.isDynamic, isTrue);
3092 expect(tau.type.isDynamic, isTrue); 3095 expect(tau.type.isDynamic, isTrue);
3093 } 3096 }
3094 3097
3095 void test_perform_error() { 3098 void test_perform_error() {
3096 enableStrongMode(); 3099 enableStrongMode();
3097 AnalysisTarget source = newSource( 3100 AnalysisTarget source = newSource(
3098 '/test.dart', 3101 '/test.dart',
3099 ''' 3102 '''
3100 var a = '' / null; 3103 var a = '' / null;
3101 '''); 3104 ''');
3102 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3105 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3103 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3106 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3104 VariableElement a = 3107 VariableElement a =
3105 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; 3108 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement;
3106 3109
3107 computeResult(a, INFERRED_STATIC_VARIABLE, 3110 computeResult(a, INFERRED_STATIC_VARIABLE,
3108 matcher: isInferStaticVariableTypeTask); 3111 matcher: isInferStaticVariableTypeTask);
3109 expect(a.type.isDynamic, isTrue); 3112 expect(a.type.isDynamic, isTrue);
3110 } 3113 }
3111 3114
3112 void test_perform_null() { 3115 void test_perform_null() {
3113 enableStrongMode(); 3116 enableStrongMode();
3114 AnalysisTarget source = newSource( 3117 AnalysisTarget source = newSource(
3115 '/test.dart', 3118 '/test.dart',
3116 ''' 3119 '''
3117 var a = null; 3120 var a = null;
3118 '''); 3121 ''');
3119 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3122 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3120 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3123 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3121 VariableElement a = 3124 VariableElement a =
3122 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; 3125 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement;
3123 3126
3124 computeResult(a, INFERRED_STATIC_VARIABLE, 3127 computeResult(a, INFERRED_STATIC_VARIABLE,
3125 matcher: isInferStaticVariableTypeTask); 3128 matcher: isInferStaticVariableTypeTask);
3126 expect(a.type.isDynamic, isTrue); 3129 expect(a.type.isDynamic, isTrue);
3127 } 3130 }
3128 } 3131 }
3129 3132
3130 @reflectiveTest 3133 @reflectiveTest
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
3417 '''); 3420 ''');
3418 Source sourceC = newSource( 3421 Source sourceC = newSource(
3419 '/c.dart', 3422 '/c.dart',
3420 ''' 3423 '''
3421 library c; 3424 library c;
3422 import 'b.dart'; 3425 import 'b.dart';
3423 main() { 3426 main() {
3424 new A<int>().m(); 3427 new A<int>().m();
3425 } 3428 }
3426 '''); 3429 ''');
3427 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT5, 3430 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT6,
3428 matcher: isPartiallyResolveUnitReferencesTask); 3431 matcher: isPartiallyResolveUnitReferencesTask);
3429 // validate 3432 // validate
3430 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); 3433 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0));
3431 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3434 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3432 expect(unit, isNotNull); 3435 expect(unit, isNotNull);
3433 3436
3434 FunctionDeclaration mainFunction = unit.declarations[0]; 3437 FunctionDeclaration mainFunction = unit.declarations[0];
3435 expect(mainFunction.element, isNotNull); 3438 expect(mainFunction.element, isNotNull);
3436 BlockFunctionBody body = mainFunction.functionExpression.body; 3439 BlockFunctionBody body = mainFunction.functionExpression.body;
3437 List<Statement> statements = body.block.statements; 3440 List<Statement> statements = body.block.statements;
3438 ExpressionStatement statement = statements[0]; 3441 ExpressionStatement statement = statements[0];
3439 MethodInvocation invocation = statement.expression; 3442 MethodInvocation invocation = statement.expression;
3440 MethodElement methodElement = invocation.methodName.staticElement; 3443 MethodElement methodElement = invocation.methodName.staticElement;
3441 expect(methodElement, isNull); 3444 expect(methodElement, isNull);
3442 } 3445 }
3443 3446
3444 test_perform_strong_inferable() { 3447 test_perform_strong_inferable() {
3445 enableStrongMode(); 3448 enableStrongMode();
3446 Source source = newSource( 3449 Source source = newSource(
3447 '/test.dart', 3450 '/test.dart',
3448 ''' 3451 '''
3449 int a = b; 3452 int a = b;
3450 int b = c; 3453 int b = c;
3451 var d = 0; 3454 var d = 0;
3452 class A {} 3455 class A {}
3453 class C { 3456 class C {
3454 static final f = ''; 3457 static final f = '';
3455 var g = 0; 3458 var g = 0;
3456 } 3459 }
3457 '''); 3460 ''');
3458 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 3461 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
3459 computeResult(target, RESOLVED_UNIT5, 3462 computeResult(target, RESOLVED_UNIT6,
3460 matcher: isPartiallyResolveUnitReferencesTask); 3463 matcher: isPartiallyResolveUnitReferencesTask);
3461 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3464 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3462 // INFERABLE_STATIC_VARIABLES_IN_UNIT 3465 // INFERABLE_STATIC_VARIABLES_IN_UNIT
3463 { 3466 {
3464 List<VariableElement> variables = 3467 List<VariableElement> variables =
3465 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] as List<VariableElement>; 3468 outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT] as List<VariableElement>;
3466 expect(variables, hasLength(4)); 3469 expect(variables, hasLength(4));
3467 expect(variables.map((v) => v.displayName), 3470 expect(variables.map((v) => v.displayName),
3468 unorderedEquals(['a', 'b', 'd', 'f'])); 3471 unorderedEquals(['a', 'b', 'd', 'f']));
3469 } 3472 }
3470 // Test the state of the AST 3473 // Test the state of the AST
3471 TopLevelVariableDeclaration a = unit.declarations[0]; 3474 TopLevelVariableDeclaration a = unit.declarations[0];
(...skipping 20 matching lines...) Expand all
3492 class C { 3495 class C {
3493 C() { 3496 C() {
3494 A; 3497 A;
3495 } 3498 }
3496 m() { 3499 m() {
3497 A; 3500 A;
3498 } 3501 }
3499 } 3502 }
3500 '''); 3503 ''');
3501 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 3504 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
3502 computeResult(target, RESOLVED_UNIT5, 3505 computeResult(target, RESOLVED_UNIT6,
3503 matcher: isPartiallyResolveUnitReferencesTask); 3506 matcher: isPartiallyResolveUnitReferencesTask);
3504 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3507 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3505 NodeList<CompilationUnitMember> declarations = unit.declarations; 3508 NodeList<CompilationUnitMember> declarations = unit.declarations;
3506 3509
3507 void expectReference(BlockFunctionBody body, bool isResolved) { 3510 void expectReference(BlockFunctionBody body, bool isResolved) {
3508 ExpressionStatement statement = body.block.statements[0]; 3511 ExpressionStatement statement = body.block.statements[0];
3509 SimpleIdentifier reference = statement.expression; 3512 SimpleIdentifier reference = statement.expression;
3510 expect(reference.staticElement, isResolved ? isNotNull : isNull); 3513 expect(reference.staticElement, isResolved ? isNotNull : isNull);
3511 } 3514 }
3512 // 3515 //
3513 // The reference to 'A' in 'f1' should not be resolved. 3516 // The reference to 'A' in 'f1' should not be resolved.
3514 // 3517 //
(...skipping 28 matching lines...) Expand all
3543 @reflectiveTest 3546 @reflectiveTest
3544 class PropagateVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { 3547 class PropagateVariableTypesInUnitTaskTest extends _AbstractDartTaskTest {
3545 test_created_resolved_unit() { 3548 test_created_resolved_unit() {
3546 Source source = newSource( 3549 Source source = newSource(
3547 '/test.dart', 3550 '/test.dart',
3548 r''' 3551 r'''
3549 library lib; 3552 library lib;
3550 class A {} 3553 class A {}
3551 '''); 3554 ''');
3552 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 3555 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
3553 computeResult(target, RESOLVED_UNIT6); 3556 computeResult(target, RESOLVED_UNIT7);
3554 expect(outputs[RESOLVED_UNIT6], isNotNull); 3557 expect(outputs[RESOLVED_UNIT7], isNotNull);
3555 expect(outputs[CREATED_RESOLVED_UNIT6], isTrue); 3558 expect(outputs[CREATED_RESOLVED_UNIT7], isTrue);
3556 } 3559 }
3557 3560
3558 void test_perform_cycle() { 3561 void test_perform_cycle() {
3559 AnalysisTarget source = newSource( 3562 AnalysisTarget source = newSource(
3560 '/test.dart', 3563 '/test.dart',
3561 ''' 3564 '''
3562 final piFirst = true; 3565 final piFirst = true;
3563 final pi = piFirst ? 3.14 : tau / 2; 3566 final pi = piFirst ? 3.14 : tau / 2;
3564 final tau = piFirst ? pi * 2 : 6.28; 3567 final tau = piFirst ? pi * 2 : 6.28;
3565 '''); 3568 ''');
3566 // compute 3569 // compute
3567 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, 3570 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7,
3568 matcher: isPropagateVariableTypesInUnitTask); 3571 matcher: isPropagateVariableTypesInUnitTask);
3569 CompilationUnit unit = outputs[RESOLVED_UNIT6]; 3572 CompilationUnit unit = outputs[RESOLVED_UNIT7];
3570 // verify 3573 // verify
3571 TopLevelVariableElement piFirst = 3574 TopLevelVariableElement piFirst =
3572 AstFinder.getTopLevelVariableElement(unit, 'piFirst'); 3575 AstFinder.getTopLevelVariableElement(unit, 'piFirst');
3573 TopLevelVariableElement pi = 3576 TopLevelVariableElement pi =
3574 AstFinder.getTopLevelVariableElement(unit, 'pi'); 3577 AstFinder.getTopLevelVariableElement(unit, 'pi');
3575 TopLevelVariableElement tau = 3578 TopLevelVariableElement tau =
3576 AstFinder.getTopLevelVariableElement(unit, 'tau'); 3579 AstFinder.getTopLevelVariableElement(unit, 'tau');
3577 expect(piFirst.propagatedType, context.typeProvider.boolType); 3580 expect(piFirst.propagatedType, context.typeProvider.boolType);
3578 expect(pi.propagatedType, isNull); 3581 expect(pi.propagatedType, isNull);
3579 expect(tau.propagatedType, isNull); 3582 expect(tau.propagatedType, isNull);
3580 } 3583 }
3581 3584
3582 void test_perform_topLevel() { 3585 void test_perform_topLevel() {
3583 AnalysisTarget source = newSource( 3586 AnalysisTarget source = newSource(
3584 '/test.dart', 3587 '/test.dart',
3585 ''' 3588 '''
3586 //final a = b + c.length; 3589 //final a = b + c.length;
3587 final a = b; 3590 final a = b;
3588 final b = 1; 3591 final b = 1;
3589 final c = '2'; 3592 final c = '2';
3590 '''); 3593 ''');
3591 // compute 3594 // compute
3592 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6, 3595 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7,
3593 matcher: isPropagateVariableTypesInUnitTask); 3596 matcher: isPropagateVariableTypesInUnitTask);
3594 CompilationUnit unit = outputs[RESOLVED_UNIT6]; 3597 CompilationUnit unit = outputs[RESOLVED_UNIT7];
3595 // verify 3598 // verify
3596 InterfaceType intType = context.typeProvider.intType; 3599 InterfaceType intType = context.typeProvider.intType;
3597 InterfaceType stringType = context.typeProvider.stringType; 3600 InterfaceType stringType = context.typeProvider.stringType;
3598 expect(AstFinder.getTopLevelVariableElement(unit, 'a').propagatedType, 3601 expect(AstFinder.getTopLevelVariableElement(unit, 'a').propagatedType,
3599 intType); 3602 intType);
3600 expect(AstFinder.getTopLevelVariableElement(unit, 'b').propagatedType, 3603 expect(AstFinder.getTopLevelVariableElement(unit, 'b').propagatedType,
3601 intType); 3604 intType);
3602 expect(AstFinder.getTopLevelVariableElement(unit, 'c').propagatedType, 3605 expect(AstFinder.getTopLevelVariableElement(unit, 'c').propagatedType,
3603 stringType); 3606 stringType);
3604 } 3607 }
3605 } 3608 }
3606 3609
3607 @reflectiveTest 3610 @reflectiveTest
3608 class PropagateVariableTypeTaskTest extends _AbstractDartTaskTest { 3611 class PropagateVariableTypeTaskTest extends _AbstractDartTaskTest {
3609 void test_perform_cycle() { 3612 void test_perform_cycle() {
3610 AnalysisTarget source = newSource( 3613 AnalysisTarget source = newSource(
3611 '/test.dart', 3614 '/test.dart',
3612 ''' 3615 '''
3613 final piFirst = true; 3616 final piFirst = true;
3614 final pi = piFirst ? 3.14 : tau / 2; 3617 final pi = piFirst ? 3.14 : tau / 2;
3615 final tau = piFirst ? pi * 2 : 6.28; 3618 final tau = piFirst ? pi * 2 : 6.28;
3616 '''); 3619 ''');
3617 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3620 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3618 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3621 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3619 TopLevelVariableElement piFirst = 3622 TopLevelVariableElement piFirst =
3620 AstFinder.getTopLevelVariableElement(unit, 'piFirst'); 3623 AstFinder.getTopLevelVariableElement(unit, 'piFirst');
3621 TopLevelVariableElement pi = 3624 TopLevelVariableElement pi =
3622 AstFinder.getTopLevelVariableElement(unit, 'pi'); 3625 AstFinder.getTopLevelVariableElement(unit, 'pi');
3623 TopLevelVariableElement tau = 3626 TopLevelVariableElement tau =
3624 AstFinder.getTopLevelVariableElement(unit, 'tau'); 3627 AstFinder.getTopLevelVariableElement(unit, 'tau');
3625 // compute 3628 // compute
3626 computeResult(piFirst, PROPAGATED_VARIABLE, 3629 computeResult(piFirst, PROPAGATED_VARIABLE,
3627 matcher: isPropagateVariableTypeTask); 3630 matcher: isPropagateVariableTypeTask);
3628 expect(piFirst.propagatedType, context.typeProvider.boolType); 3631 expect(piFirst.propagatedType, context.typeProvider.boolType);
3629 expect(pi.propagatedType, isNull); 3632 expect(pi.propagatedType, isNull);
3630 expect(tau.propagatedType, isNull); 3633 expect(tau.propagatedType, isNull);
3631 } 3634 }
3632 3635
3633 void test_perform_null() { 3636 void test_perform_null() {
3634 enableStrongMode(); 3637 enableStrongMode();
3635 AnalysisTarget source = newSource( 3638 AnalysisTarget source = newSource(
3636 '/test.dart', 3639 '/test.dart',
3637 ''' 3640 '''
3638 var a = null; 3641 var a = null;
3639 '''); 3642 ''');
3640 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3643 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3641 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3644 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3642 TopLevelVariableElement a = AstFinder.getTopLevelVariableElement(unit, 'a'); 3645 TopLevelVariableElement a = AstFinder.getTopLevelVariableElement(unit, 'a');
3643 // compute 3646 // compute
3644 computeResult(a, PROPAGATED_VARIABLE, matcher: isPropagateVariableTypeTask); 3647 computeResult(a, PROPAGATED_VARIABLE, matcher: isPropagateVariableTypeTask);
3645 expect(a.propagatedType, isNull); 3648 expect(a.propagatedType, isNull);
3646 } 3649 }
3647 3650
3648 void test_perform_topLevel() { 3651 void test_perform_topLevel() {
3649 AnalysisTarget source = newSource( 3652 AnalysisTarget source = newSource(
3650 '/test.dart', 3653 '/test.dart',
3651 ''' 3654 '''
3652 final a = b + c.length; 3655 final a = b + c.length;
3653 final b = 1; 3656 final b = 1;
3654 final c = '2'; 3657 final c = '2';
3655 '''); 3658 ''');
3656 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 3659 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT6);
3657 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 3660 CompilationUnit unit = outputs[RESOLVED_UNIT6];
3658 TopLevelVariableElement elementA = 3661 TopLevelVariableElement elementA =
3659 AstFinder.getTopLevelVariableElement(unit, 'a'); 3662 AstFinder.getTopLevelVariableElement(unit, 'a');
3660 TopLevelVariableElement elementB = 3663 TopLevelVariableElement elementB =
3661 AstFinder.getTopLevelVariableElement(unit, 'b'); 3664 AstFinder.getTopLevelVariableElement(unit, 'b');
3662 TopLevelVariableElement elementC = 3665 TopLevelVariableElement elementC =
3663 AstFinder.getTopLevelVariableElement(unit, 'c'); 3666 AstFinder.getTopLevelVariableElement(unit, 'c');
3664 // compute 3667 // compute
3665 computeResult(elementA, PROPAGATED_VARIABLE, 3668 computeResult(elementA, PROPAGATED_VARIABLE,
3666 matcher: isPropagateVariableTypeTask); 3669 matcher: isPropagateVariableTypeTask);
3667 InterfaceType intType = context.typeProvider.intType; 3670 InterfaceType intType = context.typeProvider.intType;
3668 InterfaceType stringType = context.typeProvider.stringType; 3671 InterfaceType stringType = context.typeProvider.stringType;
3669 expect(elementA.propagatedType, intType); 3672 expect(elementA.propagatedType, intType);
3670 expect(elementB.propagatedType, intType); 3673 expect(elementB.propagatedType, intType);
3671 expect(elementC.propagatedType, stringType); 3674 expect(elementC.propagatedType, stringType);
3672 } 3675 }
3673 } 3676 }
3674 3677
3675 @reflectiveTest 3678 @reflectiveTest
3679 class ResolveDirectiveElementsTaskTest extends _AbstractDartTaskTest {
3680 test_perform() {
3681 List<Source> sources = newSources({
3682 '/libA.dart': '''
3683 library libA;
3684 import 'libB.dart';
3685 export 'libC.dart';
3686 ''',
3687 '/libB.dart': '''
3688 library libB;
3689 ''',
3690 '/libC.dart': '''
3691 library libC;
3692 '''
3693 });
3694 Source sourceA = sources[0];
3695 LibrarySpecificUnit targetA = new LibrarySpecificUnit(sourceA, sourceA);
3696 // build directive elements
3697 computeResult(sourceA, LIBRARY_ELEMENT2,
3698 matcher: isBuildDirectiveElementsTask);
3699 // prepare outputs
3700 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2];
3701 LibraryElement libraryElementB = libraryElementA.imports[0].importedLibrary;
3702 LibraryElement libraryElementC = libraryElementA.exports[0].exportedLibrary;
3703 // clear elements in directive ASTs
3704 {
3705 CompilationUnit unitA = context.getResult(targetA, RESOLVED_UNIT1);
3706 unitA.directives[1].element = null;
3707 unitA.directives[2].element = null;
3708 }
3709 // resolve directive ASTs
3710 computeResult(targetA, RESOLVED_UNIT2,
3711 matcher: isResolveDirectiveElementsTask);
3712 // validate that directive ASTs have elements
3713 CompilationUnit unitA = context.getResult(targetA, RESOLVED_UNIT2);
3714 {
3715 ImportDirective importNode = unitA.directives[1];
3716 ImportElement importElement = importNode.element;
3717 expect(importElement, isNotNull);
3718 expect(importElement.importedLibrary, libraryElementB);
3719 }
3720 {
3721 ExportDirective exportNode = unitA.directives[2];
3722 ExportElement exportElement = exportNode.element;
3723 expect(exportElement, isNotNull);
3724 expect(exportElement.exportedLibrary, libraryElementC);
3725 }
3726 }
3727 }
3728
3729 @reflectiveTest
3676 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest { 3730 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest {
3677 @override 3731 @override
3678 void setUp() { 3732 void setUp() {
3679 super.setUp(); 3733 super.setUp();
3680 enableStrongMode(); 3734 enableStrongMode();
3681 } 3735 }
3682 3736
3683 test_created_resolved_unit() { 3737 test_created_resolved_unit() {
3684 Source source = newSource( 3738 Source source = newSource(
3685 '/test.dart', 3739 '/test.dart',
3686 r''' 3740 r'''
3687 library lib; 3741 library lib;
3688 class A {} 3742 class A {}
3689 '''); 3743 ''');
3690 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 3744 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
3691 computeResult(target, RESOLVED_UNIT8); 3745 computeResult(target, RESOLVED_UNIT9);
3692 expect(outputs[RESOLVED_UNIT8], isNotNull); 3746 expect(outputs[RESOLVED_UNIT9], isNotNull);
3693 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); 3747 expect(outputs[CREATED_RESOLVED_UNIT9], isTrue);
3694 } 3748 }
3695 3749
3696 // Test inference of instance fields across units 3750 // Test inference of instance fields across units
3697 void test_perform_inference_cross_unit_instance() { 3751 void test_perform_inference_cross_unit_instance() {
3698 List<Source> sources = newSources({ 3752 List<Source> sources = newSources({
3699 '/a.dart': ''' 3753 '/a.dart': '''
3700 import 'b.dart'; 3754 import 'b.dart';
3701 class A { 3755 class A {
3702 final a2 = new B().b2; 3756 final a2 = new B().b2;
3703 } 3757 }
3704 ''', 3758 ''',
3705 '/b.dart': ''' 3759 '/b.dart': '''
3706 class B { 3760 class B {
3707 final b2 = 1; 3761 final b2 = 1;
3708 } 3762 }
3709 ''', 3763 ''',
3710 '/main.dart': ''' 3764 '/main.dart': '''
3711 import "a.dart"; 3765 import "a.dart";
3712 3766
3713 test1() { 3767 test1() {
3714 int x = 0; 3768 int x = 0;
3715 x = new A().a2; 3769 x = new A().a2;
3716 } 3770 }
3717 ''' 3771 '''
3718 }); 3772 });
3719 InterfaceType intType = context.typeProvider.intType; 3773 InterfaceType intType = context.typeProvider.intType;
3720 DartType dynamicType = context.typeProvider.dynamicType; 3774 DartType dynamicType = context.typeProvider.dynamicType;
3721 3775
3722 computeResult( 3776 computeResult(
3723 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); 3777 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9);
3724 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; 3778 CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
3725 3779
3726 // B.b2 shoud be resolved on the rhs, but not yet inferred. 3780 // B.b2 shoud be resolved on the rhs, but not yet inferred.
3727 assertVariableDeclarationTypes( 3781 assertVariableDeclarationTypes(
3728 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType); 3782 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType);
3729 3783
3730 computeResult( 3784 computeResult(
3731 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); 3785 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9);
3732 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; 3786 CompilationUnit unit0 = outputs[RESOLVED_UNIT9];
3733 3787
3734 // B.b2 should now be fully resolved and inferred. 3788 // B.b2 should now be fully resolved and inferred.
3735 assertVariableDeclarationTypes( 3789 assertVariableDeclarationTypes(
3736 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); 3790 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3737 3791
3738 // A.a2 should now be resolved on the rhs, but not yet inferred. 3792 // A.a2 should now be resolved on the rhs, but not yet inferred.
3739 assertVariableDeclarationTypes( 3793 assertVariableDeclarationTypes(
3740 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); 3794 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType);
3741 3795
3742 computeResult( 3796 computeResult(
3743 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); 3797 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9);
3744 3798
3745 // A.a2 should now be fully resolved and inferred. 3799 // A.a2 should now be fully resolved and inferred.
3746 assertVariableDeclarationTypes( 3800 assertVariableDeclarationTypes(
3747 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); 3801 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
3748 3802
3749 assertVariableDeclarationTypes( 3803 assertVariableDeclarationTypes(
3750 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); 3804 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3751 } 3805 }
3752 3806
3753 // Test inference of instance fields across units 3807 // Test inference of instance fields across units
(...skipping 16 matching lines...) Expand all
3770 3824
3771 test1() { 3825 test1() {
3772 int x = 0; 3826 int x = 0;
3773 x = new A().a2; 3827 x = new A().a2;
3774 } 3828 }
3775 ''' 3829 '''
3776 }); 3830 });
3777 DartType dynamicType = context.typeProvider.dynamicType; 3831 DartType dynamicType = context.typeProvider.dynamicType;
3778 3832
3779 computeResult( 3833 computeResult(
3780 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); 3834 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9);
3781 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; 3835 CompilationUnit unit0 = outputs[RESOLVED_UNIT9];
3782 3836
3783 // A.a2 should now be resolved on the rhs, but not yet inferred. 3837 // A.a2 should now be resolved on the rhs, but not yet inferred.
3784 assertVariableDeclarationTypes( 3838 assertVariableDeclarationTypes(
3785 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); 3839 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
3786 3840
3787 computeResult( 3841 computeResult(
3788 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); 3842 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9);
3789 3843
3790 // A.a2 should now be fully resolved and inferred (but not re-resolved). 3844 // A.a2 should now be fully resolved and inferred (but not re-resolved).
3791 assertVariableDeclarationTypes( 3845 assertVariableDeclarationTypes(
3792 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); 3846 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
3793 } 3847 }
3794 3848
3795 // Test inference of instance fields across units with cycles 3849 // Test inference of instance fields across units with cycles
3796 void test_perform_inference_cross_unit_static_instance() { 3850 void test_perform_inference_cross_unit_static_instance() {
3797 List<Source> sources = newSources({ 3851 List<Source> sources = newSources({
3798 '/a.dart': ''' 3852 '/a.dart': '''
(...skipping 17 matching lines...) Expand all
3816 // inference in A now works. 3870 // inference in A now works.
3817 x = A.a1; 3871 x = A.a1;
3818 x = new A().a2; 3872 x = new A().a2;
3819 } 3873 }
3820 ''' 3874 '''
3821 }); 3875 });
3822 InterfaceType intType = context.typeProvider.intType; 3876 InterfaceType intType = context.typeProvider.intType;
3823 DartType dynamicType = context.typeProvider.dynamicType; 3877 DartType dynamicType = context.typeProvider.dynamicType;
3824 3878
3825 computeResult( 3879 computeResult(
3826 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); 3880 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9);
3827 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; 3881 CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
3828 3882
3829 assertVariableDeclarationTypes( 3883 assertVariableDeclarationTypes(
3830 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); 3884 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
3831 assertVariableDeclarationTypes( 3885 assertVariableDeclarationTypes(
3832 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType); 3886 AstFinder.getFieldInClass(unit1, "B", "b2"), dynamicType, intType);
3833 3887
3834 computeResult( 3888 computeResult(
3835 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); 3889 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9);
3836 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; 3890 CompilationUnit unit0 = outputs[RESOLVED_UNIT9];
3837 3891
3838 assertVariableDeclarationTypes( 3892 assertVariableDeclarationTypes(
3839 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); 3893 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
3840 assertVariableDeclarationTypes( 3894 assertVariableDeclarationTypes(
3841 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType); 3895 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, intType);
3842 3896
3843 assertVariableDeclarationTypes( 3897 assertVariableDeclarationTypes(
3844 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); 3898 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
3845 assertVariableDeclarationTypes( 3899 assertVariableDeclarationTypes(
3846 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); 3900 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
3847 3901
3848 computeResult( 3902 computeResult(
3849 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT8); 3903 new LibrarySpecificUnit(sources[2], sources[2]), RESOLVED_UNIT9);
3850 3904
3851 assertVariableDeclarationTypes( 3905 assertVariableDeclarationTypes(
3852 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); 3906 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
3853 assertVariableDeclarationTypes( 3907 assertVariableDeclarationTypes(
3854 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); 3908 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
3855 3909
3856 assertVariableDeclarationTypes( 3910 assertVariableDeclarationTypes(
3857 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType); 3911 AstFinder.getFieldInClass(unit1, "B", "b1"), intType, intType);
3858 assertVariableDeclarationTypes( 3912 assertVariableDeclarationTypes(
3859 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType); 3913 AstFinder.getFieldInClass(unit1, "B", "b2"), intType, intType);
(...skipping 18 matching lines...) Expand all
3878 test1() { 3932 test1() {
3879 int x = 0; 3933 int x = 0;
3880 x = new A().a2; 3934 x = new A().a2;
3881 } 3935 }
3882 ''' 3936 '''
3883 }); 3937 });
3884 InterfaceType intType = context.typeProvider.intType; 3938 InterfaceType intType = context.typeProvider.intType;
3885 DartType dynamicType = context.typeProvider.dynamicType; 3939 DartType dynamicType = context.typeProvider.dynamicType;
3886 3940
3887 computeResult( 3941 computeResult(
3888 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT8); 3942 new LibrarySpecificUnit(sources[0], sources[0]), RESOLVED_UNIT9);
3889 CompilationUnit unit0 = outputs[RESOLVED_UNIT8]; 3943 CompilationUnit unit0 = outputs[RESOLVED_UNIT9];
3890 3944
3891 // A.a2 should now be resolved on the rhs, but not yet inferred. 3945 // A.a2 should now be resolved on the rhs, but not yet inferred.
3892 assertVariableDeclarationTypes( 3946 assertVariableDeclarationTypes(
3893 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); 3947 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
3894 3948
3895 // B.b2 shoud be resolved on the rhs, but not yet inferred. 3949 // B.b2 shoud be resolved on the rhs, but not yet inferred.
3896 assertVariableDeclarationTypes( 3950 assertVariableDeclarationTypes(
3897 AstFinder.getFieldInClass(unit0, "B", "b2"), dynamicType, intType); 3951 AstFinder.getFieldInClass(unit0, "B", "b2"), dynamicType, intType);
3898 3952
3899 computeResult( 3953 computeResult(
3900 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT8); 3954 new LibrarySpecificUnit(sources[1], sources[1]), RESOLVED_UNIT9);
3901 3955
3902 // A.a2 should now be fully resolved and inferred (but not re-resolved). 3956 // A.a2 should now be fully resolved and inferred (but not re-resolved).
3903 assertVariableDeclarationTypes( 3957 assertVariableDeclarationTypes(
3904 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType); 3958 AstFinder.getFieldInClass(unit0, "A", "a2"), dynamicType, dynamicType);
3905 3959
3906 // B.b2 should now be fully resolved and inferred. 3960 // B.b2 should now be fully resolved and inferred.
3907 assertVariableDeclarationTypes( 3961 assertVariableDeclarationTypes(
3908 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); 3962 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType);
3909 } 3963 }
3910 } 3964 }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3999 @reflectiveTest 4053 @reflectiveTest
4000 class ResolveUnitTaskTest extends _AbstractDartTaskTest { 4054 class ResolveUnitTaskTest extends _AbstractDartTaskTest {
4001 test_created_resolved_unit() { 4055 test_created_resolved_unit() {
4002 Source source = newSource( 4056 Source source = newSource(
4003 '/test.dart', 4057 '/test.dart',
4004 r''' 4058 r'''
4005 library lib; 4059 library lib;
4006 class A {} 4060 class A {}
4007 '''); 4061 ''');
4008 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4062 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4009 computeResult(target, RESOLVED_UNIT10); 4063 computeResult(target, RESOLVED_UNIT11);
4010 expect(outputs[RESOLVED_UNIT10], isNotNull); 4064 expect(outputs[RESOLVED_UNIT11], isNotNull);
4011 expect(outputs[CREATED_RESOLVED_UNIT10], isTrue); 4065 expect(outputs[CREATED_RESOLVED_UNIT11], isTrue);
4012 } 4066 }
4013 4067
4014 void test_perform() { 4068 void test_perform() {
4015 AnalysisTarget source = newSource( 4069 AnalysisTarget source = newSource(
4016 '/test.dart', 4070 '/test.dart',
4017 ''' 4071 '''
4018 void f() { 4072 void f() {
4019 var c = new C(); 4073 var c = new C();
4020 c.m(); 4074 c.m();
4021 } 4075 }
4022 class C { 4076 class C {
4023 void m() { 4077 void m() {
4024 f(); 4078 f();
4025 } 4079 }
4026 } 4080 }
4027 '''); 4081 ''');
4028 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10, 4082 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11,
4029 matcher: isResolveUnitTask); 4083 matcher: isResolveUnitTask);
4030 CompilationUnit unit = outputs[RESOLVED_UNIT10]; 4084 CompilationUnit unit = outputs[RESOLVED_UNIT11];
4031 4085
4032 FunctionDeclaration f = unit.declarations[0]; 4086 FunctionDeclaration f = unit.declarations[0];
4033 _assertResolved(f.functionExpression.body); 4087 _assertResolved(f.functionExpression.body);
4034 4088
4035 MethodDeclaration m = (unit.declarations[1] as ClassDeclaration).members[0]; 4089 MethodDeclaration m = (unit.declarations[1] as ClassDeclaration).members[0];
4036 _assertResolved(m.body); 4090 _assertResolved(m.body);
4037 4091
4038 expect(outputs[RESOLVE_UNIT_ERRORS], hasLength(0)); 4092 expect(outputs[RESOLVE_UNIT_ERRORS], hasLength(0));
4039 } 4093 }
4040 4094
4041 void test_perform_ensurePropagatedVariableTypes() { 4095 void test_perform_ensurePropagatedVariableTypes() {
4042 newSource( 4096 newSource(
4043 '/lib.dart', 4097 '/lib.dart',
4044 ''' 4098 '''
4045 class A { 4099 class A {
4046 final v = 1; 4100 final v = 1;
4047 } 4101 }
4048 '''); 4102 ''');
4049 AnalysisTarget source = newSource( 4103 AnalysisTarget source = newSource(
4050 '/test.dart', 4104 '/test.dart',
4051 ''' 4105 '''
4052 import 'lib.dart'; 4106 import 'lib.dart';
4053 main(A a) { 4107 main(A a) {
4054 a.v.isEven; 4108 a.v.isEven;
4055 } 4109 }
4056 '''); 4110 ''');
4057 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10, 4111 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11,
4058 matcher: isResolveUnitTask); 4112 matcher: isResolveUnitTask);
4059 expect(outputs[RESOLVE_UNIT_ERRORS], hasLength(0)); 4113 expect(outputs[RESOLVE_UNIT_ERRORS], hasLength(0));
4060 CompilationUnit unit = outputs[RESOLVED_UNIT10]; 4114 CompilationUnit unit = outputs[RESOLVED_UNIT11];
4061 FunctionDeclaration main = unit.declarations[0]; 4115 FunctionDeclaration main = unit.declarations[0];
4062 BlockFunctionBody body = main.functionExpression.body; 4116 BlockFunctionBody body = main.functionExpression.body;
4063 ExpressionStatement statement = body.block.statements.single; 4117 ExpressionStatement statement = body.block.statements.single;
4064 Expression expression = statement.expression; 4118 Expression expression = statement.expression;
4065 expect(expression.bestType, context.typeProvider.boolType); 4119 expect(expression.bestType, context.typeProvider.boolType);
4066 } 4120 }
4067 4121
4068 void _assertResolved(FunctionBody body) { 4122 void _assertResolved(FunctionBody body) {
4069 ResolutionVerifier verifier = new ResolutionVerifier(); 4123 ResolutionVerifier verifier = new ResolutionVerifier();
4070 body.accept(verifier); 4124 body.accept(verifier);
4071 verifier.assertResolved(); 4125 verifier.assertResolved();
4072 } 4126 }
4073 } 4127 }
4074 4128
4075 @reflectiveTest 4129 @reflectiveTest
4076 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { 4130 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest {
4077 test_created_resolved_unit() { 4131 test_created_resolved_unit() {
4078 Source source = newSource( 4132 Source source = newSource(
4079 '/test.dart', 4133 '/test.dart',
4080 r''' 4134 r'''
4081 library lib; 4135 library lib;
4082 class A {} 4136 class A {}
4083 '''); 4137 ''');
4084 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4138 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4085 computeResult(target, RESOLVED_UNIT3); 4139 computeResult(target, RESOLVED_UNIT4);
4086 expect(outputs[RESOLVED_UNIT3], isNotNull); 4140 expect(outputs[RESOLVED_UNIT4], isNotNull);
4087 expect(outputs[CREATED_RESOLVED_UNIT3], isTrue); 4141 expect(outputs[CREATED_RESOLVED_UNIT4], isTrue);
4088 } 4142 }
4089 4143
4090 test_perform() { 4144 test_perform() {
4091 Source source = newSource( 4145 Source source = newSource(
4092 '/test.dart', 4146 '/test.dart',
4093 ''' 4147 '''
4094 class A {} 4148 class A {}
4095 class B extends A {} 4149 class B extends A {}
4096 int f(String p) => p.length; 4150 int f(String p) => p.length;
4097 '''); 4151 ''');
4098 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4152 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4099 computeResult(target, RESOLVED_UNIT3, matcher: isResolveUnitTypeNamesTask); 4153 computeResult(target, RESOLVED_UNIT4, matcher: isResolveUnitTypeNamesTask);
4100 // validate 4154 // validate
4101 CompilationUnit unit = outputs[RESOLVED_UNIT3]; 4155 CompilationUnit unit = outputs[RESOLVED_UNIT4];
4102 { 4156 {
4103 ClassDeclaration nodeA = unit.declarations[0]; 4157 ClassDeclaration nodeA = unit.declarations[0];
4104 ClassDeclaration nodeB = unit.declarations[1]; 4158 ClassDeclaration nodeB = unit.declarations[1];
4105 DartType extendsType = nodeB.extendsClause.superclass.type; 4159 DartType extendsType = nodeB.extendsClause.superclass.type;
4106 expect(extendsType, nodeA.element.type); 4160 expect(extendsType, nodeA.element.type);
4107 } 4161 }
4108 { 4162 {
4109 FunctionDeclaration functionNode = unit.declarations[2]; 4163 FunctionDeclaration functionNode = unit.declarations[2];
4110 DartType returnType = functionNode.returnType.type; 4164 DartType returnType = functionNode.returnType.type;
4111 List<FormalParameter> parameters = 4165 List<FormalParameter> parameters =
(...skipping 19 matching lines...) Expand all
4131 } 4185 }
4132 4186
4133 test_perform_typedef() { 4187 test_perform_typedef() {
4134 Source source = newSource( 4188 Source source = newSource(
4135 '/test.dart', 4189 '/test.dart',
4136 ''' 4190 '''
4137 typedef int F(G g); 4191 typedef int F(G g);
4138 typedef String G(int p); 4192 typedef String G(int p);
4139 '''); 4193 ''');
4140 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4194 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4141 computeResult(target, RESOLVED_UNIT3, matcher: isResolveUnitTypeNamesTask); 4195 computeResult(target, RESOLVED_UNIT4, matcher: isResolveUnitTypeNamesTask);
4142 // validate 4196 // validate
4143 CompilationUnit unit = outputs[RESOLVED_UNIT3]; 4197 CompilationUnit unit = outputs[RESOLVED_UNIT4];
4144 FunctionTypeAlias nodeF = unit.declarations[0]; 4198 FunctionTypeAlias nodeF = unit.declarations[0];
4145 FunctionTypeAlias nodeG = unit.declarations[1]; 4199 FunctionTypeAlias nodeG = unit.declarations[1];
4146 { 4200 {
4147 FormalParameter parameter = nodeF.parameters.parameters[0]; 4201 FormalParameter parameter = nodeF.parameters.parameters[0];
4148 DartType parameterType = parameter.element.type; 4202 DartType parameterType = parameter.element.type;
4149 Element returnTypeElement = nodeF.returnType.type.element; 4203 Element returnTypeElement = nodeF.returnType.type.element;
4150 expect(returnTypeElement.displayName, 'int'); 4204 expect(returnTypeElement.displayName, 'int');
4151 expect(parameterType.element, nodeG.element); 4205 expect(parameterType.element, nodeG.element);
4152 } 4206 }
4153 { 4207 {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
4187 } 4241 }
4188 4242
4189 test_created_resolved_unit() { 4243 test_created_resolved_unit() {
4190 Source source = newSource( 4244 Source source = newSource(
4191 '/test.dart', 4245 '/test.dart',
4192 r''' 4246 r'''
4193 library lib; 4247 library lib;
4194 class A {} 4248 class A {}
4195 '''); 4249 ''');
4196 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4250 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4197 computeResult(target, RESOLVED_UNIT4); 4251 computeResult(target, RESOLVED_UNIT5);
4198 expect(outputs[RESOLVED_UNIT4], isNotNull); 4252 expect(outputs[RESOLVED_UNIT5], isNotNull);
4199 expect(outputs[CREATED_RESOLVED_UNIT4], isTrue); 4253 expect(outputs[CREATED_RESOLVED_UNIT5], isTrue);
4200 } 4254 }
4201 4255
4202 test_perform_buildClosureLibraryElements() { 4256 test_perform_buildClosureLibraryElements() {
4203 Source source = newSource( 4257 Source source = newSource(
4204 '/test.dart', 4258 '/test.dart',
4205 ''' 4259 '''
4206 main() { 4260 main() {
4207 } 4261 }
4208 '''); 4262 ''');
4209 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4263 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4210 computeResult(target, RESOLVED_UNIT4, 4264 computeResult(target, RESOLVED_UNIT5,
4211 matcher: isResolveVariableReferencesTask); 4265 matcher: isResolveVariableReferencesTask);
4212 } 4266 }
4213 4267
4214 test_perform_local() { 4268 test_perform_local() {
4215 Source source = newSource( 4269 Source source = newSource(
4216 '/test.dart', 4270 '/test.dart',
4217 ''' 4271 '''
4218 main() { 4272 main() {
4219 var v1 = 1; 4273 var v1 = 1;
4220 var v2 = 1; 4274 var v2 = 1;
4221 var v3 = 1; 4275 var v3 = 1;
4222 var v4 = 1; 4276 var v4 = 1;
4223 v2 = 2; 4277 v2 = 2;
4224 v4 = 2; 4278 v4 = 2;
4225 localFunction() { 4279 localFunction() {
4226 v3 = 3; 4280 v3 = 3;
4227 v4 = 3; 4281 v4 = 3;
4228 } 4282 }
4229 } 4283 }
4230 '''); 4284 ''');
4231 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4285 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4232 computeResult(target, RESOLVED_UNIT4, 4286 computeResult(target, RESOLVED_UNIT5,
4233 matcher: isResolveVariableReferencesTask); 4287 matcher: isResolveVariableReferencesTask);
4234 // validate 4288 // validate
4235 CompilationUnit unit = outputs[RESOLVED_UNIT4]; 4289 CompilationUnit unit = outputs[RESOLVED_UNIT5];
4236 FunctionDeclaration mainDeclaration = unit.declarations[0]; 4290 FunctionDeclaration mainDeclaration = unit.declarations[0];
4237 FunctionBody body = mainDeclaration.functionExpression.body; 4291 FunctionBody body = mainDeclaration.functionExpression.body;
4238 FunctionElement main = mainDeclaration.element; 4292 FunctionElement main = mainDeclaration.element;
4239 expectMutated(body, main.localVariables[0], false, false); 4293 expectMutated(body, main.localVariables[0], false, false);
4240 expectMutated(body, main.localVariables[1], false, true); 4294 expectMutated(body, main.localVariables[1], false, true);
4241 expectMutated(body, main.localVariables[2], true, true); 4295 expectMutated(body, main.localVariables[2], true, true);
4242 expectMutated(body, main.localVariables[3], true, true); 4296 expectMutated(body, main.localVariables[3], true, true);
4243 } 4297 }
4244 4298
4245 test_perform_parameter() { 4299 test_perform_parameter() {
4246 Source source = newSource( 4300 Source source = newSource(
4247 '/test.dart', 4301 '/test.dart',
4248 ''' 4302 '''
4249 main(p1, p2, p3, p4) { 4303 main(p1, p2, p3, p4) {
4250 p2 = 2; 4304 p2 = 2;
4251 p4 = 2; 4305 p4 = 2;
4252 localFunction() { 4306 localFunction() {
4253 p3 = 3; 4307 p3 = 3;
4254 p4 = 3; 4308 p4 = 3;
4255 } 4309 }
4256 } 4310 }
4257 '''); 4311 ''');
4258 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 4312 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
4259 computeResult(target, RESOLVED_UNIT4, 4313 computeResult(target, RESOLVED_UNIT5,
4260 matcher: isResolveVariableReferencesTask); 4314 matcher: isResolveVariableReferencesTask);
4261 // validate 4315 // validate
4262 CompilationUnit unit = outputs[RESOLVED_UNIT4]; 4316 CompilationUnit unit = outputs[RESOLVED_UNIT5];
4263 FunctionDeclaration mainDeclaration = unit.declarations[0]; 4317 FunctionDeclaration mainDeclaration = unit.declarations[0];
4264 FunctionBody body = mainDeclaration.functionExpression.body; 4318 FunctionBody body = mainDeclaration.functionExpression.body;
4265 FunctionElement main = mainDeclaration.element; 4319 FunctionElement main = mainDeclaration.element;
4266 expectMutated(body, main.parameters[0], false, false); 4320 expectMutated(body, main.parameters[0], false, false);
4267 expectMutated(body, main.parameters[1], false, true); 4321 expectMutated(body, main.parameters[1], false, true);
4268 expectMutated(body, main.parameters[2], true, true); 4322 expectMutated(body, main.parameters[2], true, true);
4269 expectMutated(body, main.parameters[3], true, true); 4323 expectMutated(body, main.parameters[3], true, true);
4270 } 4324 }
4271 } 4325 }
4272 4326
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4331 // Check that even within a static variable cycle, inferred 4385 // Check that even within a static variable cycle, inferred
4332 // types get propagated to the members of the cycle. 4386 // types get propagated to the members of the cycle.
4333 void test_perform_cycle() { 4387 void test_perform_cycle() {
4334 AnalysisTarget source = newSource( 4388 AnalysisTarget source = newSource(
4335 '/test.dart', 4389 '/test.dart',
4336 ''' 4390 '''
4337 var piFirst = true; 4391 var piFirst = true;
4338 var pi = piFirst ? 3.14 : tau / 2; 4392 var pi = piFirst ? 3.14 : tau / 2;
4339 var tau = piFirst ? pi * 2 : 6.28; 4393 var tau = piFirst ? pi * 2 : 6.28;
4340 '''); 4394 ''');
4341 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); 4395 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
4342 CompilationUnit unit = outputs[RESOLVED_UNIT10]; 4396 CompilationUnit unit = outputs[RESOLVED_UNIT11];
4343 VariableElement piFirst = 4397 VariableElement piFirst =
4344 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; 4398 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement;
4345 VariableElement pi = 4399 VariableElement pi =
4346 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; 4400 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement;
4347 VariableElement tau = 4401 VariableElement tau =
4348 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; 4402 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement;
4349 Expression piFirstUse = (AstFinder 4403 Expression piFirstUse = (AstFinder
4350 .getTopLevelVariable(unit, 'tau') 4404 .getTopLevelVariable(unit, 'tau')
4351 .initializer as ConditionalExpression) 4405 .initializer as ConditionalExpression)
4352 .condition; 4406 .condition;
(...skipping 21 matching lines...) Expand all
4374 4428
4375 test1() { 4429 test1() {
4376 int t = 3; 4430 int t = 3;
4377 t = x; 4431 t = x;
4378 t = y; 4432 t = y;
4379 t = A.x; 4433 t = A.x;
4380 t = B.y; 4434 t = B.y;
4381 } 4435 }
4382 '''); 4436 ''');
4383 computeResult( 4437 computeResult(
4384 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10); 4438 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT11);
4385 CompilationUnit unit1 = outputs[RESOLVED_UNIT10]; 4439 CompilationUnit unit1 = outputs[RESOLVED_UNIT11];
4386 computeResult( 4440 computeResult(
4387 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10); 4441 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT11);
4388 CompilationUnit unit2 = outputs[RESOLVED_UNIT10]; 4442 CompilationUnit unit2 = outputs[RESOLVED_UNIT11];
4389 4443
4390 InterfaceType intType = context.typeProvider.intType; 4444 InterfaceType intType = context.typeProvider.intType;
4391 4445
4392 assertVariableDeclarationTypes( 4446 assertVariableDeclarationTypes(
4393 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType); 4447 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType);
4394 assertVariableDeclarationTypes( 4448 assertVariableDeclarationTypes(
4395 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType); 4449 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType);
4396 4450
4397 assertVariableDeclarationTypes( 4451 assertVariableDeclarationTypes(
4398 AstFinder.getTopLevelVariable(unit2, "y"), intType, intType); 4452 AstFinder.getTopLevelVariable(unit2, "y"), intType, intType);
(...skipping 26 matching lines...) Expand all
4425 '/main.dart': ''' 4479 '/main.dart': '''
4426 import "a.dart"; 4480 import "a.dart";
4427 4481
4428 test1() { 4482 test1() {
4429 int x = 0; 4483 int x = 0;
4430 x = new A().a2; 4484 x = new A().a2;
4431 } 4485 }
4432 ''' 4486 '''
4433 }); 4487 });
4434 List<dynamic> units = 4488 List<dynamic> units =
4435 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); 4489 computeLibraryResults(sources, RESOLVED_UNIT11).toList();
4436 CompilationUnit unit0 = units[0]; 4490 CompilationUnit unit0 = units[0];
4437 CompilationUnit unit1 = units[1]; 4491 CompilationUnit unit1 = units[1];
4438 CompilationUnit unit2 = units[2]; 4492 CompilationUnit unit2 = units[2];
4439 4493
4440 InterfaceType intType = context.typeProvider.intType; 4494 InterfaceType intType = context.typeProvider.intType;
4441 4495
4442 assertVariableDeclarationTypes( 4496 assertVariableDeclarationTypes(
4443 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); 4497 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
4444 4498
4445 assertVariableDeclarationTypes( 4499 assertVariableDeclarationTypes(
(...skipping 26 matching lines...) Expand all
4472 ''', 4526 ''',
4473 '/c.dart': ''' 4527 '/c.dart': '''
4474 import 'b.dart'; 4528 import 'b.dart';
4475 var bar = new B(); 4529 var bar = new B();
4476 void foo() { 4530 void foo() {
4477 String x = bar.f.z; 4531 String x = bar.f.z;
4478 } 4532 }
4479 ''' 4533 '''
4480 }); 4534 });
4481 List<dynamic> units = 4535 List<dynamic> units =
4482 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); 4536 computeLibraryResults(sources, RESOLVED_UNIT11).toList();
4483 CompilationUnit unit0 = units[0]; 4537 CompilationUnit unit0 = units[0];
4484 CompilationUnit unit2 = units[2]; 4538 CompilationUnit unit2 = units[2];
4485 4539
4486 InterfaceType intType = context.typeProvider.intType; 4540 InterfaceType intType = context.typeProvider.intType;
4487 InterfaceType stringType = context.typeProvider.stringType; 4541 InterfaceType stringType = context.typeProvider.stringType;
4488 4542
4489 assertVariableDeclarationStatementTypes( 4543 assertVariableDeclarationStatementTypes(
4490 AstFinder.getStatementsInTopLevelFunction(unit0, "foo")[0], 4544 AstFinder.getStatementsInTopLevelFunction(unit0, "foo")[0],
4491 stringType, 4545 stringType,
4492 intType); 4546 intType);
(...skipping 20 matching lines...) Expand all
4513 class B { static var y = A.x; } 4567 class B { static var y = A.x; }
4514 4568
4515 test1() { 4569 test1() {
4516 x = /*severe:StaticTypeError*/"hi"; 4570 x = /*severe:StaticTypeError*/"hi";
4517 y = /*severe:StaticTypeError*/"hi"; 4571 y = /*severe:StaticTypeError*/"hi";
4518 A.x = /*severe:StaticTypeError*/"hi"; 4572 A.x = /*severe:StaticTypeError*/"hi";
4519 B.y = /*severe:StaticTypeError*/"hi"; 4573 B.y = /*severe:StaticTypeError*/"hi";
4520 } 4574 }
4521 '''); 4575 ''');
4522 computeResult( 4576 computeResult(
4523 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10); 4577 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT11);
4524 CompilationUnit unit1 = outputs[RESOLVED_UNIT10]; 4578 CompilationUnit unit1 = outputs[RESOLVED_UNIT11];
4525 computeResult( 4579 computeResult(
4526 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT10); 4580 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT11);
4527 CompilationUnit unit2 = outputs[RESOLVED_UNIT10]; 4581 CompilationUnit unit2 = outputs[RESOLVED_UNIT11];
4528 4582
4529 InterfaceType intType = context.typeProvider.intType; 4583 InterfaceType intType = context.typeProvider.intType;
4530 InterfaceType stringType = context.typeProvider.stringType; 4584 InterfaceType stringType = context.typeProvider.stringType;
4531 4585
4532 assertVariableDeclarationTypes( 4586 assertVariableDeclarationTypes(
4533 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType); 4587 AstFinder.getTopLevelVariable(unit1, "x"), intType, intType);
4534 assertVariableDeclarationTypes( 4588 assertVariableDeclarationTypes(
4535 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType); 4589 AstFinder.getFieldInClass(unit1, "A", "x"), intType, intType);
4536 4590
4537 assertVariableDeclarationTypes( 4591 assertVariableDeclarationTypes(
(...skipping 29 matching lines...) Expand all
4567 4621
4568 test1() { 4622 test1() {
4569 int x = 0; 4623 int x = 0;
4570 // inference in A now works. 4624 // inference in A now works.
4571 x = A.a1; 4625 x = A.a1;
4572 x = new A().a2; 4626 x = new A().a2;
4573 } 4627 }
4574 ''' 4628 '''
4575 }); 4629 });
4576 List<dynamic> units = 4630 List<dynamic> units =
4577 computeLibraryResults(sources, RESOLVED_UNIT10).toList(); 4631 computeLibraryResults(sources, RESOLVED_UNIT11).toList();
4578 CompilationUnit unit0 = units[0]; 4632 CompilationUnit unit0 = units[0];
4579 CompilationUnit unit1 = units[1]; 4633 CompilationUnit unit1 = units[1];
4580 CompilationUnit unit2 = units[2]; 4634 CompilationUnit unit2 = units[2];
4581 4635
4582 InterfaceType intType = context.typeProvider.intType; 4636 InterfaceType intType = context.typeProvider.intType;
4583 4637
4584 assertVariableDeclarationTypes( 4638 assertVariableDeclarationTypes(
4585 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType); 4639 AstFinder.getFieldInClass(unit0, "A", "a1"), intType, intType);
4586 assertVariableDeclarationTypes( 4640 assertVariableDeclarationTypes(
4587 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType); 4641 AstFinder.getFieldInClass(unit0, "A", "a2"), intType, intType);
(...skipping 15 matching lines...) Expand all
4603 AnalysisTarget source = newSource( 4657 AnalysisTarget source = newSource(
4604 '/test.dart', 4658 '/test.dart',
4605 ''' 4659 '''
4606 test() { 4660 test() {
4607 int x = 3; 4661 int x = 3;
4608 x = "hi"; 4662 x = "hi";
4609 var y = 3; 4663 var y = 3;
4610 y = "hi"; 4664 y = "hi";
4611 } 4665 }
4612 '''); 4666 ''');
4613 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); 4667 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
4614 CompilationUnit unit = outputs[RESOLVED_UNIT10]; 4668 CompilationUnit unit = outputs[RESOLVED_UNIT11];
4615 4669
4616 InterfaceType intType = context.typeProvider.intType; 4670 InterfaceType intType = context.typeProvider.intType;
4617 InterfaceType stringType = context.typeProvider.stringType; 4671 InterfaceType stringType = context.typeProvider.stringType;
4618 4672
4619 List<Statement> statements = 4673 List<Statement> statements =
4620 AstFinder.getStatementsInTopLevelFunction(unit, "test"); 4674 AstFinder.getStatementsInTopLevelFunction(unit, "test");
4621 4675
4622 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 4676 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
4623 assertAssignmentStatementTypes(statements[1], intType, stringType); 4677 assertAssignmentStatementTypes(statements[1], intType, stringType);
4624 assertVariableDeclarationStatementTypes(statements[2], intType, intType); 4678 assertVariableDeclarationStatementTypes(statements[2], intType, intType);
(...skipping 17 matching lines...) Expand all
4642 b = 4; 4696 b = 4;
4643 var c = z; 4697 var c = z;
4644 c = "hi"; 4698 c = "hi";
4645 c = 4; 4699 c = 4;
4646 } 4700 }
4647 4701
4648 int y; // field def after use 4702 int y; // field def after use
4649 final z = 42; // should infer `int` 4703 final z = 42; // should infer `int`
4650 } 4704 }
4651 '''); 4705 ''');
4652 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); 4706 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
4653 CompilationUnit unit = outputs[RESOLVED_UNIT10]; 4707 CompilationUnit unit = outputs[RESOLVED_UNIT11];
4654 4708
4655 InterfaceType intType = context.typeProvider.intType; 4709 InterfaceType intType = context.typeProvider.intType;
4656 InterfaceType stringType = context.typeProvider.stringType; 4710 InterfaceType stringType = context.typeProvider.stringType;
4657 4711
4658 List<Statement> statements = 4712 List<Statement> statements =
4659 AstFinder.getStatementsInMethod(unit, "A", "test1"); 4713 AstFinder.getStatementsInMethod(unit, "A", "test1");
4660 4714
4661 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 4715 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
4662 assertAssignmentStatementTypes(statements[1], intType, stringType); 4716 assertAssignmentStatementTypes(statements[1], intType, stringType);
4663 assertAssignmentStatementTypes(statements[2], intType, intType); 4717 assertAssignmentStatementTypes(statements[2], intType, intType);
(...skipping 27 matching lines...) Expand all
4691 b = /*severe:StaticTypeError*/"hi"; 4745 b = /*severe:StaticTypeError*/"hi";
4692 b = 4; 4746 b = 4;
4693 var c = z; 4747 var c = z;
4694 c = /*severe:StaticTypeError*/"hi"; 4748 c = /*severe:StaticTypeError*/"hi";
4695 c = 4; 4749 c = 4;
4696 } 4750 }
4697 4751
4698 int y = 0; // field def after use 4752 int y = 0; // field def after use
4699 final z = 42; // should infer `int` 4753 final z = 42; // should infer `int`
4700 '''); 4754 ''');
4701 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); 4755 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
4702 CompilationUnit unit = outputs[RESOLVED_UNIT10]; 4756 CompilationUnit unit = outputs[RESOLVED_UNIT11];
4703 4757
4704 InterfaceType intType = context.typeProvider.intType; 4758 InterfaceType intType = context.typeProvider.intType;
4705 InterfaceType stringType = context.typeProvider.stringType; 4759 InterfaceType stringType = context.typeProvider.stringType;
4706 4760
4707 List<Statement> statements = 4761 List<Statement> statements =
4708 AstFinder.getStatementsInTopLevelFunction(unit, "test1"); 4762 AstFinder.getStatementsInTopLevelFunction(unit, "test1");
4709 4763
4710 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 4764 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
4711 assertAssignmentStatementTypes(statements[1], intType, stringType); 4765 assertAssignmentStatementTypes(statements[1], intType, stringType);
4712 assertAssignmentStatementTypes(statements[2], intType, intType); 4766 assertAssignmentStatementTypes(statements[2], intType, intType);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
4744 4798
4745 test() { 4799 test() {
4746 x = "hi"; 4800 x = "hi";
4747 y = /*severe:StaticTypeError*/"hi"; 4801 y = /*severe:StaticTypeError*/"hi";
4748 A.x = "hi"; 4802 A.x = "hi";
4749 A.y = /*severe:StaticTypeError*/"hi"; 4803 A.y = /*severe:StaticTypeError*/"hi";
4750 new A().x2 = "hi"; 4804 new A().x2 = "hi";
4751 new A().y2 = /*severe:StaticTypeError*/"hi"; 4805 new A().y2 = /*severe:StaticTypeError*/"hi";
4752 } 4806 }
4753 '''); 4807 ''');
4754 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); 4808 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
4755 CompilationUnit unit = outputs[RESOLVED_UNIT10]; 4809 CompilationUnit unit = outputs[RESOLVED_UNIT11];
4756 4810
4757 InterfaceType intType = context.typeProvider.intType; 4811 InterfaceType intType = context.typeProvider.intType;
4758 InterfaceType stringType = context.typeProvider.stringType; 4812 InterfaceType stringType = context.typeProvider.stringType;
4759 DartType bottomType = context.typeProvider.bottomType; 4813 DartType bottomType = context.typeProvider.bottomType;
4760 DartType dynamicType = context.typeProvider.dynamicType; 4814 DartType dynamicType = context.typeProvider.dynamicType;
4761 4815
4762 assertVariableDeclarationTypes( 4816 assertVariableDeclarationTypes(
4763 AstFinder.getTopLevelVariable(unit, "x"), dynamicType, bottomType); 4817 AstFinder.getTopLevelVariable(unit, "x"), dynamicType, bottomType);
4764 assertVariableDeclarationTypes( 4818 assertVariableDeclarationTypes(
4765 AstFinder.getTopLevelVariable(unit, "y"), intType, intType); 4819 AstFinder.getTopLevelVariable(unit, "y"), intType, intType);
(...skipping 20 matching lines...) Expand all
4786 // Test inference between fields and method bodies 4840 // Test inference between fields and method bodies
4787 void test_perform_local_explicit_disabled() { 4841 void test_perform_local_explicit_disabled() {
4788 AnalysisTarget source = newSource( 4842 AnalysisTarget source = newSource(
4789 '/test.dart', 4843 '/test.dart',
4790 ''' 4844 '''
4791 test() { 4845 test() {
4792 int x = 3; 4846 int x = 3;
4793 x = "hi"; 4847 x = "hi";
4794 } 4848 }
4795 '''); 4849 ''');
4796 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); 4850 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11);
4797 CompilationUnit unit = outputs[RESOLVED_UNIT10]; 4851 CompilationUnit unit = outputs[RESOLVED_UNIT11];
4798 4852
4799 InterfaceType intType = context.typeProvider.intType; 4853 InterfaceType intType = context.typeProvider.intType;
4800 InterfaceType stringType = context.typeProvider.stringType; 4854 InterfaceType stringType = context.typeProvider.stringType;
4801 4855
4802 List<Statement> statements = 4856 List<Statement> statements =
4803 AstFinder.getStatementsInTopLevelFunction(unit, "test"); 4857 AstFinder.getStatementsInTopLevelFunction(unit, "test");
4804 VariableDeclaration decl = 4858 VariableDeclaration decl =
4805 (statements[0] as VariableDeclarationStatement).variables.variables[0]; 4859 (statements[0] as VariableDeclarationStatement).variables.variables[0];
4806 expect(decl.element.type, intType); 4860 expect(decl.element.type, intType);
4807 expect(decl.initializer.staticType, intType); 4861 expect(decl.initializer.staticType, intType);
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
5141 /** 5195 /**
5142 * Fill [errorListener] with [result] errors in the current [task]. 5196 * Fill [errorListener] with [result] errors in the current [task].
5143 */ 5197 */
5144 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 5198 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
5145 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; 5199 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>;
5146 expect(errors, isNotNull, reason: result.name); 5200 expect(errors, isNotNull, reason: result.name);
5147 errorListener = new GatheringErrorListener(); 5201 errorListener = new GatheringErrorListener();
5148 errorListener.addAll(errors); 5202 errorListener.addAll(errors);
5149 } 5203 }
5150 } 5204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698