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

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

Issue 1386023002: Resolve ordering issues. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Small fixes Created 5 years, 2 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 test.src.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 runReflectiveTests(GatherUsedImportedElementsTaskTest); 48 runReflectiveTests(GatherUsedImportedElementsTaskTest);
49 runReflectiveTests(GatherUsedLocalElementsTaskTest); 49 runReflectiveTests(GatherUsedLocalElementsTaskTest);
50 runReflectiveTests(GenerateHintsTaskTest); 50 runReflectiveTests(GenerateHintsTaskTest);
51 runReflectiveTests(InferInstanceMembersInUnitTaskTest); 51 runReflectiveTests(InferInstanceMembersInUnitTaskTest);
52 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); 52 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest);
53 runReflectiveTests(InferStaticVariableTypeTaskTest); 53 runReflectiveTests(InferStaticVariableTypeTaskTest);
54 runReflectiveTests(LibraryErrorsReadyTaskTest); 54 runReflectiveTests(LibraryErrorsReadyTaskTest);
55 runReflectiveTests(LibraryUnitErrorsTaskTest); 55 runReflectiveTests(LibraryUnitErrorsTaskTest);
56 runReflectiveTests(ParseDartTaskTest); 56 runReflectiveTests(ParseDartTaskTest);
57 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); 57 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest);
58 runReflectiveTests(ResolveFunctionBodiesInUnitTaskTest);
59 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); 58 runReflectiveTests(ResolveLibraryTypeNamesTaskTest);
59 runReflectiveTests(ResolveLibraryTypeNamesTaskTest);
Brian Wilkerson 2015/10/06 19:04:47 Duplicated line. (Probably copied and pasted in pr
Leaf 2015/10/07 18:53:55 Done.
60 runReflectiveTests(ResolveUnitTaskTest);
60 runReflectiveTests(ResolveUnitTypeNamesTaskTest); 61 runReflectiveTests(ResolveUnitTypeNamesTaskTest);
61 runReflectiveTests(ResolveVariableReferencesTaskTest); 62 runReflectiveTests(ResolveVariableReferencesTaskTest);
62 runReflectiveTests(ScanDartTaskTest); 63 runReflectiveTests(ScanDartTaskTest);
63 runReflectiveTests(StrongModeInferenceTest); 64 runReflectiveTests(StrongModeInferenceTest);
64 runReflectiveTests(VerifyUnitTaskTest); 65 runReflectiveTests(VerifyUnitTaskTest);
Brian Wilkerson 2015/10/06 19:04:47 We appear to be missing tests for ComputeLibraryCy
Leaf 2015/10/07 18:53:55 Done.
65 } 66 }
66 67
67 isInstanceOf isBuildCompilationUnitElementTask = 68 isInstanceOf isBuildCompilationUnitElementTask =
68 new isInstanceOf<BuildCompilationUnitElementTask>(); 69 new isInstanceOf<BuildCompilationUnitElementTask>();
69 isInstanceOf isBuildDirectiveElementsTask = 70 isInstanceOf isBuildDirectiveElementsTask =
70 new isInstanceOf<BuildDirectiveElementsTask>(); 71 new isInstanceOf<BuildDirectiveElementsTask>();
71 isInstanceOf isBuildEnumMemberElementsTask = 72 isInstanceOf isBuildEnumMemberElementsTask =
72 new isInstanceOf<BuildEnumMemberElementsTask>(); 73 new isInstanceOf<BuildEnumMemberElementsTask>();
73 isInstanceOf isBuildExportNamespaceTask = 74 isInstanceOf isBuildExportNamespaceTask =
74 new isInstanceOf<BuildExportNamespaceTask>(); 75 new isInstanceOf<BuildExportNamespaceTask>();
(...skipping 29 matching lines...) Expand all
104 new isInstanceOf<InferStaticVariableTypesInUnitTask>(); 105 new isInstanceOf<InferStaticVariableTypesInUnitTask>();
105 isInstanceOf isInferStaticVariableTypeTask = 106 isInstanceOf isInferStaticVariableTypeTask =
106 new isInstanceOf<InferStaticVariableTypeTask>(); 107 new isInstanceOf<InferStaticVariableTypeTask>();
107 isInstanceOf isLibraryErrorsReadyTask = 108 isInstanceOf isLibraryErrorsReadyTask =
108 new isInstanceOf<LibraryErrorsReadyTask>(); 109 new isInstanceOf<LibraryErrorsReadyTask>();
109 isInstanceOf isLibraryUnitErrorsTask = 110 isInstanceOf isLibraryUnitErrorsTask =
110 new isInstanceOf<LibraryUnitErrorsTask>(); 111 new isInstanceOf<LibraryUnitErrorsTask>();
111 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); 112 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>();
112 isInstanceOf isPartiallyResolveUnitReferencesTask = 113 isInstanceOf isPartiallyResolveUnitReferencesTask =
113 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); 114 new isInstanceOf<PartiallyResolveUnitReferencesTask>();
114 isInstanceOf isResolveFunctionBodiesInUnitTask =
115 new isInstanceOf<ResolveFunctionBodiesInUnitTask>();
116 isInstanceOf isResolveLibraryTypeNamesTask = 115 isInstanceOf isResolveLibraryTypeNamesTask =
117 new isInstanceOf<ResolveLibraryTypeNamesTask>(); 116 new isInstanceOf<ResolveLibraryTypeNamesTask>();
117 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>();
118 isInstanceOf isResolveUnitTypeNamesTask = 118 isInstanceOf isResolveUnitTypeNamesTask =
119 new isInstanceOf<ResolveUnitTypeNamesTask>(); 119 new isInstanceOf<ResolveUnitTypeNamesTask>();
120 isInstanceOf isResolveVariableReferencesTask = 120 isInstanceOf isResolveVariableReferencesTask =
121 new isInstanceOf<ResolveVariableReferencesTask>(); 121 new isInstanceOf<ResolveVariableReferencesTask>();
122 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>(); 122 isInstanceOf isScanDartTask = new isInstanceOf<ScanDartTask>();
123 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); 123 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>();
124 124
125 @reflectiveTest 125 @reflectiveTest
126 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { 126 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest {
127 Source source; 127 Source source;
(...skipping 1759 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 Y m(Z x) {} 1887 Y m(Z x) {}
1888 } 1888 }
1889 class B extends A { 1889 class B extends A {
1890 var f; 1890 var f;
1891 m(x) {} 1891 m(x) {}
1892 } 1892 }
1893 class X {} 1893 class X {}
1894 class Y {} 1894 class Y {}
1895 class Z {} 1895 class Z {}
1896 '''); 1896 ''');
1897 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7, 1897 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8,
1898 matcher: isInferInstanceMembersInUnitTask); 1898 matcher: isInferInstanceMembersInUnitTask);
1899 CompilationUnit unit = outputs[RESOLVED_UNIT7]; 1899 CompilationUnit unit = outputs[RESOLVED_UNIT8];
1900 VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); 1900 VariableDeclaration field = getFieldInClass(unit, 'B', 'f');
1901 MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); 1901 MethodDeclaration method = getMethodInClass(unit, 'B', 'm');
1902 DartType typeX = getClass(unit, 'X').element.type; 1902 DartType typeX = getClass(unit, 'X').element.type;
1903 DartType typeY = getClass(unit, 'Y').element.type; 1903 DartType typeY = getClass(unit, 'Y').element.type;
1904 DartType typeZ = getClass(unit, 'Z').element.type; 1904 DartType typeZ = getClass(unit, 'Z').element.type;
1905 1905
1906 expect(field.element.type, typeX); 1906 expect(field.element.type, typeX);
1907 expect(method.element.returnType, typeY); 1907 expect(method.element.returnType, typeY);
1908 expect(method.element.parameters[0].type, typeZ); 1908 expect(method.element.parameters[0].type, typeZ);
1909 } 1909 }
(...skipping 11 matching lines...) Expand all
1921 '/second.dart', 1921 '/second.dart',
1922 ''' 1922 '''
1923 import 'first.dart'; 1923 import 'first.dart';
1924 1924
1925 const b = a; 1925 const b = a;
1926 class M { 1926 class M {
1927 String c = a; 1927 String c = a;
1928 } 1928 }
1929 '''); 1929 ''');
1930 computeResult( 1930 computeResult(
1931 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT7, 1931 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8,
1932 matcher: isInferInstanceMembersInUnitTask); 1932 matcher: isInferInstanceMembersInUnitTask);
1933 CompilationUnit firstUnit = outputs[RESOLVED_UNIT7]; 1933 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8];
1934 computeResult( 1934 computeResult(
1935 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT7); 1935 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8);
1936 CompilationUnit secondUnit = outputs[RESOLVED_UNIT7]; 1936 CompilationUnit secondUnit = outputs[RESOLVED_UNIT8];
1937 1937
1938 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a'); 1938 VariableDeclaration variableA = getTopLevelVariable(firstUnit, 'a');
1939 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b'); 1939 VariableDeclaration variableB = getTopLevelVariable(secondUnit, 'b');
1940 VariableDeclaration variableC = getFieldInClass(secondUnit, 'M', 'c'); 1940 VariableDeclaration variableC = getFieldInClass(secondUnit, 'M', 'c');
1941 InterfaceType stringType = context.typeProvider.stringType; 1941 InterfaceType stringType = context.typeProvider.stringType;
1942 1942
1943 expect(variableA.element.type, stringType); 1943 expect(variableA.element.type, stringType);
1944 expect(variableB.element.type, stringType); 1944 expect(variableB.element.type, stringType);
1945 expect(variableB.initializer.staticType, stringType); 1945 expect(variableB.initializer.staticType, stringType);
1946 expect(variableC.element.type, stringType); 1946 expect(variableC.element.type, stringType);
1947 expect(variableC.initializer.staticType, stringType); 1947 expect(variableC.initializer.staticType, stringType);
1948 } 1948 }
1949 1949
1950 void test_perform_reresolution() { 1950 void test_perform_reresolution() {
1951 enableStrongMode(); 1951 enableStrongMode();
1952 AnalysisTarget source = newSource( 1952 AnalysisTarget source = newSource(
1953 '/test.dart', 1953 '/test.dart',
1954 ''' 1954 '''
1955 const topLevel = ''; 1955 const topLevel = '';
1956 class C { 1956 class C {
1957 String field = topLevel; 1957 String field = topLevel;
1958 } 1958 }
1959 '''); 1959 ''');
1960 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); 1960 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8);
1961 CompilationUnit unit = outputs[RESOLVED_UNIT7]; 1961 CompilationUnit unit = outputs[RESOLVED_UNIT8];
1962 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel'); 1962 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel');
1963 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field'); 1963 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field');
1964 VariableElement topLevel = topLevelDecl.name.staticElement; 1964 VariableElement topLevel = topLevelDecl.name.staticElement;
1965 VariableElement field = fieldDecl.name.staticElement; 1965 VariableElement field = fieldDecl.name.staticElement;
1966 1966
1967 InterfaceType stringType = context.typeProvider.stringType; 1967 InterfaceType stringType = context.typeProvider.stringType;
1968 expect(topLevel.type, stringType); 1968 expect(topLevel.type, stringType);
1969 expect(field.type, stringType); 1969 expect(field.type, stringType);
1970 expect(fieldDecl.initializer.staticType, stringType); 1970 expect(fieldDecl.initializer.staticType, stringType);
1971 } 1971 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
2118 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3'); 2118 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field3');
2119 VariableElement topLevel = topLevelDecl.name.staticElement; 2119 VariableElement topLevel = topLevelDecl.name.staticElement;
2120 VariableElement field = fieldDecl.name.staticElement; 2120 VariableElement field = fieldDecl.name.staticElement;
2121 2121
2122 computeResult(field, INFERRED_STATIC_VARIABLE, 2122 computeResult(field, INFERRED_STATIC_VARIABLE,
2123 matcher: isInferStaticVariableTypeTask); 2123 matcher: isInferStaticVariableTypeTask);
2124 InterfaceType stringType = context.typeProvider.stringType; 2124 InterfaceType stringType = context.typeProvider.stringType;
2125 expect(topLevel.type, stringType); 2125 expect(topLevel.type, stringType);
2126 expect(field.type, stringType); 2126 expect(field.type, stringType);
2127 expect(fieldDecl.initializer.staticType, stringType); 2127 expect(fieldDecl.initializer.staticType, stringType);
2128 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0));
2129 }
2130
2131 void test_perform_reresolution() {
Brian Wilkerson 2015/10/06 19:04:47 Out of curiosity, why was this test removed?
Leaf 2015/10/06 20:30:55 The thing it's testing for (re-resolution of field
2132 AnalysisTarget source = newSource(
2133 '/test.dart',
2134 '''
2135 const topLevel = '';
2136 class C {
2137 String field = topLevel;
2138 }
2139 ''');
2140 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2141 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2142 VariableDeclaration topLevelDecl = getTopLevelVariable(unit, 'topLevel');
2143 VariableDeclaration fieldDecl = getFieldInClass(unit, 'C', 'field');
2144 VariableElement topLevel = topLevelDecl.name.staticElement;
2145 VariableElement field = fieldDecl.name.staticElement;
2146
2147 computeResult(field, INFERRED_STATIC_VARIABLE,
2148 matcher: isInferStaticVariableTypeTask);
2149 InterfaceType stringType = context.typeProvider.stringType;
2150 expect(topLevel.type, stringType);
2151 expect(field.type, stringType);
2152 expect(fieldDecl.initializer.staticType, stringType);
2153 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0));
2154 } 2128 }
2155 2129
2156 void test_perform_const() { 2130 void test_perform_const() {
2157 AnalysisTarget source = newSource( 2131 AnalysisTarget source = newSource(
2158 '/test.dart', 2132 '/test.dart',
2159 ''' 2133 '''
2160 const topLevel = "hello"; 2134 const topLevel = "hello";
2161 class C { 2135 class C {
2162 var field = topLevel; 2136 var field = topLevel;
2163 } 2137 }
2164 '''); 2138 ''');
2165 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2139 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2166 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2140 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2167 VariableElement topLevel = 2141 VariableElement topLevel =
2168 getTopLevelVariable(unit, 'topLevel').name.staticElement; 2142 getTopLevelVariable(unit, 'topLevel').name.staticElement;
2169 VariableElement field = 2143 VariableElement field =
2170 getFieldInClass(unit, 'C', 'field').name.staticElement; 2144 getFieldInClass(unit, 'C', 'field').name.staticElement;
2171 2145
2172 computeResult(field, INFERRED_STATIC_VARIABLE, 2146 computeResult(field, INFERRED_STATIC_VARIABLE,
2173 matcher: isInferStaticVariableTypeTask); 2147 matcher: isInferStaticVariableTypeTask);
2174 InterfaceType stringType = context.typeProvider.stringType; 2148 InterfaceType stringType = context.typeProvider.stringType;
2175 expect(topLevel.type, stringType); 2149 expect(topLevel.type, stringType);
2176 expect(field.type, stringType); 2150 expect(field.type, stringType);
2177 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0));
2178 } 2151 }
2179 2152
2180 void test_perform_cycle() { 2153 void test_perform_cycle() {
2181 AnalysisTarget source = newSource( 2154 AnalysisTarget source = newSource(
2182 '/test.dart', 2155 '/test.dart',
2183 ''' 2156 '''
2184 var piFirst = true; 2157 var piFirst = true;
2185 var pi = piFirst ? 3.14 : tau / 2; 2158 var pi = piFirst ? 3.14 : tau / 2;
2186 var tau = piFirst ? pi * 2 : 6.28; 2159 var tau = piFirst ? pi * 2 : 6.28;
2187 '''); 2160 ''');
2188 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2161 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2189 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2162 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2190 VariableElement piFirst = 2163 VariableElement piFirst =
2191 getTopLevelVariable(unit, 'piFirst').name.staticElement; 2164 getTopLevelVariable(unit, 'piFirst').name.staticElement;
2192 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; 2165 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement;
2193 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; 2166 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement;
2194 2167
2195 computeResult(piFirst, INFERRED_STATIC_VARIABLE, 2168 computeResult(piFirst, INFERRED_STATIC_VARIABLE,
2196 matcher: isInferStaticVariableTypeTask); 2169 matcher: isInferStaticVariableTypeTask);
2197 expect(piFirst.type, context.typeProvider.boolType); 2170 expect(piFirst.type, context.typeProvider.boolType);
2198 expect(pi.type.isDynamic, isTrue); 2171 expect(pi.type.isDynamic, isTrue);
2199 expect(tau.type.isDynamic, isTrue); 2172 expect(tau.type.isDynamic, isTrue);
2200 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0));
2201 } 2173 }
2202 2174
2203 void test_perform_error() { 2175 void test_perform_error() {
2204 AnalysisTarget source = newSource( 2176 AnalysisTarget source = newSource(
2205 '/test.dart', 2177 '/test.dart',
2206 ''' 2178 '''
2207 var a = '' / null; 2179 var a = '' / null;
2208 '''); 2180 ''');
2209 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2181 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2210 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2182 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2211 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; 2183 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement;
2212 2184
2213 computeResult(a, INFERRED_STATIC_VARIABLE, 2185 computeResult(a, INFERRED_STATIC_VARIABLE,
2214 matcher: isInferStaticVariableTypeTask); 2186 matcher: isInferStaticVariableTypeTask);
2215 expect(a.type.isDynamic, isTrue); 2187 expect(a.type.isDynamic, isTrue);
2216 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(1));
2217 } 2188 }
2218 2189
2219 void test_perform_null() { 2190 void test_perform_null() {
2220 AnalysisTarget source = newSource( 2191 AnalysisTarget source = newSource(
2221 '/test.dart', 2192 '/test.dart',
2222 ''' 2193 '''
2223 var a = null; 2194 var a = null;
2224 '''); 2195 ''');
2225 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5); 2196 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT5);
2226 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2197 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2227 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement; 2198 VariableElement a = getTopLevelVariable(unit, 'a').name.staticElement;
2228 2199
2229 computeResult(a, INFERRED_STATIC_VARIABLE, 2200 computeResult(a, INFERRED_STATIC_VARIABLE,
2230 matcher: isInferStaticVariableTypeTask); 2201 matcher: isInferStaticVariableTypeTask);
2231 expect(a.type.isDynamic, isTrue); 2202 expect(a.type.isDynamic, isTrue);
2232 expect(outputs[INFER_STATIC_VARIABLE_ERRORS], hasLength(0));
2233 } 2203 }
2234 } 2204 }
2235 2205
2236 @reflectiveTest 2206 @reflectiveTest
2237 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { 2207 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest {
2238 test_perform() { 2208 test_perform() {
2239 Source library = newSource( 2209 Source library = newSource(
2240 '/lib.dart', 2210 '/lib.dart',
2241 r''' 2211 r'''
2242 library lib; 2212 library lib;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 class A {} 2400 class A {}
2431 class C { 2401 class C {
2432 static final f = ''; 2402 static final f = '';
2433 var g = 0; 2403 var g = 0;
2434 } 2404 }
2435 '''); 2405 ''');
2436 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2406 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2437 computeResult(target, RESOLVED_UNIT5, 2407 computeResult(target, RESOLVED_UNIT5,
2438 matcher: isPartiallyResolveUnitReferencesTask); 2408 matcher: isPartiallyResolveUnitReferencesTask);
2439 // Test the outputs 2409 // Test the outputs
2440 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(5)); 2410 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(4));
2441 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2411 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2442 expect(unit, same(outputs[RESOLVED_UNIT5])); 2412 expect(unit, same(outputs[RESOLVED_UNIT5]));
2443 // Test the state of the AST 2413 // Test the state of the AST
2444 TopLevelVariableDeclaration a = unit.declarations[0]; 2414 TopLevelVariableDeclaration a = unit.declarations[0];
2445 VariableDeclaration variableA = a.variables.variables[0]; 2415 VariableDeclaration variableA = a.variables.variables[0];
2446 SimpleIdentifier initializer = variableA.initializer; 2416 SimpleIdentifier initializer = variableA.initializer;
2447 expect(initializer.staticElement, isNotNull); 2417 expect(initializer.staticElement, isNotNull);
2448 // Test the error generation
2449 _fillErrorListener(PARTIALLY_RESOLVE_REFERENCES_ERRORS);
2450 errorListener.assertNoErrors();
2451 } 2418 }
2452 2419
2453 test_perform_importExport() { 2420 test_perform_importExport() {
2454 newSource( 2421 newSource(
2455 '/a.dart', 2422 '/a.dart',
2456 ''' 2423 '''
2457 library a; 2424 library a;
2458 class A<T> { 2425 class A<T> {
2459 T m() {} 2426 T m() {}
2460 } 2427 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2551 2518
2552 ConstructorDeclaration constructor = members[0]; 2519 ConstructorDeclaration constructor = members[0];
2553 expectReference(constructor.body, false); 2520 expectReference(constructor.body, false);
2554 2521
2555 MethodDeclaration method = members[1]; 2522 MethodDeclaration method = members[1];
2556 expectReference(method.body, false); 2523 expectReference(method.body, false);
2557 } 2524 }
2558 } 2525 }
2559 2526
2560 @reflectiveTest 2527 @reflectiveTest
2561 class ResolveFunctionBodiesInUnitTaskTest extends _AbstractDartTaskTest { 2528 class ResolveUnitTaskTest extends _AbstractDartTaskTest {
2562 void test_perform() { 2529 void test_perform() {
2563 AnalysisTarget source = newSource( 2530 AnalysisTarget source = newSource(
2564 '/test.dart', 2531 '/test.dart',
2565 ''' 2532 '''
2566 void f() { 2533 void f() {
2567 var c = new C(); 2534 var c = new C();
2568 c.m(); 2535 c.m();
2569 } 2536 }
2570 class C { 2537 class C {
2571 void m() { 2538 void m() {
2572 f(); 2539 f();
2573 } 2540 }
2574 } 2541 }
2575 '''); 2542 ''');
2576 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, 2543 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9,
2577 matcher: isResolveFunctionBodiesInUnitTask); 2544 matcher: isResolveUnitTask);
2578 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2545 CompilationUnit unit = outputs[RESOLVED_UNIT9];
2579 2546
2580 FunctionDeclaration f = unit.declarations[0]; 2547 FunctionDeclaration f = unit.declarations[0];
2581 _assertResolved(f.functionExpression.body); 2548 _assertResolved(f.functionExpression.body);
2582 2549
2583 MethodDeclaration m = (unit.declarations[1] as ClassDeclaration).members[0]; 2550 MethodDeclaration m = (unit.declarations[1] as ClassDeclaration).members[0];
2584 _assertResolved(m.body); 2551 _assertResolved(m.body);
2585 2552
2586 expect(outputs[RESOLVE_FUNCTION_BODIES_ERRORS], hasLength(0)); 2553 expect(outputs[RESOLVE_UNIT_ERRORS], hasLength(0));
2587 } 2554 }
2588 2555
2589 void _assertResolved(FunctionBody body) { 2556 void _assertResolved(FunctionBody body) {
2590 ResolutionVerifier verifier = new ResolutionVerifier(); 2557 ResolutionVerifier verifier = new ResolutionVerifier();
2591 body.accept(verifier); 2558 body.accept(verifier);
2592 verifier.assertResolved(); 2559 verifier.assertResolved();
2593 } 2560 }
2594 } 2561 }
2595 2562
2596 @reflectiveTest 2563 @reflectiveTest
2597 class StrongModeInferenceTest extends _AbstractDartTaskTest { 2564 class StrongModeInferenceTest extends _AbstractDartTaskTest {
2598
2599 @override 2565 @override
2600 void setUp() { 2566 void setUp() {
2601 super.setUp(); 2567 super.setUp();
2602 enableStrongMode(); 2568 enableStrongMode();
2603 } 2569 }
2604 2570
2571 void test_library_cycle_singleton() {
Brian Wilkerson 2015/10/06 19:04:47 These tests look like they're testing the results
Leaf 2015/10/07 18:53:55 Done.
2572 Source source = newSource(
2573 '/test.dart',
2574 '''
2575 import 'dart:core';
2576 ''');
2577 computeResult(new LibrarySpecificUnit(source, source), LIBRARY_CYCLE);
2578 List<LibraryElement> component = outputs[LIBRARY_CYCLE];
2579 List<CompilationUnitElement> units = outputs[LIBRARY_CYCLE_UNITS];
2580 expect(component, hasLength(1));
2581 expect(units, hasLength(1));
2582
2583 computeResult(
2584 new LibrarySpecificUnit(source, source), LIBRARY_CYCLE_DEPENDENCIES);
2585 List<CompilationUnitElement> deps = outputs[LIBRARY_CYCLE_DEPENDENCIES];
2586 expect(deps, hasLength(1));
2587 }
2588
2589 void test_library_cycle_linear() {
2590 List<Source> sources = newSources({
2591 '/a.dart': '''
2592 ''',
2593 '/b.dart': '''
2594 import 'a.dart';
2595 '''
2596 });
2597 List<List<LibraryElement>> components =
2598 computeLibraryResults(sources, LIBRARY_CYCLE).toList();
2599 List<LibraryElement> component0 = components[0];
2600 List<LibraryElement> component1 = components[1];
2601 expect(component0, hasLength(1));
2602 expect(component1, hasLength(1));
2603
2604 List<List<CompilationUnitElement>> deps =
2605 computeLibraryResults(sources, LIBRARY_CYCLE_DEPENDENCIES).toList();
2606 List<CompilationUnitElement> dep0 = deps[0];
2607 List<CompilationUnitElement> dep1 = deps[1];
2608 expect(dep0, hasLength(1)); // dart:core
2609 expect(dep1, hasLength(2)); // dart:core, a.dart
2610 }
2611
2612 void test_library_cycle_tree() {
2613 List<Source> sources = newSources({
2614 '/a.dart': '''
2615 ''',
2616 '/b.dart': '''
2617 ''',
2618 '/c.dart': '''
2619 import 'a.dart';
2620 import 'b.dart';
2621 '''
2622 });
2623 List<List<LibraryElement>> components =
2624 computeLibraryResults(sources, LIBRARY_CYCLE).toList();
2625 List<LibraryElement> component0 = components[0];
2626 List<LibraryElement> component1 = components[1];
2627 List<LibraryElement> component2 = components[2];
2628 expect(component0, hasLength(1));
2629 expect(component1, hasLength(1));
2630 expect(component2, hasLength(1));
2631
2632 List<List<CompilationUnitElement>> deps =
2633 computeLibraryResults(sources, LIBRARY_CYCLE_DEPENDENCIES).toList();
2634 List<CompilationUnitElement> dep0 = deps[0];
2635 List<CompilationUnitElement> dep1 = deps[1];
2636 List<CompilationUnitElement> dep2 = deps[2];
2637 expect(dep0, hasLength(1)); // dart:core
2638 expect(dep1, hasLength(1)); // dart:core,
2639 expect(dep2, hasLength(3)); // dart:core, a.dart, b.dart
2640 }
2641
2642 void test_library_cycle_loop() {
2643 List<Source> sources = newSources({
2644 '/a.dart': '''
2645 import 'c.dart';
2646 ''',
2647 '/b.dart': '''
2648 import 'a.dart';
2649 ''',
2650 '/c.dart': '''
2651 import 'b.dart';
2652 '''
2653 });
2654 List<List<LibraryElement>> components =
2655 computeLibraryResults(sources, LIBRARY_CYCLE).toList();
2656 List<LibraryElement> component0 = components[0];
2657 List<LibraryElement> component1 = components[1];
2658 List<LibraryElement> component2 = components[2];
2659
2660 expect(component0, hasLength(3));
2661 expect(component1, hasLength(3));
2662 expect(component2, hasLength(3));
2663
2664 List<List<CompilationUnitElement>> deps =
2665 computeLibraryResults(sources, LIBRARY_CYCLE_DEPENDENCIES).toList();
2666 List<CompilationUnitElement> dep0 = deps[0];
2667 List<CompilationUnitElement> dep1 = deps[1];
2668 List<CompilationUnitElement> dep2 = deps[2];
2669 expect(dep0, hasLength(1)); // dart:core
2670 expect(dep1, hasLength(1)); // dart:core
2671 expect(dep2, hasLength(1)); // dart:core
2672 }
2673
2674 void test_library_cycle_self_loop() {
2675 List<Source> sources = newSources({
2676 '/a.dart': '''
2677 import 'a.dart';
2678 '''
2679 });
2680 List<List<LibraryElement>> components =
2681 computeLibraryResults(sources, LIBRARY_CYCLE).toList();
2682 List<LibraryElement> component0 = components[0];
2683
2684 expect(component0, hasLength(1));
2685
2686 List<List<CompilationUnitElement>> deps =
2687 computeLibraryResults(sources, LIBRARY_CYCLE_DEPENDENCIES).toList();
2688 List<CompilationUnitElement> dep0 = deps[0];
2689 expect(dep0, hasLength(1)); // dart:core
2690 }
2691
2692 void test_library_double_loop() {
2693 List<Source> sources = newSources({
2694 '/a.dart': '''
2695 import 'b.dart';
2696 ''',
2697 '/b.dart': '''
2698 import 'a.dart';
2699 ''',
2700 '/c.dart': '''
2701 import 'd.dart' as foo;
2702 import 'a.dart' as bar;
2703 export 'b.dart';
2704 ''',
2705 '/d.dart': '''
2706 import 'c.dart' as foo;
2707 import 'b.dart' as bar;
2708 export 'a.dart';
2709 '''
2710 });
2711 List<List<LibraryElement>> components =
2712 computeLibraryResults(sources, LIBRARY_CYCLE).toList();
2713 List<LibraryElement> component0 = components[0];
2714 List<LibraryElement> component1 = components[1];
2715 List<LibraryElement> component2 = components[2];
2716 List<LibraryElement> component3 = components[3];
2717
2718 expect(component0, hasLength(2));
2719 expect(component1, hasLength(2));
2720 expect(component2, hasLength(2));
2721 expect(component3, hasLength(2));
2722
2723 List<List<CompilationUnitElement>> deps =
2724 computeLibraryResults(sources, LIBRARY_CYCLE_DEPENDENCIES).toList();
2725 List<CompilationUnitElement> dep0 = deps[0];
2726 List<CompilationUnitElement> dep1 = deps[1];
2727 List<CompilationUnitElement> dep2 = deps[2];
2728 List<CompilationUnitElement> dep3 = deps[3];
2729 expect(dep0, hasLength(1)); // dart:core
2730 expect(dep1, hasLength(1)); // dart:core
2731 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart
2732 expect(dep3, hasLength(3)); // dart:core, a.dart, b.dart
2733 }
2734
2605 // Check that even within a static variable cycle, inferred 2735 // Check that even within a static variable cycle, inferred
2606 // types get propagated to the members of the cycle. 2736 // types get propagated to the members of the cycle.
2607 void test_perform_cycle() { 2737 void test_perform_cycle() {
2608 AnalysisTarget source = newSource( 2738 AnalysisTarget source = newSource(
2609 '/test.dart', 2739 '/test.dart',
2610 ''' 2740 '''
2611 var piFirst = true; 2741 var piFirst = true;
2612 var pi = piFirst ? 3.14 : tau / 2; 2742 var pi = piFirst ? 3.14 : tau / 2;
2613 var tau = piFirst ? pi * 2 : 6.28; 2743 var tau = piFirst ? pi * 2 : 6.28;
2614 '''); 2744 ''');
2615 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); 2745 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
2616 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2746 CompilationUnit unit = outputs[RESOLVED_UNIT9];
2617 VariableElement piFirst = 2747 VariableElement piFirst =
2618 getTopLevelVariable(unit, 'piFirst').name.staticElement; 2748 getTopLevelVariable(unit, 'piFirst').name.staticElement;
2619 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement; 2749 VariableElement pi = getTopLevelVariable(unit, 'pi').name.staticElement;
2620 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement; 2750 VariableElement tau = getTopLevelVariable(unit, 'tau').name.staticElement;
2621 Expression piFirstUse = (getTopLevelVariable(unit, 'tau').initializer 2751 Expression piFirstUse = (getTopLevelVariable(unit, 'tau').initializer
2622 as ConditionalExpression).condition; 2752 as ConditionalExpression).condition;
2623 2753
2624 expect(piFirstUse.staticType, context.typeProvider.boolType); 2754 expect(piFirstUse.staticType, context.typeProvider.boolType);
2625 expect(piFirst.type, context.typeProvider.boolType); 2755 expect(piFirst.type, context.typeProvider.boolType);
2626 expect(pi.type.isDynamic, isTrue); 2756 expect(pi.type.isDynamic, isTrue);
2627 expect(tau.type.isDynamic, isTrue); 2757 expect(tau.type.isDynamic, isTrue);
2628 } 2758 }
2629 2759
2630 void test_perform_local_explicit_disabled() { 2760 void test_perform_local_explicit_disabled() {
2631 AnalysisTarget source = newSource( 2761 AnalysisTarget source = newSource(
2632 '/test.dart', 2762 '/test.dart',
2633 ''' 2763 '''
2634 test() { 2764 test() {
2635 int x = 3; 2765 int x = 3;
2636 x = "hi"; 2766 x = "hi";
2637 } 2767 }
2638 '''); 2768 ''');
2639 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); 2769 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
2640 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2770 CompilationUnit unit = outputs[RESOLVED_UNIT9];
2641 2771
2642 InterfaceType intType = context.typeProvider.intType; 2772 InterfaceType intType = context.typeProvider.intType;
2643 InterfaceType stringType = context.typeProvider.stringType; 2773 InterfaceType stringType = context.typeProvider.stringType;
2644 2774
2645 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); 2775 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test");
2646 VariableDeclaration decl = 2776 VariableDeclaration decl =
2647 (statements[0] as VariableDeclarationStatement).variables.variables[0]; 2777 (statements[0] as VariableDeclarationStatement).variables.variables[0];
2648 expect(decl.element.type, intType); 2778 expect(decl.element.type, intType);
2649 expect(decl.initializer.staticType, intType); 2779 expect(decl.initializer.staticType, intType);
2650 2780
(...skipping 28 matching lines...) Expand all
2679 AnalysisTarget source = newSource( 2809 AnalysisTarget source = newSource(
2680 '/test.dart', 2810 '/test.dart',
2681 ''' 2811 '''
2682 test() { 2812 test() {
2683 int x = 3; 2813 int x = 3;
2684 x = "hi"; 2814 x = "hi";
2685 var y = 3; 2815 var y = 3;
2686 y = "hi"; 2816 y = "hi";
2687 } 2817 }
2688 '''); 2818 ''');
2689 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); 2819 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
2690 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2820 CompilationUnit unit = outputs[RESOLVED_UNIT9];
2691 2821
2692 InterfaceType intType = context.typeProvider.intType; 2822 InterfaceType intType = context.typeProvider.intType;
2693 InterfaceType stringType = context.typeProvider.stringType; 2823 InterfaceType stringType = context.typeProvider.stringType;
2694 2824
2695 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test"); 2825 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test");
2696 2826
2697 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 2827 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
2698 assertAssignmentStatementTypes(statements[1], intType, stringType); 2828 assertAssignmentStatementTypes(statements[1], intType, stringType);
2699 assertVariableDeclarationStatementTypes(statements[2], intType, intType); 2829 assertVariableDeclarationStatementTypes(statements[2], intType, intType);
2700 assertAssignmentStatementTypes(statements[3], intType, stringType); 2830 assertAssignmentStatementTypes(statements[3], intType, stringType);
(...skipping 16 matching lines...) Expand all
2717 b = 4; 2847 b = 4;
2718 var c = z; 2848 var c = z;
2719 c = "hi"; 2849 c = "hi";
2720 c = 4; 2850 c = 4;
2721 } 2851 }
2722 2852
2723 int y; // field def after use 2853 int y; // field def after use
2724 final z = 42; // should infer `int` 2854 final z = 42; // should infer `int`
2725 } 2855 }
2726 '''); 2856 ''');
2727 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); 2857 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
2728 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2858 CompilationUnit unit = outputs[RESOLVED_UNIT9];
2729 2859
2730 InterfaceType intType = context.typeProvider.intType; 2860 InterfaceType intType = context.typeProvider.intType;
2731 InterfaceType stringType = context.typeProvider.stringType; 2861 InterfaceType stringType = context.typeProvider.stringType;
2732 2862
2733 List<Statement> statements = getStatementsInMethod(unit, "A", "test1"); 2863 List<Statement> statements = getStatementsInMethod(unit, "A", "test1");
2734 2864
2735 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 2865 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
2736 assertAssignmentStatementTypes(statements[1], intType, stringType); 2866 assertAssignmentStatementTypes(statements[1], intType, stringType);
2737 assertAssignmentStatementTypes(statements[2], intType, intType); 2867 assertAssignmentStatementTypes(statements[2], intType, intType);
2738 2868
(...skipping 27 matching lines...) Expand all
2766 b = /*severe:StaticTypeError*/"hi"; 2896 b = /*severe:StaticTypeError*/"hi";
2767 b = 4; 2897 b = 4;
2768 var c = z; 2898 var c = z;
2769 c = /*severe:StaticTypeError*/"hi"; 2899 c = /*severe:StaticTypeError*/"hi";
2770 c = 4; 2900 c = 4;
2771 } 2901 }
2772 2902
2773 int y = 0; // field def after use 2903 int y = 0; // field def after use
2774 final z = 42; // should infer `int` 2904 final z = 42; // should infer `int`
2775 '''); 2905 ''');
2776 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); 2906 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
2777 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2907 CompilationUnit unit = outputs[RESOLVED_UNIT9];
2778 2908
2779 InterfaceType intType = context.typeProvider.intType; 2909 InterfaceType intType = context.typeProvider.intType;
2780 InterfaceType stringType = context.typeProvider.stringType; 2910 InterfaceType stringType = context.typeProvider.stringType;
2781 2911
2782 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test1"); 2912 List<Statement> statements = getStatementsInTopLevelFunction(unit, "test1");
2783 2913
2784 assertVariableDeclarationStatementTypes(statements[0], intType, intType); 2914 assertVariableDeclarationStatementTypes(statements[0], intType, intType);
2785 assertAssignmentStatementTypes(statements[1], intType, stringType); 2915 assertAssignmentStatementTypes(statements[1], intType, stringType);
2786 assertAssignmentStatementTypes(statements[2], intType, intType); 2916 assertAssignmentStatementTypes(statements[2], intType, intType);
2787 2917
(...skipping 30 matching lines...) Expand all
2818 2948
2819 test() { 2949 test() {
2820 x = "hi"; 2950 x = "hi";
2821 y = /*severe:StaticTypeError*/"hi"; 2951 y = /*severe:StaticTypeError*/"hi";
2822 A.x = "hi"; 2952 A.x = "hi";
2823 A.y = /*severe:StaticTypeError*/"hi"; 2953 A.y = /*severe:StaticTypeError*/"hi";
2824 new A().x2 = "hi"; 2954 new A().x2 = "hi";
2825 new A().y2 = /*severe:StaticTypeError*/"hi"; 2955 new A().y2 = /*severe:StaticTypeError*/"hi";
2826 } 2956 }
2827 '''); 2957 ''');
2828 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8); 2958 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT9);
2829 CompilationUnit unit = outputs[RESOLVED_UNIT8]; 2959 CompilationUnit unit = outputs[RESOLVED_UNIT9];
2830 2960
2831 InterfaceType intType = context.typeProvider.intType; 2961 InterfaceType intType = context.typeProvider.intType;
2832 InterfaceType stringType = context.typeProvider.stringType; 2962 InterfaceType stringType = context.typeProvider.stringType;
2833 DartType bottomType = context.typeProvider.bottomType; 2963 DartType bottomType = context.typeProvider.bottomType;
2834 DartType dynamicType = context.typeProvider.dynamicType; 2964 DartType dynamicType = context.typeProvider.dynamicType;
2835 2965
2836 assertVariableDeclarationTypes( 2966 assertVariableDeclarationTypes(
2837 getTopLevelVariable(unit, "x"), dynamicType, bottomType); 2967 getTopLevelVariable(unit, "x"), dynamicType, bottomType);
2838 assertVariableDeclarationTypes( 2968 assertVariableDeclarationTypes(
2839 getTopLevelVariable(unit, "y"), intType, intType); 2969 getTopLevelVariable(unit, "y"), intType, intType);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 class B { static var y = A.x; } 3002 class B { static var y = A.x; }
2873 3003
2874 test1() { 3004 test1() {
2875 x = /*severe:StaticTypeError*/"hi"; 3005 x = /*severe:StaticTypeError*/"hi";
2876 y = /*severe:StaticTypeError*/"hi"; 3006 y = /*severe:StaticTypeError*/"hi";
2877 A.x = /*severe:StaticTypeError*/"hi"; 3007 A.x = /*severe:StaticTypeError*/"hi";
2878 B.y = /*severe:StaticTypeError*/"hi"; 3008 B.y = /*severe:StaticTypeError*/"hi";
2879 } 3009 }
2880 '''); 3010 ''');
2881 computeResult( 3011 computeResult(
2882 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8); 3012 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9);
2883 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; 3013 CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
2884 computeResult( 3014 computeResult(
2885 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8); 3015 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9);
2886 CompilationUnit unit2 = outputs[RESOLVED_UNIT8]; 3016 CompilationUnit unit2 = outputs[RESOLVED_UNIT9];
2887 3017
2888 InterfaceType intType = context.typeProvider.intType; 3018 InterfaceType intType = context.typeProvider.intType;
2889 InterfaceType stringType = context.typeProvider.stringType; 3019 InterfaceType stringType = context.typeProvider.stringType;
2890 3020
2891 assertVariableDeclarationTypes( 3021 assertVariableDeclarationTypes(
2892 getTopLevelVariable(unit1, "x"), intType, intType); 3022 getTopLevelVariable(unit1, "x"), intType, intType);
2893 assertVariableDeclarationTypes( 3023 assertVariableDeclarationTypes(
2894 getFieldInClass(unit1, "A", "x"), intType, intType); 3024 getFieldInClass(unit1, "A", "x"), intType, intType);
2895 3025
2896 assertVariableDeclarationTypes( 3026 assertVariableDeclarationTypes(
(...skipping 26 matching lines...) Expand all
2923 3053
2924 test1() { 3054 test1() {
2925 int t = 3; 3055 int t = 3;
2926 t = x; 3056 t = x;
2927 t = y; 3057 t = y;
2928 t = A.x; 3058 t = A.x;
2929 t = B.y; 3059 t = B.y;
2930 } 3060 }
2931 '''); 3061 ''');
2932 computeResult( 3062 computeResult(
2933 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8); 3063 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT9);
2934 CompilationUnit unit1 = outputs[RESOLVED_UNIT8]; 3064 CompilationUnit unit1 = outputs[RESOLVED_UNIT9];
2935 computeResult( 3065 computeResult(
2936 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT8); 3066 new LibrarySpecificUnit(secondSource, secondSource), RESOLVED_UNIT9);
2937 CompilationUnit unit2 = outputs[RESOLVED_UNIT8]; 3067 CompilationUnit unit2 = outputs[RESOLVED_UNIT9];
2938 3068
2939 InterfaceType intType = context.typeProvider.intType; 3069 InterfaceType intType = context.typeProvider.intType;
2940 3070
2941 assertVariableDeclarationTypes( 3071 assertVariableDeclarationTypes(
2942 getTopLevelVariable(unit1, "x"), intType, intType); 3072 getTopLevelVariable(unit1, "x"), intType, intType);
2943 assertVariableDeclarationTypes( 3073 assertVariableDeclarationTypes(
2944 getFieldInClass(unit1, "A", "x"), intType, intType); 3074 getFieldInClass(unit1, "A", "x"), intType, intType);
2945 3075
2946 assertVariableDeclarationTypes( 3076 assertVariableDeclarationTypes(
2947 getTopLevelVariable(unit2, "y"), intType, intType); 3077 getTopLevelVariable(unit2, "y"), intType, intType);
2948 assertVariableDeclarationTypes( 3078 assertVariableDeclarationTypes(
2949 getFieldInClass(unit2, "B", "y"), intType, intType); 3079 getFieldInClass(unit2, "B", "y"), intType, intType);
2950 3080
2951 List<Statement> statements = 3081 List<Statement> statements =
2952 getStatementsInTopLevelFunction(unit2, "test1"); 3082 getStatementsInTopLevelFunction(unit2, "test1");
2953 3083
2954 assertAssignmentStatementTypes(statements[1], intType, intType); 3084 assertAssignmentStatementTypes(statements[1], intType, intType);
2955 assertAssignmentStatementTypes(statements[2], intType, intType); 3085 assertAssignmentStatementTypes(statements[2], intType, intType);
2956 assertAssignmentStatementTypes(statements[3], intType, intType); 3086 assertAssignmentStatementTypes(statements[3], intType, intType);
2957 assertAssignmentStatementTypes(statements[4], intType, intType); 3087 assertAssignmentStatementTypes(statements[4], intType, intType);
2958 } 3088 }
2959 3089
2960 // Test inference of instance fields across units 3090 // Test inference of instance fields across units
2961 // TODO(leafp): Fix this 3091 void test_perform_inference_cross_unit_instance() {
2962 // https://github.com/dart-lang/dev_compiler/issues/354
2963 void fail_perform_inference_cross_unit_instance() {
2964 List<Source> sources = newSources({ 3092 List<Source> sources = newSources({
2965 '/a7.dart': ''' 3093 '/a7.dart': '''
2966 import 'b7.dart'; 3094 import 'b7.dart';
2967 class A { 3095 class A {
2968 final a2 = new B().b2; 3096 final a2 = new B().b2;
2969 } 3097 }
2970 ''', 3098 ''',
2971 '/b7.dart': ''' 3099 '/b7.dart': '''
2972 class B { 3100 class B {
2973 final b2 = 1; 3101 final b2 = 1;
2974 } 3102 }
2975 ''', 3103 ''',
2976 '/main7.dart': ''' 3104 '/main7.dart': '''
2977 import "a7.dart"; 3105 import "a7.dart";
2978 3106
2979 test1() { 3107 test1() {
2980 int x = 0; 3108 int x = 0;
2981 x = new A().a2; 3109 x = new A().a2;
2982 } 3110 }
2983 ''' 3111 '''
2984 }); 3112 });
2985 List<dynamic> units = 3113 List<dynamic> units =
2986 computeLibraryResults(sources, RESOLVED_UNIT8).toList(); 3114 computeLibraryResults(sources, RESOLVED_UNIT9).toList();
2987 CompilationUnit unit0 = units[0]; 3115 CompilationUnit unit0 = units[0];
2988 CompilationUnit unit1 = units[1]; 3116 CompilationUnit unit1 = units[1];
2989 CompilationUnit unit2 = units[2]; 3117 CompilationUnit unit2 = units[2];
2990 3118
2991 InterfaceType intType = context.typeProvider.intType; 3119 InterfaceType intType = context.typeProvider.intType;
2992 3120
2993 assertVariableDeclarationTypes( 3121 assertVariableDeclarationTypes(
2994 getFieldInClass(unit0, "A", "a2"), intType, intType); 3122 getFieldInClass(unit0, "A", "a2"), intType, intType);
2995 3123
2996 assertVariableDeclarationTypes( 3124 assertVariableDeclarationTypes(
2997 getFieldInClass(unit1, "B", "b2"), intType, intType); 3125 getFieldInClass(unit1, "B", "b2"), intType, intType);
2998 3126
2999 List<Statement> statements = 3127 List<Statement> statements =
3000 getStatementsInTopLevelFunction(unit2, "test1"); 3128 getStatementsInTopLevelFunction(unit2, "test1");
3001 3129
3002 assertAssignmentStatementTypes(statements[1], intType, intType); 3130 assertAssignmentStatementTypes(statements[1], intType, intType);
3003 } 3131 }
3004 3132
3005 // Test inference between static and instance fields 3133 // Test inference between static and instance fields
3006 // TODO(leafp): Fix this 3134 void test_perform_inference_cross_unit_static_instance() {
3007 // https://github.com/dart-lang/dev_compiler/issues/354
3008 void fail_perform_inference_cross_unit_static_instance() {
3009 List<Source> sources = newSources({ 3135 List<Source> sources = newSources({
3010 '/a.dart': ''' 3136 '/a.dart': '''
3011 import 'b.dart'; 3137 import 'b.dart';
3012 class A { 3138 class A {
3013 static final a1 = B.b1; 3139 static final a1 = B.b1;
3014 final a2 = new B().b2; 3140 final a2 = new B().b2;
3015 } 3141 }
3016 ''', 3142 ''',
3017 '/b.dart': ''' 3143 '/b.dart': '''
3018 class B { 3144 class B {
3019 static final b1 = 1; 3145 static final b1 = 1;
3020 final b2 = 1; 3146 final b2 = 1;
3021 } 3147 }
3022 ''', 3148 ''',
3023 '/main.dart': ''' 3149 '/main.dart': '''
3024 import "a.dart"; 3150 import "a.dart";
3025 3151
3026 test1() { 3152 test1() {
3027 int x = 0; 3153 int x = 0;
3028 // inference in A now works. 3154 // inference in A now works.
3029 x = A.a1; 3155 x = A.a1;
3030 x = new A().a2; 3156 x = new A().a2;
3031 } 3157 }
3032 ''' 3158 '''
3033 }); 3159 });
3034 List<dynamic> units = 3160 List<dynamic> units =
3035 computeLibraryResults(sources, RESOLVED_UNIT8).toList(); 3161 computeLibraryResults(sources, RESOLVED_UNIT9).toList();
3036 CompilationUnit unit0 = units[0]; 3162 CompilationUnit unit0 = units[0];
3037 CompilationUnit unit1 = units[1]; 3163 CompilationUnit unit1 = units[1];
3038 CompilationUnit unit2 = units[2]; 3164 CompilationUnit unit2 = units[2];
3039 3165
3040 InterfaceType intType = context.typeProvider.intType; 3166 InterfaceType intType = context.typeProvider.intType;
3041 3167
3042 assertVariableDeclarationTypes( 3168 assertVariableDeclarationTypes(
3043 getFieldInClass(unit0, "A", "a1"), intType, intType); 3169 getFieldInClass(unit0, "A", "a1"), intType, intType);
3044 assertVariableDeclarationTypes( 3170 assertVariableDeclarationTypes(
3045 getFieldInClass(unit0, "A", "a2"), intType, intType); 3171 getFieldInClass(unit0, "A", "a2"), intType, intType);
3046 3172
3047 assertVariableDeclarationTypes( 3173 assertVariableDeclarationTypes(
3048 getFieldInClass(unit1, "B", "b1"), intType, intType); 3174 getFieldInClass(unit1, "B", "b1"), intType, intType);
3049 assertVariableDeclarationTypes( 3175 assertVariableDeclarationTypes(
3050 getFieldInClass(unit1, "B", "b2"), intType, intType); 3176 getFieldInClass(unit1, "B", "b2"), intType, intType);
3051 3177
3052 List<Statement> statements = 3178 List<Statement> statements =
3053 getStatementsInTopLevelFunction(unit2, "test1"); 3179 getStatementsInTopLevelFunction(unit2, "test1");
3054 3180
3055 assertAssignmentStatementTypes(statements[1], intType, intType); 3181 assertAssignmentStatementTypes(statements[1], intType, intType);
3056 assertAssignmentStatementTypes(statements[2], intType, intType); 3182 assertAssignmentStatementTypes(statements[2], intType, intType);
3057 } 3183 }
3184
3185 // Test inference between fields and method bodies
3186 void test_perform_inference_cross_unit_instance_member() {
3187 List<Source> sources = newSources({
3188 '/a.dart': '''
3189 import 'b.dart';
3190 var bar = new B();
3191 void foo() {
3192 String x = bar.f.z;
3193 }
3194 ''',
3195 '/b.dart': '''
3196 class C {
3197 var z = 3;
3198 }
3199
3200 class B {
3201 var f = new C();
3202 }
3203 ''',
3204 '/c.dart': '''
3205 import 'b.dart';
3206 var bar = new B();
3207 void foo() {
3208 String x = bar.f.z;
3209 }
3210 '''
3211 });
3212 List<dynamic> units =
3213 computeLibraryResults(sources, RESOLVED_UNIT9).toList();
3214 CompilationUnit unit0 = units[0];
3215 CompilationUnit unit1 = units[1];
3216 CompilationUnit unit2 = units[2];
3217
3218 InterfaceType intType = context.typeProvider.intType;
3219 InterfaceType stringType = context.typeProvider.stringType;
3220
3221 assertVariableDeclarationStatementTypes(
3222 getStatementsInTopLevelFunction(unit0, "foo")[0], stringType, intType);
3223 assertVariableDeclarationStatementTypes(
3224 getStatementsInTopLevelFunction(unit2, "foo")[0], stringType, intType);
3225 }
3058 } 3226 }
3059 3227
3060 @reflectiveTest 3228 @reflectiveTest
3061 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { 3229 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest {
3062 test_perform() { 3230 test_perform() {
3063 Source sourceLib = newSource( 3231 Source sourceLib = newSource(
3064 '/my_lib.dart', 3232 '/my_lib.dart',
3065 ''' 3233 '''
3066 library my_lib; 3234 library my_lib;
3067 part 'my_part.dart'; 3235 part 'my_part.dart';
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
3583 /** 3751 /**
3584 * Fill [errorListener] with [result] errors in the current [task]. 3752 * Fill [errorListener] with [result] errors in the current [task].
3585 */ 3753 */
3586 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 3754 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
3587 List<AnalysisError> errors = task.outputs[result]; 3755 List<AnalysisError> errors = task.outputs[result];
3588 expect(errors, isNotNull, reason: result.name); 3756 expect(errors, isNotNull, reason: result.name);
3589 errorListener = new GatheringErrorListener(); 3757 errorListener = new GatheringErrorListener();
3590 errorListener.addAll(errors); 3758 errorListener.addAll(errors);
3591 } 3759 }
3592 } 3760 }
OLDNEW
« pkg/analyzer/lib/src/task/dart.dart ('K') | « pkg/analyzer/test/src/context/context_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698