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