| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.resolver_test; | 5 library analyzer.test.generated.resolver_test; |
| 6 | 6 |
| 7 import 'dart:async'; |
| 7 import 'dart:collection'; | 8 import 'dart:collection'; |
| 8 | 9 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 11 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 11 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 12 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 12 import 'package:analyzer/dart/ast/token.dart'; | 13 import 'package:analyzer/dart/ast/token.dart'; |
| 13 import 'package:analyzer/dart/ast/visitor.dart'; | 14 import 'package:analyzer/dart/ast/visitor.dart'; |
| 14 import 'package:analyzer/dart/element/element.dart'; | 15 import 'package:analyzer/dart/element/element.dart'; |
| 15 import 'package:analyzer/dart/element/type.dart'; | 16 import 'package:analyzer/dart/element/type.dart'; |
| 16 import 'package:analyzer/file_system/memory_file_system.dart'; | 17 import 'package:analyzer/file_system/memory_file_system.dart'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 44 defineReflectiveTests(LibraryImportScopeTest); | 45 defineReflectiveTests(LibraryImportScopeTest); |
| 45 defineReflectiveTests(LibraryScopeTest); | 46 defineReflectiveTests(LibraryScopeTest); |
| 46 defineReflectiveTests(PrefixedNamespaceTest); | 47 defineReflectiveTests(PrefixedNamespaceTest); |
| 47 defineReflectiveTests(ScopeTest); | 48 defineReflectiveTests(ScopeTest); |
| 48 defineReflectiveTests(StrictModeTest); | 49 defineReflectiveTests(StrictModeTest); |
| 49 defineReflectiveTests(SubtypeManagerTest); | 50 defineReflectiveTests(SubtypeManagerTest); |
| 50 defineReflectiveTests(TypeOverrideManagerTest); | 51 defineReflectiveTests(TypeOverrideManagerTest); |
| 51 defineReflectiveTests(TypePropagationTest); | 52 defineReflectiveTests(TypePropagationTest); |
| 52 defineReflectiveTests(TypeProviderImplTest); | 53 defineReflectiveTests(TypeProviderImplTest); |
| 53 defineReflectiveTests(TypeResolverVisitorTest); | 54 defineReflectiveTests(TypeResolverVisitorTest); |
| 55 defineReflectiveTests(TypePropagationTest_Driver); |
| 54 }); | 56 }); |
| 55 } | 57 } |
| 56 | 58 |
| 57 @reflectiveTest | 59 @reflectiveTest |
| 58 class AnalysisDeltaTest extends EngineTestCase { | 60 class AnalysisDeltaTest extends EngineTestCase { |
| 59 TestSource source1 = new TestSource('/1.dart'); | 61 TestSource source1 = new TestSource('/1.dart'); |
| 60 TestSource source2 = new TestSource('/2.dart'); | 62 TestSource source2 = new TestSource('/2.dart'); |
| 61 TestSource source3 = new TestSource('/3.dart'); | 63 TestSource source3 = new TestSource('/3.dart'); |
| 62 | 64 |
| 63 void test_getAddedSources() { | 65 void test_getAddedSources() { |
| (...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 class A { | 1086 class A { |
| 1085 bool get g => true; | 1087 bool get g => true; |
| 1086 } | 1088 } |
| 1087 A f(var p) { | 1089 A f(var p) { |
| 1088 if ((p as A).g) { | 1090 if ((p as A).g) { |
| 1089 return p; | 1091 return p; |
| 1090 } else { | 1092 } else { |
| 1091 return null; | 1093 return null; |
| 1092 } | 1094 } |
| 1093 }'''); | 1095 }'''); |
| 1094 LibraryElement library = resolve2(source); | 1096 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1095 await computeAnalysisResult(source); | |
| 1096 assertNoErrors(source); | |
| 1097 verify([source]); | |
| 1098 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1099 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1097 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1100 InterfaceType typeA = | 1098 InterfaceType typeA = |
| 1101 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1099 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1102 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1100 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1103 BlockFunctionBody body = | 1101 BlockFunctionBody body = |
| 1104 function.functionExpression.body as BlockFunctionBody; | 1102 function.functionExpression.body as BlockFunctionBody; |
| 1105 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 1103 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 1106 ReturnStatement statement = | 1104 ReturnStatement statement = |
| 1107 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 1105 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 1108 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1106 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1109 expect(variableName.propagatedType, same(typeA)); | 1107 expect(variableName.propagatedType, same(typeA)); |
| 1110 } | 1108 } |
| 1111 | 1109 |
| 1112 test_assert() async { | 1110 test_assert() async { |
| 1113 Source source = addSource(r''' | 1111 Source source = addSource(r''' |
| 1114 class A {} | 1112 class A {} |
| 1115 A f(var p) { | 1113 A f(var p) { |
| 1116 assert (p is A); | 1114 assert (p is A); |
| 1117 return p; | 1115 return p; |
| 1118 }'''); | 1116 }'''); |
| 1119 LibraryElement library = resolve2(source); | 1117 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1120 await computeAnalysisResult(source); | |
| 1121 assertNoErrors(source); | |
| 1122 verify([source]); | |
| 1123 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1124 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1118 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1125 InterfaceType typeA = | 1119 InterfaceType typeA = |
| 1126 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1120 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1127 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1121 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1128 BlockFunctionBody body = | 1122 BlockFunctionBody body = |
| 1129 function.functionExpression.body as BlockFunctionBody; | 1123 function.functionExpression.body as BlockFunctionBody; |
| 1130 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 1124 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 1131 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1125 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1132 expect(variableName.propagatedType, same(typeA)); | 1126 expect(variableName.propagatedType, same(typeA)); |
| 1133 } | 1127 } |
| 1134 | 1128 |
| 1135 test_assignment() async { | 1129 test_assignment() async { |
| 1136 Source source = addSource(r''' | 1130 Source source = addSource(r''' |
| 1137 f() { | 1131 f() { |
| 1138 var v; | 1132 var v; |
| 1139 v = 0; | 1133 v = 0; |
| 1140 return v; | 1134 return v; |
| 1141 }'''); | 1135 }'''); |
| 1142 LibraryElement library = resolve2(source); | 1136 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1143 await computeAnalysisResult(source); | |
| 1144 assertNoErrors(source); | |
| 1145 verify([source]); | |
| 1146 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1147 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1137 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 1148 BlockFunctionBody body = | 1138 BlockFunctionBody body = |
| 1149 function.functionExpression.body as BlockFunctionBody; | 1139 function.functionExpression.body as BlockFunctionBody; |
| 1150 ReturnStatement statement = body.block.statements[2] as ReturnStatement; | 1140 ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| 1151 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1141 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1152 expect(variableName.propagatedType, same(typeProvider.intType)); | 1142 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 1153 } | 1143 } |
| 1154 | 1144 |
| 1155 test_assignment_afterInitializer() async { | 1145 test_assignment_afterInitializer() async { |
| 1156 Source source = addSource(r''' | 1146 Source source = addSource(r''' |
| 1157 f() { | 1147 f() { |
| 1158 var v = 0; | 1148 var v = 0; |
| 1159 v = 1.0; | 1149 v = 1.0; |
| 1160 return v; | 1150 return v; |
| 1161 }'''); | 1151 }'''); |
| 1162 LibraryElement library = resolve2(source); | 1152 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1163 await computeAnalysisResult(source); | |
| 1164 assertNoErrors(source); | |
| 1165 verify([source]); | |
| 1166 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1167 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1153 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 1168 BlockFunctionBody body = | 1154 BlockFunctionBody body = |
| 1169 function.functionExpression.body as BlockFunctionBody; | 1155 function.functionExpression.body as BlockFunctionBody; |
| 1170 ReturnStatement statement = body.block.statements[2] as ReturnStatement; | 1156 ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| 1171 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1157 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1172 expect(variableName.propagatedType, same(typeProvider.doubleType)); | 1158 expect(variableName.propagatedType, same(typeProvider.doubleType)); |
| 1173 } | 1159 } |
| 1174 | 1160 |
| 1175 test_assignment_null() async { | 1161 test_assignment_null() async { |
| 1176 String code = r''' | 1162 String code = r''' |
| 1177 main() { | 1163 main() { |
| 1178 int v; // declare | 1164 int v; // declare |
| 1179 v = null; | 1165 v = null; |
| 1180 return v; // return | 1166 return v; // return |
| 1181 }'''; | 1167 }'''; |
| 1182 CompilationUnit unit; | 1168 CompilationUnit unit; |
| 1183 { | 1169 { |
| 1184 Source source = addSource(code); | 1170 Source source = addSource(code); |
| 1185 LibraryElement library = resolve2(source); | 1171 TestAnalysisResult analysisResult = await computeAnalysisResult(source); |
| 1186 await computeAnalysisResult(source); | |
| 1187 assertNoErrors(source); | 1172 assertNoErrors(source); |
| 1188 verify([source]); | 1173 verify([source]); |
| 1189 unit = resolveCompilationUnit(source, library); | 1174 unit = analysisResult.unit; |
| 1190 } | 1175 } |
| 1191 { | 1176 { |
| 1192 SimpleIdentifier identifier = EngineTestCase.findNode( | 1177 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1193 unit, code, "v; // declare", (node) => node is SimpleIdentifier); | 1178 unit, code, "v; // declare", (node) => node is SimpleIdentifier); |
| 1194 expect(identifier.staticType, same(typeProvider.intType)); | 1179 expect(identifier.staticType, same(typeProvider.intType)); |
| 1195 expect(identifier.propagatedType, same(null)); | 1180 expect(identifier.propagatedType, same(null)); |
| 1196 } | 1181 } |
| 1197 { | 1182 { |
| 1198 SimpleIdentifier identifier = EngineTestCase.findNode( | 1183 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1199 unit, code, "v = null;", (node) => node is SimpleIdentifier); | 1184 unit, code, "v = null;", (node) => node is SimpleIdentifier); |
| 1200 expect(identifier.staticType, same(typeProvider.intType)); | 1185 expect(identifier.staticType, same(typeProvider.intType)); |
| 1201 expect(identifier.propagatedType, same(null)); | 1186 expect(identifier.propagatedType, same(null)); |
| 1202 } | 1187 } |
| 1203 { | 1188 { |
| 1204 SimpleIdentifier identifier = EngineTestCase.findNode( | 1189 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1205 unit, code, "v; // return", (node) => node is SimpleIdentifier); | 1190 unit, code, "v; // return", (node) => node is SimpleIdentifier); |
| 1206 expect(identifier.staticType, same(typeProvider.intType)); | 1191 expect(identifier.staticType, same(typeProvider.intType)); |
| 1207 expect(identifier.propagatedType, same(null)); | 1192 expect(identifier.propagatedType, same(null)); |
| 1208 } | 1193 } |
| 1209 } | 1194 } |
| 1210 | 1195 |
| 1211 test_CanvasElement_getContext() async { | 1196 test_CanvasElement_getContext() async { |
| 1212 String code = r''' | 1197 String code = r''' |
| 1213 import 'dart:html'; | 1198 import 'dart:html'; |
| 1214 main(CanvasElement canvas) { | 1199 main(CanvasElement canvas) { |
| 1215 var context = canvas.getContext('2d'); | 1200 var context = canvas.getContext('2d'); |
| 1216 }'''; | 1201 }'''; |
| 1217 Source source = addSource(code); | 1202 Source source = addSource(code); |
| 1218 LibraryElement library = resolve2(source); | 1203 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1219 await computeAnalysisResult(source); | |
| 1220 assertNoErrors(source); | |
| 1221 verify([source]); | |
| 1222 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1223 SimpleIdentifier identifier = EngineTestCase.findNode( | 1204 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1224 unit, code, "context", (node) => node is SimpleIdentifier); | 1205 unit, code, "context", (node) => node is SimpleIdentifier); |
| 1225 expect(resolutionMap.propagatedTypeForExpression(identifier).name, | 1206 expect(resolutionMap.propagatedTypeForExpression(identifier).name, |
| 1226 "CanvasRenderingContext2D"); | 1207 "CanvasRenderingContext2D"); |
| 1227 } | 1208 } |
| 1228 | 1209 |
| 1229 test_forEach() async { | 1210 test_forEach() async { |
| 1230 String code = r''' | 1211 String code = r''' |
| 1231 main() { | 1212 main() { |
| 1232 var list = <String> []; | 1213 var list = <String> []; |
| 1233 for (var e in list) { | 1214 for (var e in list) { |
| 1234 e; | 1215 e; |
| 1235 } | 1216 } |
| 1236 }'''; | 1217 }'''; |
| 1237 Source source = addSource(code); | 1218 Source source = addSource(code); |
| 1238 LibraryElement library = resolve2(source); | 1219 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1239 await computeAnalysisResult(source); | |
| 1240 assertNoErrors(source); | |
| 1241 verify([source]); | |
| 1242 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1243 InterfaceType stringType = typeProvider.stringType; | 1220 InterfaceType stringType = typeProvider.stringType; |
| 1244 // in the declaration | 1221 // in the declaration |
| 1245 { | 1222 { |
| 1246 SimpleIdentifier identifier = EngineTestCase.findNode( | 1223 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1247 unit, code, "e in", (node) => node is SimpleIdentifier); | 1224 unit, code, "e in", (node) => node is SimpleIdentifier); |
| 1248 expect(identifier.propagatedType, same(stringType)); | 1225 expect(identifier.propagatedType, same(stringType)); |
| 1249 } | 1226 } |
| 1250 // in the loop body | 1227 // in the loop body |
| 1251 { | 1228 { |
| 1252 SimpleIdentifier identifier = EngineTestCase.findNode( | 1229 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1253 unit, code, "e;", (node) => node is SimpleIdentifier); | 1230 unit, code, "e;", (node) => node is SimpleIdentifier); |
| 1254 expect(identifier.propagatedType, same(stringType)); | 1231 expect(identifier.propagatedType, same(stringType)); |
| 1255 } | 1232 } |
| 1256 } | 1233 } |
| 1257 | 1234 |
| 1258 test_forEach_async() async { | 1235 test_forEach_async() async { |
| 1259 String code = r''' | 1236 String code = r''' |
| 1260 import 'dart:async'; | 1237 import 'dart:async'; |
| 1261 f(Stream<String> stream) async { | 1238 f(Stream<String> stream) async { |
| 1262 await for (var e in stream) { | 1239 await for (var e in stream) { |
| 1263 e; | 1240 e; |
| 1264 } | 1241 } |
| 1265 }'''; | 1242 }'''; |
| 1266 Source source = addSource(code); | 1243 Source source = addSource(code); |
| 1267 LibraryElement library = resolve2(source); | 1244 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1268 await computeAnalysisResult(source); | |
| 1269 assertNoErrors(source); | |
| 1270 verify([source]); | |
| 1271 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1272 InterfaceType stringType = typeProvider.stringType; | 1245 InterfaceType stringType = typeProvider.stringType; |
| 1273 // in the declaration | 1246 // in the declaration |
| 1274 { | 1247 { |
| 1275 SimpleIdentifier identifier = EngineTestCase.findNode( | 1248 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1276 unit, code, "e in", (node) => node is SimpleIdentifier); | 1249 unit, code, "e in", (node) => node is SimpleIdentifier); |
| 1277 expect(identifier.propagatedType, same(stringType)); | 1250 expect(identifier.propagatedType, same(stringType)); |
| 1278 } | 1251 } |
| 1279 // in the loop body | 1252 // in the loop body |
| 1280 { | 1253 { |
| 1281 SimpleIdentifier identifier = EngineTestCase.findNode( | 1254 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1282 unit, code, "e;", (node) => node is SimpleIdentifier); | 1255 unit, code, "e;", (node) => node is SimpleIdentifier); |
| 1283 expect(identifier.propagatedType, same(stringType)); | 1256 expect(identifier.propagatedType, same(stringType)); |
| 1284 } | 1257 } |
| 1285 } | 1258 } |
| 1286 | 1259 |
| 1287 test_forEach_async_inheritedStream() async { | 1260 test_forEach_async_inheritedStream() async { |
| 1288 // From https://github.com/dart-lang/sdk/issues/24191, this ensures that | 1261 // From https://github.com/dart-lang/sdk/issues/24191, this ensures that |
| 1289 // `await for` works for types where the generic parameter doesn't | 1262 // `await for` works for types where the generic parameter doesn't |
| 1290 // correspond to the type of the Stream's data. | 1263 // correspond to the type of the Stream's data. |
| 1291 String code = r''' | 1264 String code = r''' |
| 1292 import 'dart:async'; | 1265 import 'dart:async'; |
| 1293 abstract class MyCustomStream<T> implements Stream<List<T>> {} | 1266 abstract class MyCustomStream<T> implements Stream<List<T>> {} |
| 1294 f(MyCustomStream<String> stream) async { | 1267 f(MyCustomStream<String> stream) async { |
| 1295 await for (var e in stream) { | 1268 await for (var e in stream) { |
| 1296 e; | 1269 e; |
| 1297 } | 1270 } |
| 1298 }'''; | 1271 }'''; |
| 1299 Source source = addSource(code); | 1272 Source source = addSource(code); |
| 1300 LibraryElement library = resolve2(source); | 1273 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1301 await computeAnalysisResult(source); | |
| 1302 assertNoErrors(source); | |
| 1303 verify([source]); | |
| 1304 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1305 InterfaceType listOfStringType = | 1274 InterfaceType listOfStringType = |
| 1306 typeProvider.listType.instantiate([typeProvider.stringType]); | 1275 typeProvider.listType.instantiate([typeProvider.stringType]); |
| 1307 // in the declaration | 1276 // in the declaration |
| 1308 { | 1277 { |
| 1309 SimpleIdentifier identifier = EngineTestCase.findNode( | 1278 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1310 unit, code, "e in", (node) => node is SimpleIdentifier); | 1279 unit, code, "e in", (node) => node is SimpleIdentifier); |
| 1311 expect(identifier.propagatedType, equals(listOfStringType)); | 1280 expect(identifier.propagatedType, equals(listOfStringType)); |
| 1312 } | 1281 } |
| 1313 // in the loop body | 1282 // in the loop body |
| 1314 { | 1283 { |
| 1315 SimpleIdentifier identifier = EngineTestCase.findNode( | 1284 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1316 unit, code, "e;", (node) => node is SimpleIdentifier); | 1285 unit, code, "e;", (node) => node is SimpleIdentifier); |
| 1317 expect(identifier.propagatedType, equals(listOfStringType)); | 1286 expect(identifier.propagatedType, equals(listOfStringType)); |
| 1318 } | 1287 } |
| 1319 } | 1288 } |
| 1320 | 1289 |
| 1321 test_functionExpression_asInvocationArgument() async { | 1290 test_functionExpression_asInvocationArgument() async { |
| 1322 String code = r''' | 1291 String code = r''' |
| 1323 class MyMap<K, V> { | 1292 class MyMap<K, V> { |
| 1324 forEach(f(K key, V value)) {} | 1293 forEach(f(K key, V value)) {} |
| 1325 } | 1294 } |
| 1326 f(MyMap<int, String> m) { | 1295 f(MyMap<int, String> m) { |
| 1327 m.forEach((k, v) { | 1296 m.forEach((k, v) { |
| 1328 k; | 1297 k; |
| 1329 v; | 1298 v; |
| 1330 }); | 1299 }); |
| 1331 }'''; | 1300 }'''; |
| 1332 Source source = addSource(code); | 1301 Source source = addSource(code); |
| 1333 LibraryElement library = resolve2(source); | 1302 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1334 await computeAnalysisResult(source); | |
| 1335 assertNoErrors(source); | |
| 1336 verify([source]); | |
| 1337 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1338 // k | 1303 // k |
| 1339 DartType intType = typeProvider.intType; | 1304 DartType intType = typeProvider.intType; |
| 1340 FormalParameter kParameter = EngineTestCase.findNode( | 1305 FormalParameter kParameter = EngineTestCase.findNode( |
| 1341 unit, code, "k, ", (node) => node is SimpleFormalParameter); | 1306 unit, code, "k, ", (node) => node is SimpleFormalParameter); |
| 1342 expect(kParameter.identifier.propagatedType, same(intType)); | 1307 expect(kParameter.identifier.propagatedType, same(intType)); |
| 1343 SimpleIdentifier kIdentifier = EngineTestCase.findNode( | 1308 SimpleIdentifier kIdentifier = EngineTestCase.findNode( |
| 1344 unit, code, "k;", (node) => node is SimpleIdentifier); | 1309 unit, code, "k;", (node) => node is SimpleIdentifier); |
| 1345 expect(kIdentifier.propagatedType, same(intType)); | 1310 expect(kIdentifier.propagatedType, same(intType)); |
| 1346 expect(kIdentifier.staticType, same(typeProvider.dynamicType)); | 1311 expect(kIdentifier.staticType, same(typeProvider.dynamicType)); |
| 1347 // v | 1312 // v |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1358 test_functionExpression_asInvocationArgument_fromInferredInvocation() async { | 1323 test_functionExpression_asInvocationArgument_fromInferredInvocation() async { |
| 1359 String code = r''' | 1324 String code = r''' |
| 1360 class MyMap<K, V> { | 1325 class MyMap<K, V> { |
| 1361 forEach(f(K key, V value)) {} | 1326 forEach(f(K key, V value)) {} |
| 1362 } | 1327 } |
| 1363 f(MyMap<int, String> m) { | 1328 f(MyMap<int, String> m) { |
| 1364 var m2 = m; | 1329 var m2 = m; |
| 1365 m2.forEach((k, v) {}); | 1330 m2.forEach((k, v) {}); |
| 1366 }'''; | 1331 }'''; |
| 1367 Source source = addSource(code); | 1332 Source source = addSource(code); |
| 1368 LibraryElement library = resolve2(source); | 1333 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1369 await computeAnalysisResult(source); | |
| 1370 assertNoErrors(source); | |
| 1371 verify([source]); | |
| 1372 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1373 // k | 1334 // k |
| 1374 DartType intType = typeProvider.intType; | 1335 DartType intType = typeProvider.intType; |
| 1375 FormalParameter kParameter = EngineTestCase.findNode( | 1336 FormalParameter kParameter = EngineTestCase.findNode( |
| 1376 unit, code, "k, ", (node) => node is SimpleFormalParameter); | 1337 unit, code, "k, ", (node) => node is SimpleFormalParameter); |
| 1377 expect(kParameter.identifier.propagatedType, same(intType)); | 1338 expect(kParameter.identifier.propagatedType, same(intType)); |
| 1378 // v | 1339 // v |
| 1379 DartType stringType = typeProvider.stringType; | 1340 DartType stringType = typeProvider.stringType; |
| 1380 FormalParameter vParameter = EngineTestCase.findNode( | 1341 FormalParameter vParameter = EngineTestCase.findNode( |
| 1381 unit, code, "v)", (node) => node is SimpleFormalParameter); | 1342 unit, code, "v)", (node) => node is SimpleFormalParameter); |
| 1382 expect(vParameter.identifier.propagatedType, same(stringType)); | 1343 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 1383 } | 1344 } |
| 1384 | 1345 |
| 1385 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as
ync { | 1346 test_functionExpression_asInvocationArgument_functionExpressionInvocation() as
ync { |
| 1386 String code = r''' | 1347 String code = r''' |
| 1387 main() { | 1348 main() { |
| 1388 (f(String value)) {} ((v) { | 1349 (f(String value)) {} ((v) { |
| 1389 v; | 1350 v; |
| 1390 }); | 1351 }); |
| 1391 }'''; | 1352 }'''; |
| 1392 Source source = addSource(code); | 1353 Source source = addSource(code); |
| 1393 LibraryElement library = resolve2(source); | 1354 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1394 await computeAnalysisResult(source); | |
| 1395 assertNoErrors(source); | |
| 1396 verify([source]); | |
| 1397 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1398 // v | 1355 // v |
| 1399 DartType dynamicType = typeProvider.dynamicType; | 1356 DartType dynamicType = typeProvider.dynamicType; |
| 1400 DartType stringType = typeProvider.stringType; | 1357 DartType stringType = typeProvider.stringType; |
| 1401 FormalParameter vParameter = EngineTestCase.findNode( | 1358 FormalParameter vParameter = EngineTestCase.findNode( |
| 1402 unit, code, "v)", (node) => node is FormalParameter); | 1359 unit, code, "v)", (node) => node is FormalParameter); |
| 1403 expect(vParameter.identifier.propagatedType, same(stringType)); | 1360 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 1404 expect(vParameter.identifier.staticType, same(dynamicType)); | 1361 expect(vParameter.identifier.staticType, same(dynamicType)); |
| 1405 SimpleIdentifier vIdentifier = EngineTestCase.findNode( | 1362 SimpleIdentifier vIdentifier = EngineTestCase.findNode( |
| 1406 unit, code, "v;", (node) => node is SimpleIdentifier); | 1363 unit, code, "v;", (node) => node is SimpleIdentifier); |
| 1407 expect(vIdentifier.propagatedType, same(stringType)); | 1364 expect(vIdentifier.propagatedType, same(stringType)); |
| 1408 expect(vIdentifier.staticType, same(dynamicType)); | 1365 expect(vIdentifier.staticType, same(dynamicType)); |
| 1409 } | 1366 } |
| 1410 | 1367 |
| 1411 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async { | 1368 test_functionExpression_asInvocationArgument_keepIfLessSpecific() async { |
| 1412 String code = r''' | 1369 String code = r''' |
| 1413 class MyList { | 1370 class MyList { |
| 1414 forEach(f(Object value)) {} | 1371 forEach(f(Object value)) {} |
| 1415 } | 1372 } |
| 1416 f(MyList list) { | 1373 f(MyList list) { |
| 1417 list.forEach((int v) { | 1374 list.forEach((int v) { |
| 1418 v; | 1375 v; |
| 1419 }); | 1376 }); |
| 1420 }'''; | 1377 }'''; |
| 1421 Source source = addSource(code); | 1378 Source source = addSource(code); |
| 1422 LibraryElement library = resolve2(source); | 1379 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1423 await computeAnalysisResult(source); | |
| 1424 assertNoErrors(source); | |
| 1425 verify([source]); | |
| 1426 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1427 // v | 1380 // v |
| 1428 DartType intType = typeProvider.intType; | 1381 DartType intType = typeProvider.intType; |
| 1429 FormalParameter vParameter = EngineTestCase.findNode( | 1382 FormalParameter vParameter = EngineTestCase.findNode( |
| 1430 unit, code, "v)", (node) => node is SimpleFormalParameter); | 1383 unit, code, "v)", (node) => node is SimpleFormalParameter); |
| 1431 expect(vParameter.identifier.propagatedType, same(null)); | 1384 expect(vParameter.identifier.propagatedType, same(null)); |
| 1432 expect(vParameter.identifier.staticType, same(intType)); | 1385 expect(vParameter.identifier.staticType, same(intType)); |
| 1433 SimpleIdentifier vIdentifier = EngineTestCase.findNode( | 1386 SimpleIdentifier vIdentifier = EngineTestCase.findNode( |
| 1434 unit, code, "v;", (node) => node is SimpleIdentifier); | 1387 unit, code, "v;", (node) => node is SimpleIdentifier); |
| 1435 expect(vIdentifier.staticType, same(intType)); | 1388 expect(vIdentifier.staticType, same(intType)); |
| 1436 expect(vIdentifier.propagatedType, same(null)); | 1389 expect(vIdentifier.propagatedType, same(null)); |
| 1437 } | 1390 } |
| 1438 | 1391 |
| 1439 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async { | 1392 test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() async { |
| 1440 String code = r''' | 1393 String code = r''' |
| 1441 class A { | 1394 class A { |
| 1442 m(void f(int i)) {} | 1395 m(void f(int i)) {} |
| 1443 } | 1396 } |
| 1444 x() { | 1397 x() { |
| 1445 A a = new A(); | 1398 A a = new A(); |
| 1446 a.m(() => 0); | 1399 a.m(() => 0); |
| 1447 }'''; | 1400 }'''; |
| 1448 Source source = addSource(code); | 1401 Source source = addSource(code); |
| 1449 LibraryElement library = resolve2(source); | 1402 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); |
| 1450 await computeAnalysisResult(source); | |
| 1451 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 1403 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 1452 verify([source]); | |
| 1453 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1454 // () => 0 | 1404 // () => 0 |
| 1455 FunctionExpression functionExpression = EngineTestCase.findNode( | 1405 FunctionExpression functionExpression = EngineTestCase.findNode( |
| 1456 unit, code, "() => 0)", (node) => node is FunctionExpression); | 1406 unit, code, "() => 0)", (node) => node is FunctionExpression); |
| 1457 expect((functionExpression.staticType as FunctionType).parameters.length, | 1407 expect((functionExpression.staticType as FunctionType).parameters.length, |
| 1458 same(0)); | 1408 same(0)); |
| 1459 expect(functionExpression.propagatedType, same(null)); | 1409 expect(functionExpression.propagatedType, same(null)); |
| 1460 } | 1410 } |
| 1461 | 1411 |
| 1462 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async { | 1412 test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() async { |
| 1463 String code = r''' | 1413 String code = r''' |
| 1464 class MyList<E> { | 1414 class MyList<E> { |
| 1465 forEach(f(E value)) {} | 1415 forEach(f(E value)) {} |
| 1466 } | 1416 } |
| 1467 f(MyList<String> list) { | 1417 f(MyList<String> list) { |
| 1468 list.forEach((Object v) { | 1418 list.forEach((Object v) { |
| 1469 v; | 1419 v; |
| 1470 }); | 1420 }); |
| 1471 }'''; | 1421 }'''; |
| 1472 Source source = addSource(code); | 1422 Source source = addSource(code); |
| 1473 LibraryElement library = resolve2(source); | 1423 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1474 await computeAnalysisResult(source); | |
| 1475 assertNoErrors(source); | |
| 1476 verify([source]); | |
| 1477 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1478 // v | 1424 // v |
| 1479 DartType stringType = typeProvider.stringType; | 1425 DartType stringType = typeProvider.stringType; |
| 1480 FormalParameter vParameter = EngineTestCase.findNode( | 1426 FormalParameter vParameter = EngineTestCase.findNode( |
| 1481 unit, code, "v)", (node) => node is SimpleFormalParameter); | 1427 unit, code, "v)", (node) => node is SimpleFormalParameter); |
| 1482 expect(vParameter.identifier.propagatedType, same(stringType)); | 1428 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 1483 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); | 1429 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); |
| 1484 SimpleIdentifier vIdentifier = EngineTestCase.findNode( | 1430 SimpleIdentifier vIdentifier = EngineTestCase.findNode( |
| 1485 unit, code, "v;", (node) => node is SimpleIdentifier); | 1431 unit, code, "v;", (node) => node is SimpleIdentifier); |
| 1486 expect(vIdentifier.propagatedType, same(stringType)); | 1432 expect(vIdentifier.propagatedType, same(stringType)); |
| 1487 } | 1433 } |
| 1488 | 1434 |
| 1489 test_Future_then() async { | 1435 test_Future_then() async { |
| 1490 String code = r''' | 1436 String code = r''' |
| 1491 import 'dart:async'; | 1437 import 'dart:async'; |
| 1492 main(Future<int> firstFuture) { | 1438 main(Future<int> firstFuture) { |
| 1493 firstFuture.then((p1) { | 1439 firstFuture.then((p1) { |
| 1494 return 1.0; | 1440 return 1.0; |
| 1495 }).then((p2) { | 1441 }).then((p2) { |
| 1496 return new Future<String>.value('str'); | 1442 return new Future<String>.value('str'); |
| 1497 }).then((p3) { | 1443 }).then((p3) { |
| 1498 }); | 1444 }); |
| 1499 }'''; | 1445 }'''; |
| 1500 Source source = addSource(code); | 1446 Source source = addSource(code); |
| 1501 LibraryElement library = resolve2(source); | 1447 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1502 await computeAnalysisResult(source); | |
| 1503 assertNoErrors(source); | |
| 1504 verify([source]); | |
| 1505 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1506 // p1 | 1448 // p1 |
| 1507 FormalParameter p1 = EngineTestCase.findNode( | 1449 FormalParameter p1 = EngineTestCase.findNode( |
| 1508 unit, code, "p1) {", (node) => node is SimpleFormalParameter); | 1450 unit, code, "p1) {", (node) => node is SimpleFormalParameter); |
| 1509 expect(p1.identifier.propagatedType, same(typeProvider.intType)); | 1451 expect(p1.identifier.propagatedType, same(typeProvider.intType)); |
| 1510 // p2 | 1452 // p2 |
| 1511 FormalParameter p2 = EngineTestCase.findNode( | 1453 FormalParameter p2 = EngineTestCase.findNode( |
| 1512 unit, code, "p2) {", (node) => node is SimpleFormalParameter); | 1454 unit, code, "p2) {", (node) => node is SimpleFormalParameter); |
| 1513 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); | 1455 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); |
| 1514 // p3 | 1456 // p3 |
| 1515 FormalParameter p3 = EngineTestCase.findNode( | 1457 FormalParameter p3 = EngineTestCase.findNode( |
| 1516 unit, code, "p3) {", (node) => node is SimpleFormalParameter); | 1458 unit, code, "p3) {", (node) => node is SimpleFormalParameter); |
| 1517 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); | 1459 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); |
| 1518 } | 1460 } |
| 1519 | 1461 |
| 1520 test_initializer() async { | 1462 test_initializer() async { |
| 1521 Source source = addSource(r''' | 1463 Source source = addSource(r''' |
| 1522 f() { | 1464 f() { |
| 1523 var v = 0; | 1465 var v = 0; |
| 1524 return v; | 1466 return v; |
| 1525 }'''); | 1467 }'''); |
| 1526 LibraryElement library = resolve2(source); | 1468 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1527 await computeAnalysisResult(source); | |
| 1528 assertNoErrors(source); | |
| 1529 verify([source]); | |
| 1530 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1531 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1469 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 1532 BlockFunctionBody body = | 1470 BlockFunctionBody body = |
| 1533 function.functionExpression.body as BlockFunctionBody; | 1471 function.functionExpression.body as BlockFunctionBody; |
| 1534 NodeList<Statement> statements = body.block.statements; | 1472 NodeList<Statement> statements = body.block.statements; |
| 1535 // Type of 'v' in declaration. | 1473 // Type of 'v' in declaration. |
| 1536 { | 1474 { |
| 1537 VariableDeclarationStatement statement = | 1475 VariableDeclarationStatement statement = |
| 1538 statements[0] as VariableDeclarationStatement; | 1476 statements[0] as VariableDeclarationStatement; |
| 1539 SimpleIdentifier variableName = statement.variables.variables[0].name; | 1477 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 1540 expect(variableName.staticType, same(typeProvider.dynamicType)); | 1478 expect(variableName.staticType, same(typeProvider.dynamicType)); |
| 1541 expect(variableName.propagatedType, same(typeProvider.intType)); | 1479 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 1542 } | 1480 } |
| 1543 // Type of 'v' in reference. | 1481 // Type of 'v' in reference. |
| 1544 { | 1482 { |
| 1545 ReturnStatement statement = statements[1] as ReturnStatement; | 1483 ReturnStatement statement = statements[1] as ReturnStatement; |
| 1546 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1484 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1547 expect(variableName.propagatedType, same(typeProvider.intType)); | 1485 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 1548 } | 1486 } |
| 1549 } | 1487 } |
| 1550 | 1488 |
| 1551 test_initializer_dereference() async { | 1489 test_initializer_dereference() async { |
| 1552 Source source = addSource(r''' | 1490 Source source = addSource(r''' |
| 1553 f() { | 1491 f() { |
| 1554 var v = 'String'; | 1492 var v = 'String'; |
| 1555 v. | 1493 v. |
| 1556 }'''); | 1494 }'''); |
| 1557 LibraryElement library = resolve2(source); | 1495 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); |
| 1558 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1559 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1496 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 1560 BlockFunctionBody body = | 1497 BlockFunctionBody body = |
| 1561 function.functionExpression.body as BlockFunctionBody; | 1498 function.functionExpression.body as BlockFunctionBody; |
| 1562 ExpressionStatement statement = | 1499 ExpressionStatement statement = |
| 1563 body.block.statements[1] as ExpressionStatement; | 1500 body.block.statements[1] as ExpressionStatement; |
| 1564 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; | 1501 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; |
| 1565 SimpleIdentifier variableName = invocation.prefix; | 1502 SimpleIdentifier variableName = invocation.prefix; |
| 1566 expect(variableName.propagatedType, same(typeProvider.stringType)); | 1503 expect(variableName.propagatedType, same(typeProvider.stringType)); |
| 1567 } | 1504 } |
| 1568 | 1505 |
| 1569 test_initializer_hasStaticType() async { | 1506 test_initializer_hasStaticType() async { |
| 1570 Source source = addSource(r''' | 1507 Source source = addSource(r''' |
| 1571 f() { | 1508 f() { |
| 1572 int v = 0; | 1509 int v = 0; |
| 1573 return v; | 1510 return v; |
| 1574 }'''); | 1511 }'''); |
| 1575 LibraryElement library = resolve2(source); | 1512 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1576 await computeAnalysisResult(source); | |
| 1577 assertNoErrors(source); | |
| 1578 verify([source]); | |
| 1579 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1580 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1513 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 1581 BlockFunctionBody body = | 1514 BlockFunctionBody body = |
| 1582 function.functionExpression.body as BlockFunctionBody; | 1515 function.functionExpression.body as BlockFunctionBody; |
| 1583 NodeList<Statement> statements = body.block.statements; | 1516 NodeList<Statement> statements = body.block.statements; |
| 1584 // Type of 'v' in declaration. | 1517 // Type of 'v' in declaration. |
| 1585 { | 1518 { |
| 1586 VariableDeclarationStatement statement = | 1519 VariableDeclarationStatement statement = |
| 1587 statements[0] as VariableDeclarationStatement; | 1520 statements[0] as VariableDeclarationStatement; |
| 1588 SimpleIdentifier variableName = statement.variables.variables[0].name; | 1521 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 1589 expect(variableName.staticType, same(typeProvider.intType)); | 1522 expect(variableName.staticType, same(typeProvider.intType)); |
| 1590 expect(variableName.propagatedType, isNull); | 1523 expect(variableName.propagatedType, isNull); |
| 1591 } | 1524 } |
| 1592 // Type of 'v' in reference. | 1525 // Type of 'v' in reference. |
| 1593 { | 1526 { |
| 1594 ReturnStatement statement = statements[1] as ReturnStatement; | 1527 ReturnStatement statement = statements[1] as ReturnStatement; |
| 1595 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1528 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1596 expect(variableName.staticType, same(typeProvider.intType)); | 1529 expect(variableName.staticType, same(typeProvider.intType)); |
| 1597 expect(variableName.propagatedType, isNull); | 1530 expect(variableName.propagatedType, isNull); |
| 1598 } | 1531 } |
| 1599 } | 1532 } |
| 1600 | 1533 |
| 1601 test_initializer_hasStaticType_parameterized() async { | 1534 test_initializer_hasStaticType_parameterized() async { |
| 1602 Source source = addSource(r''' | 1535 Source source = addSource(r''' |
| 1603 f() { | 1536 f() { |
| 1604 List<int> v = <int>[]; | 1537 List<int> v = <int>[]; |
| 1605 return v; | 1538 return v; |
| 1606 }'''); | 1539 }'''); |
| 1607 LibraryElement library = resolve2(source); | 1540 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1608 await computeAnalysisResult(source); | |
| 1609 assertNoErrors(source); | |
| 1610 verify([source]); | |
| 1611 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1612 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1541 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 1613 BlockFunctionBody body = | 1542 BlockFunctionBody body = |
| 1614 function.functionExpression.body as BlockFunctionBody; | 1543 function.functionExpression.body as BlockFunctionBody; |
| 1615 NodeList<Statement> statements = body.block.statements; | 1544 NodeList<Statement> statements = body.block.statements; |
| 1616 // Type of 'v' in declaration. | 1545 // Type of 'v' in declaration. |
| 1617 { | 1546 { |
| 1618 VariableDeclarationStatement statement = | 1547 VariableDeclarationStatement statement = |
| 1619 statements[0] as VariableDeclarationStatement; | 1548 statements[0] as VariableDeclarationStatement; |
| 1620 SimpleIdentifier variableName = statement.variables.variables[0].name; | 1549 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 1621 expect(variableName.staticType, isNotNull); | 1550 expect(variableName.staticType, isNotNull); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1632 | 1561 |
| 1633 test_initializer_null() async { | 1562 test_initializer_null() async { |
| 1634 String code = r''' | 1563 String code = r''' |
| 1635 main() { | 1564 main() { |
| 1636 int v = null; | 1565 int v = null; |
| 1637 return v; // marker | 1566 return v; // marker |
| 1638 }'''; | 1567 }'''; |
| 1639 CompilationUnit unit; | 1568 CompilationUnit unit; |
| 1640 { | 1569 { |
| 1641 Source source = addSource(code); | 1570 Source source = addSource(code); |
| 1642 LibraryElement library = resolve2(source); | 1571 unit = await _computeResolvedUnit(source); |
| 1643 await computeAnalysisResult(source); | |
| 1644 assertNoErrors(source); | |
| 1645 verify([source]); | |
| 1646 unit = resolveCompilationUnit(source, library); | |
| 1647 } | 1572 } |
| 1648 { | 1573 { |
| 1649 SimpleIdentifier identifier = EngineTestCase.findNode( | 1574 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1650 unit, code, "v = null;", (node) => node is SimpleIdentifier); | 1575 unit, code, "v = null;", (node) => node is SimpleIdentifier); |
| 1651 expect(identifier.staticType, same(typeProvider.intType)); | 1576 expect(identifier.staticType, same(typeProvider.intType)); |
| 1652 expect(identifier.propagatedType, same(null)); | 1577 expect(identifier.propagatedType, same(null)); |
| 1653 } | 1578 } |
| 1654 { | 1579 { |
| 1655 SimpleIdentifier identifier = EngineTestCase.findNode( | 1580 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 1656 unit, code, "v; // marker", (node) => node is SimpleIdentifier); | 1581 unit, code, "v; // marker", (node) => node is SimpleIdentifier); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1677 expect(methodInvoke.methodName.staticElement, isNotNull); | 1602 expect(methodInvoke.methodName.staticElement, isNotNull); |
| 1678 expect(methodInvoke.methodName.propagatedElement, isNull); | 1603 expect(methodInvoke.methodName.propagatedElement, isNull); |
| 1679 } | 1604 } |
| 1680 | 1605 |
| 1681 test_is_conditional() async { | 1606 test_is_conditional() async { |
| 1682 Source source = addSource(r''' | 1607 Source source = addSource(r''' |
| 1683 class A {} | 1608 class A {} |
| 1684 A f(var p) { | 1609 A f(var p) { |
| 1685 return (p is A) ? p : null; | 1610 return (p is A) ? p : null; |
| 1686 }'''); | 1611 }'''); |
| 1687 LibraryElement library = resolve2(source); | 1612 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1688 await computeAnalysisResult(source); | |
| 1689 assertNoErrors(source); | |
| 1690 verify([source]); | |
| 1691 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1692 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1613 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1693 InterfaceType typeA = | 1614 InterfaceType typeA = |
| 1694 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1615 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1695 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1616 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1696 BlockFunctionBody body = | 1617 BlockFunctionBody body = |
| 1697 function.functionExpression.body as BlockFunctionBody; | 1618 function.functionExpression.body as BlockFunctionBody; |
| 1698 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 1619 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 1699 ConditionalExpression conditional = | 1620 ConditionalExpression conditional = |
| 1700 statement.expression as ConditionalExpression; | 1621 statement.expression as ConditionalExpression; |
| 1701 SimpleIdentifier variableName = | 1622 SimpleIdentifier variableName = |
| 1702 conditional.thenExpression as SimpleIdentifier; | 1623 conditional.thenExpression as SimpleIdentifier; |
| 1703 expect(variableName.propagatedType, same(typeA)); | 1624 expect(variableName.propagatedType, same(typeA)); |
| 1704 } | 1625 } |
| 1705 | 1626 |
| 1706 test_is_if() async { | 1627 test_is_if() async { |
| 1707 Source source = addSource(r''' | 1628 Source source = addSource(r''' |
| 1708 class A {} | 1629 class A {} |
| 1709 A f(var p) { | 1630 A f(var p) { |
| 1710 if (p is A) { | 1631 if (p is A) { |
| 1711 return p; | 1632 return p; |
| 1712 } else { | 1633 } else { |
| 1713 return null; | 1634 return null; |
| 1714 } | 1635 } |
| 1715 }'''); | 1636 }'''); |
| 1716 LibraryElement library = resolve2(source); | 1637 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1717 await computeAnalysisResult(source); | |
| 1718 assertNoErrors(source); | |
| 1719 verify([source]); | |
| 1720 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1721 // prepare A | 1638 // prepare A |
| 1722 InterfaceType typeA; | 1639 InterfaceType typeA; |
| 1723 { | 1640 { |
| 1724 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1641 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1725 typeA = resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1642 typeA = resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1726 } | 1643 } |
| 1727 // verify "f" | 1644 // verify "f" |
| 1728 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1645 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1729 BlockFunctionBody body = | 1646 BlockFunctionBody body = |
| 1730 function.functionExpression.body as BlockFunctionBody; | 1647 function.functionExpression.body as BlockFunctionBody; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1747 test_is_if_lessSpecific() async { | 1664 test_is_if_lessSpecific() async { |
| 1748 Source source = addSource(r''' | 1665 Source source = addSource(r''' |
| 1749 class A {} | 1666 class A {} |
| 1750 A f(A p) { | 1667 A f(A p) { |
| 1751 if (p is String) { | 1668 if (p is String) { |
| 1752 return p; | 1669 return p; |
| 1753 } else { | 1670 } else { |
| 1754 return null; | 1671 return null; |
| 1755 } | 1672 } |
| 1756 }'''); | 1673 }'''); |
| 1757 LibraryElement library = resolve2(source); | 1674 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1758 await computeAnalysisResult(source); | |
| 1759 assertNoErrors(source); | |
| 1760 verify([source]); | |
| 1761 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1762 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().get(0)
; | |
| 1763 // InterfaceType typeA = classA.getElement().getType(); | |
| 1764 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1675 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1765 BlockFunctionBody body = | 1676 BlockFunctionBody body = |
| 1766 function.functionExpression.body as BlockFunctionBody; | 1677 function.functionExpression.body as BlockFunctionBody; |
| 1767 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 1678 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 1768 ReturnStatement statement = | 1679 ReturnStatement statement = |
| 1769 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 1680 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 1770 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1681 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1771 expect(variableName.propagatedType, same(null)); | 1682 expect(variableName.propagatedType, same(null)); |
| 1772 } | 1683 } |
| 1773 | 1684 |
| 1774 test_is_if_logicalAnd() async { | 1685 test_is_if_logicalAnd() async { |
| 1775 Source source = addSource(r''' | 1686 Source source = addSource(r''' |
| 1776 class A {} | 1687 class A {} |
| 1777 A f(var p) { | 1688 A f(var p) { |
| 1778 if (p is A && p != null) { | 1689 if (p is A && p != null) { |
| 1779 return p; | 1690 return p; |
| 1780 } else { | 1691 } else { |
| 1781 return null; | 1692 return null; |
| 1782 } | 1693 } |
| 1783 }'''); | 1694 }'''); |
| 1784 LibraryElement library = resolve2(source); | 1695 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1785 await computeAnalysisResult(source); | |
| 1786 assertNoErrors(source); | |
| 1787 verify([source]); | |
| 1788 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1789 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1696 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1790 InterfaceType typeA = | 1697 InterfaceType typeA = |
| 1791 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1698 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1792 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1699 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1793 BlockFunctionBody body = | 1700 BlockFunctionBody body = |
| 1794 function.functionExpression.body as BlockFunctionBody; | 1701 function.functionExpression.body as BlockFunctionBody; |
| 1795 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 1702 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 1796 ReturnStatement statement = | 1703 ReturnStatement statement = |
| 1797 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 1704 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 1798 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1705 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1799 expect(variableName.propagatedType, same(typeA)); | 1706 expect(variableName.propagatedType, same(typeA)); |
| 1800 } | 1707 } |
| 1801 | 1708 |
| 1802 test_is_postConditional() async { | 1709 test_is_postConditional() async { |
| 1803 Source source = addSource(r''' | 1710 Source source = addSource(r''' |
| 1804 class A {} | 1711 class A {} |
| 1805 A f(var p) { | 1712 A f(var p) { |
| 1806 A a = (p is A) ? p : throw null; | 1713 A a = (p is A) ? p : throw null; |
| 1807 return p; | 1714 return p; |
| 1808 }'''); | 1715 }'''); |
| 1809 LibraryElement library = resolve2(source); | 1716 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1810 await computeAnalysisResult(source); | |
| 1811 assertNoErrors(source); | |
| 1812 verify([source]); | |
| 1813 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1814 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1717 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1815 InterfaceType typeA = | 1718 InterfaceType typeA = |
| 1816 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1719 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1817 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1720 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1818 BlockFunctionBody body = | 1721 BlockFunctionBody body = |
| 1819 function.functionExpression.body as BlockFunctionBody; | 1722 function.functionExpression.body as BlockFunctionBody; |
| 1820 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 1723 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 1821 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1724 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1822 expect(variableName.propagatedType, same(typeA)); | 1725 expect(variableName.propagatedType, same(typeA)); |
| 1823 } | 1726 } |
| 1824 | 1727 |
| 1825 test_is_postIf() async { | 1728 test_is_postIf() async { |
| 1826 Source source = addSource(r''' | 1729 Source source = addSource(r''' |
| 1827 class A {} | 1730 class A {} |
| 1828 A f(var p) { | 1731 A f(var p) { |
| 1829 if (p is A) { | 1732 if (p is A) { |
| 1830 A a = p; | 1733 A a = p; |
| 1831 } else { | 1734 } else { |
| 1832 return null; | 1735 return null; |
| 1833 } | 1736 } |
| 1834 return p; | 1737 return p; |
| 1835 }'''); | 1738 }'''); |
| 1836 LibraryElement library = resolve2(source); | 1739 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1837 await computeAnalysisResult(source); | |
| 1838 assertNoErrors(source); | |
| 1839 verify([source]); | |
| 1840 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1841 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1740 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1842 InterfaceType typeA = | 1741 InterfaceType typeA = |
| 1843 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1742 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1844 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1743 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1845 BlockFunctionBody body = | 1744 BlockFunctionBody body = |
| 1846 function.functionExpression.body as BlockFunctionBody; | 1745 function.functionExpression.body as BlockFunctionBody; |
| 1847 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 1746 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 1848 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1747 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1849 expect(variableName.propagatedType, same(typeA)); | 1748 expect(variableName.propagatedType, same(typeA)); |
| 1850 } | 1749 } |
| 1851 | 1750 |
| 1852 test_is_subclass() async { | 1751 test_is_subclass() async { |
| 1853 Source source = addSource(r''' | 1752 Source source = addSource(r''' |
| 1854 class A {} | 1753 class A {} |
| 1855 class B extends A { | 1754 class B extends A { |
| 1856 B m() => this; | 1755 B m() => this; |
| 1857 } | 1756 } |
| 1858 A f(A p) { | 1757 A f(A p) { |
| 1859 if (p is B) { | 1758 if (p is B) { |
| 1860 return p.m(); | 1759 return p.m(); |
| 1861 } | 1760 } |
| 1862 return p; | 1761 return p; |
| 1863 }'''); | 1762 }'''); |
| 1864 LibraryElement library = resolve2(source); | 1763 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1865 await computeAnalysisResult(source); | |
| 1866 assertNoErrors(source); | |
| 1867 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1868 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; | 1764 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; |
| 1869 BlockFunctionBody body = | 1765 BlockFunctionBody body = |
| 1870 function.functionExpression.body as BlockFunctionBody; | 1766 function.functionExpression.body as BlockFunctionBody; |
| 1871 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 1767 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 1872 ReturnStatement statement = | 1768 ReturnStatement statement = |
| 1873 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; | 1769 (ifStatement.thenStatement as Block).statements[0] as ReturnStatement; |
| 1874 MethodInvocation invocation = statement.expression as MethodInvocation; | 1770 MethodInvocation invocation = statement.expression as MethodInvocation; |
| 1875 expect(invocation.methodName.staticElement, isNotNull); | 1771 expect(invocation.methodName.staticElement, isNotNull); |
| 1876 expect(invocation.methodName.propagatedElement, isNull); | 1772 expect(invocation.methodName.propagatedElement, isNull); |
| 1877 } | 1773 } |
| 1878 | 1774 |
| 1879 test_is_while() async { | 1775 test_is_while() async { |
| 1880 Source source = addSource(r''' | 1776 Source source = addSource(r''' |
| 1881 class A {} | 1777 class A {} |
| 1882 A f(var p) { | 1778 A f(var p) { |
| 1883 while (p is A) { | 1779 while (p is A) { |
| 1884 return p; | 1780 return p; |
| 1885 } | 1781 } |
| 1886 return p; | 1782 return p; |
| 1887 }'''); | 1783 }'''); |
| 1888 LibraryElement library = resolve2(source); | 1784 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1889 await computeAnalysisResult(source); | |
| 1890 assertNoErrors(source); | |
| 1891 verify([source]); | |
| 1892 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1893 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1785 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1894 InterfaceType typeA = | 1786 InterfaceType typeA = |
| 1895 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1787 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1896 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1788 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1897 BlockFunctionBody body = | 1789 BlockFunctionBody body = |
| 1898 function.functionExpression.body as BlockFunctionBody; | 1790 function.functionExpression.body as BlockFunctionBody; |
| 1899 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; | 1791 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; |
| 1900 ReturnStatement statement = | 1792 ReturnStatement statement = |
| 1901 (whileStatement.body as Block).statements[0] as ReturnStatement; | 1793 (whileStatement.body as Block).statements[0] as ReturnStatement; |
| 1902 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1794 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1903 expect(variableName.propagatedType, same(typeA)); | 1795 expect(variableName.propagatedType, same(typeA)); |
| 1904 } | 1796 } |
| 1905 | 1797 |
| 1906 test_isNot_conditional() async { | 1798 test_isNot_conditional() async { |
| 1907 Source source = addSource(r''' | 1799 Source source = addSource(r''' |
| 1908 class A {} | 1800 class A {} |
| 1909 A f(var p) { | 1801 A f(var p) { |
| 1910 return (p is! A) ? null : p; | 1802 return (p is! A) ? null : p; |
| 1911 }'''); | 1803 }'''); |
| 1912 LibraryElement library = resolve2(source); | 1804 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1913 await computeAnalysisResult(source); | |
| 1914 assertNoErrors(source); | |
| 1915 verify([source]); | |
| 1916 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1917 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1805 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1918 InterfaceType typeA = | 1806 InterfaceType typeA = |
| 1919 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1807 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1920 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1808 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1921 BlockFunctionBody body = | 1809 BlockFunctionBody body = |
| 1922 function.functionExpression.body as BlockFunctionBody; | 1810 function.functionExpression.body as BlockFunctionBody; |
| 1923 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 1811 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 1924 ConditionalExpression conditional = | 1812 ConditionalExpression conditional = |
| 1925 statement.expression as ConditionalExpression; | 1813 statement.expression as ConditionalExpression; |
| 1926 SimpleIdentifier variableName = | 1814 SimpleIdentifier variableName = |
| 1927 conditional.elseExpression as SimpleIdentifier; | 1815 conditional.elseExpression as SimpleIdentifier; |
| 1928 expect(variableName.propagatedType, same(typeA)); | 1816 expect(variableName.propagatedType, same(typeA)); |
| 1929 } | 1817 } |
| 1930 | 1818 |
| 1931 test_isNot_if() async { | 1819 test_isNot_if() async { |
| 1932 Source source = addSource(r''' | 1820 Source source = addSource(r''' |
| 1933 class A {} | 1821 class A {} |
| 1934 A f(var p) { | 1822 A f(var p) { |
| 1935 if (p is! A) { | 1823 if (p is! A) { |
| 1936 return null; | 1824 return null; |
| 1937 } else { | 1825 } else { |
| 1938 return p; | 1826 return p; |
| 1939 } | 1827 } |
| 1940 }'''); | 1828 }'''); |
| 1941 LibraryElement library = resolve2(source); | 1829 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1942 await computeAnalysisResult(source); | |
| 1943 assertNoErrors(source); | |
| 1944 verify([source]); | |
| 1945 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1946 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1830 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1947 InterfaceType typeA = | 1831 InterfaceType typeA = |
| 1948 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1832 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1949 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1833 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1950 BlockFunctionBody body = | 1834 BlockFunctionBody body = |
| 1951 function.functionExpression.body as BlockFunctionBody; | 1835 function.functionExpression.body as BlockFunctionBody; |
| 1952 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 1836 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 1953 ReturnStatement statement = | 1837 ReturnStatement statement = |
| 1954 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; | 1838 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; |
| 1955 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1839 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1956 expect(variableName.propagatedType, same(typeA)); | 1840 expect(variableName.propagatedType, same(typeA)); |
| 1957 } | 1841 } |
| 1958 | 1842 |
| 1959 test_isNot_if_logicalOr() async { | 1843 test_isNot_if_logicalOr() async { |
| 1960 Source source = addSource(r''' | 1844 Source source = addSource(r''' |
| 1961 class A {} | 1845 class A {} |
| 1962 A f(var p) { | 1846 A f(var p) { |
| 1963 if (p is! A || null == p) { | 1847 if (p is! A || null == p) { |
| 1964 return null; | 1848 return null; |
| 1965 } else { | 1849 } else { |
| 1966 return p; | 1850 return p; |
| 1967 } | 1851 } |
| 1968 }'''); | 1852 }'''); |
| 1969 LibraryElement library = resolve2(source); | 1853 CompilationUnit unit = await _computeResolvedUnit(source, noErrors: false); |
| 1970 await computeAnalysisResult(source); | |
| 1971 assertNoErrors(source); | |
| 1972 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1973 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1854 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1974 InterfaceType typeA = | 1855 InterfaceType typeA = |
| 1975 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1856 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 1976 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1857 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 1977 BlockFunctionBody body = | 1858 BlockFunctionBody body = |
| 1978 function.functionExpression.body as BlockFunctionBody; | 1859 function.functionExpression.body as BlockFunctionBody; |
| 1979 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 1860 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 1980 ReturnStatement statement = | 1861 ReturnStatement statement = |
| 1981 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; | 1862 (ifStatement.elseStatement as Block).statements[0] as ReturnStatement; |
| 1982 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1863 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 1983 expect(variableName.propagatedType, same(typeA)); | 1864 expect(variableName.propagatedType, same(typeA)); |
| 1984 } | 1865 } |
| 1985 | 1866 |
| 1986 test_isNot_postConditional() async { | 1867 test_isNot_postConditional() async { |
| 1987 Source source = addSource(r''' | 1868 Source source = addSource(r''' |
| 1988 class A {} | 1869 class A {} |
| 1989 A f(var p) { | 1870 A f(var p) { |
| 1990 A a = (p is! A) ? throw null : p; | 1871 A a = (p is! A) ? throw null : p; |
| 1991 return p; | 1872 return p; |
| 1992 }'''); | 1873 }'''); |
| 1993 LibraryElement library = resolve2(source); | 1874 CompilationUnit unit = await _computeResolvedUnit(source); |
| 1994 await computeAnalysisResult(source); | |
| 1995 assertNoErrors(source); | |
| 1996 verify([source]); | |
| 1997 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 1998 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1875 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 1999 InterfaceType typeA = | 1876 InterfaceType typeA = |
| 2000 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1877 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 2001 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1878 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 2002 BlockFunctionBody body = | 1879 BlockFunctionBody body = |
| 2003 function.functionExpression.body as BlockFunctionBody; | 1880 function.functionExpression.body as BlockFunctionBody; |
| 2004 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 1881 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 2005 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1882 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 2006 expect(variableName.propagatedType, same(typeA)); | 1883 expect(variableName.propagatedType, same(typeA)); |
| 2007 } | 1884 } |
| 2008 | 1885 |
| 2009 test_isNot_postIf() async { | 1886 test_isNot_postIf() async { |
| 2010 Source source = addSource(r''' | 1887 Source source = addSource(r''' |
| 2011 class A {} | 1888 class A {} |
| 2012 A f(var p) { | 1889 A f(var p) { |
| 2013 if (p is! A) { | 1890 if (p is! A) { |
| 2014 return null; | 1891 return null; |
| 2015 } | 1892 } |
| 2016 return p; | 1893 return p; |
| 2017 }'''); | 1894 }'''); |
| 2018 LibraryElement library = resolve2(source); | 1895 CompilationUnit unit = await _computeResolvedUnit(source); |
| 2019 await computeAnalysisResult(source); | |
| 2020 assertNoErrors(source); | |
| 2021 verify([source]); | |
| 2022 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 2023 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 1896 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 2024 InterfaceType typeA = | 1897 InterfaceType typeA = |
| 2025 resolutionMap.elementDeclaredByClassDeclaration(classA).type; | 1898 resolutionMap.elementDeclaredByClassDeclaration(classA).type; |
| 2026 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 1899 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 2027 BlockFunctionBody body = | 1900 BlockFunctionBody body = |
| 2028 function.functionExpression.body as BlockFunctionBody; | 1901 function.functionExpression.body as BlockFunctionBody; |
| 2029 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 1902 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 2030 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 1903 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 2031 expect(variableName.propagatedType, same(typeA)); | 1904 expect(variableName.propagatedType, same(typeA)); |
| 2032 } | 1905 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2084 DartType tB = (await findMarkedIdentifier(code, "; // B")).propagatedType; | 1957 DartType tB = (await findMarkedIdentifier(code, "; // B")).propagatedType; |
| 2085 await assertTypeOfMarkedExpression(code, null, tB); | 1958 await assertTypeOfMarkedExpression(code, null, tB); |
| 2086 } | 1959 } |
| 2087 | 1960 |
| 2088 test_listLiteral_different() async { | 1961 test_listLiteral_different() async { |
| 2089 Source source = addSource(r''' | 1962 Source source = addSource(r''' |
| 2090 f() { | 1963 f() { |
| 2091 var v = [0, '1', 2]; | 1964 var v = [0, '1', 2]; |
| 2092 return v[2]; | 1965 return v[2]; |
| 2093 }'''); | 1966 }'''); |
| 2094 LibraryElement library = resolve2(source); | 1967 CompilationUnit unit = await _computeResolvedUnit(source); |
| 2095 await computeAnalysisResult(source); | |
| 2096 assertNoErrors(source); | |
| 2097 verify([source]); | |
| 2098 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 2099 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1968 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 2100 BlockFunctionBody body = | 1969 BlockFunctionBody body = |
| 2101 function.functionExpression.body as BlockFunctionBody; | 1970 function.functionExpression.body as BlockFunctionBody; |
| 2102 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 1971 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 2103 IndexExpression indexExpression = statement.expression as IndexExpression; | 1972 IndexExpression indexExpression = statement.expression as IndexExpression; |
| 2104 expect(indexExpression.propagatedType, isNull); | 1973 expect(indexExpression.propagatedType, isNull); |
| 2105 } | 1974 } |
| 2106 | 1975 |
| 2107 test_listLiteral_same() async { | 1976 test_listLiteral_same() async { |
| 2108 Source source = addSource(r''' | 1977 Source source = addSource(r''' |
| 2109 f() { | 1978 f() { |
| 2110 var v = [0, 1, 2]; | 1979 var v = [0, 1, 2]; |
| 2111 return v[2]; | 1980 return v[2]; |
| 2112 }'''); | 1981 }'''); |
| 2113 LibraryElement library = resolve2(source); | 1982 CompilationUnit unit = await _computeResolvedUnit(source); |
| 2114 await computeAnalysisResult(source); | |
| 2115 assertNoErrors(source); | |
| 2116 verify([source]); | |
| 2117 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 2118 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 1983 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 2119 BlockFunctionBody body = | 1984 BlockFunctionBody body = |
| 2120 function.functionExpression.body as BlockFunctionBody; | 1985 function.functionExpression.body as BlockFunctionBody; |
| 2121 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 1986 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 2122 IndexExpression indexExpression = statement.expression as IndexExpression; | 1987 IndexExpression indexExpression = statement.expression as IndexExpression; |
| 2123 expect(indexExpression.propagatedType, isNull); | 1988 expect(indexExpression.propagatedType, isNull); |
| 2124 Expression v = indexExpression.target; | 1989 Expression v = indexExpression.target; |
| 2125 InterfaceType propagatedType = v.propagatedType as InterfaceType; | 1990 InterfaceType propagatedType = v.propagatedType as InterfaceType; |
| 2126 expect(propagatedType.element, same(typeProvider.listType.element)); | 1991 expect(propagatedType.element, same(typeProvider.listType.element)); |
| 2127 List<DartType> typeArguments = propagatedType.typeArguments; | 1992 List<DartType> typeArguments = propagatedType.typeArguments; |
| 2128 expect(typeArguments, hasLength(1)); | 1993 expect(typeArguments, hasLength(1)); |
| 2129 expect(typeArguments[0], same(typeProvider.dynamicType)); | 1994 expect(typeArguments[0], same(typeProvider.dynamicType)); |
| 2130 } | 1995 } |
| 2131 | 1996 |
| 2132 test_mapLiteral_different() async { | 1997 test_mapLiteral_different() async { |
| 2133 Source source = addSource(r''' | 1998 Source source = addSource(r''' |
| 2134 f() { | 1999 f() { |
| 2135 var v = {'0' : 0, 1 : '1', '2' : 2}; | 2000 var v = {'0' : 0, 1 : '1', '2' : 2}; |
| 2136 return v; | 2001 return v; |
| 2137 }'''); | 2002 }'''); |
| 2138 LibraryElement library = resolve2(source); | 2003 CompilationUnit unit = await _computeResolvedUnit(source); |
| 2139 await computeAnalysisResult(source); | |
| 2140 assertNoErrors(source); | |
| 2141 verify([source]); | |
| 2142 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 2143 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 2004 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 2144 BlockFunctionBody body = | 2005 BlockFunctionBody body = |
| 2145 function.functionExpression.body as BlockFunctionBody; | 2006 function.functionExpression.body as BlockFunctionBody; |
| 2146 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 2007 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 2147 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | 2008 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 2148 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; | 2009 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| 2149 expect(propagatedType.element, same(typeProvider.mapType.element)); | 2010 expect(propagatedType.element, same(typeProvider.mapType.element)); |
| 2150 List<DartType> typeArguments = propagatedType.typeArguments; | 2011 List<DartType> typeArguments = propagatedType.typeArguments; |
| 2151 expect(typeArguments, hasLength(2)); | 2012 expect(typeArguments, hasLength(2)); |
| 2152 expect(typeArguments[0], same(typeProvider.dynamicType)); | 2013 expect(typeArguments[0], same(typeProvider.dynamicType)); |
| 2153 expect(typeArguments[1], same(typeProvider.dynamicType)); | 2014 expect(typeArguments[1], same(typeProvider.dynamicType)); |
| 2154 } | 2015 } |
| 2155 | 2016 |
| 2156 test_mapLiteral_same() async { | 2017 test_mapLiteral_same() async { |
| 2157 Source source = addSource(r''' | 2018 Source source = addSource(r''' |
| 2158 f() { | 2019 f() { |
| 2159 var v = {'a' : 0, 'b' : 1, 'c' : 2}; | 2020 var v = {'a' : 0, 'b' : 1, 'c' : 2}; |
| 2160 return v; | 2021 return v; |
| 2161 }'''); | 2022 }'''); |
| 2162 LibraryElement library = resolve2(source); | 2023 CompilationUnit unit = await _computeResolvedUnit(source); |
| 2163 await computeAnalysisResult(source); | |
| 2164 assertNoErrors(source); | |
| 2165 verify([source]); | |
| 2166 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 2167 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 2024 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 2168 BlockFunctionBody body = | 2025 BlockFunctionBody body = |
| 2169 function.functionExpression.body as BlockFunctionBody; | 2026 function.functionExpression.body as BlockFunctionBody; |
| 2170 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 2027 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 2171 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | 2028 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 2172 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; | 2029 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| 2173 expect(propagatedType.element, same(typeProvider.mapType.element)); | 2030 expect(propagatedType.element, same(typeProvider.mapType.element)); |
| 2174 List<DartType> typeArguments = propagatedType.typeArguments; | 2031 List<DartType> typeArguments = propagatedType.typeArguments; |
| 2175 expect(typeArguments, hasLength(2)); | 2032 expect(typeArguments, hasLength(2)); |
| 2176 expect(typeArguments[0], same(typeProvider.dynamicType)); | 2033 expect(typeArguments[0], same(typeProvider.dynamicType)); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2464 var v6 = query('input#id'); | 2321 var v6 = query('input#id'); |
| 2465 var v7 = query('select#id'); | 2322 var v7 = query('select#id'); |
| 2466 // invocation of method | 2323 // invocation of method |
| 2467 var m1 = document.query('div'); | 2324 var m1 = document.query('div'); |
| 2468 // unsupported currently | 2325 // unsupported currently |
| 2469 var b1 = query('noSuchTag'); | 2326 var b1 = query('noSuchTag'); |
| 2470 var b2 = query('DART_EDITOR_NO_SUCH_TYPE'); | 2327 var b2 = query('DART_EDITOR_NO_SUCH_TYPE'); |
| 2471 var b3 = query('body div'); | 2328 var b3 = query('body div'); |
| 2472 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; | 2329 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; |
| 2473 }'''); | 2330 }'''); |
| 2474 LibraryElement library = resolve2(source); | 2331 CompilationUnit unit = await _computeResolvedUnit(source); |
| 2475 await computeAnalysisResult(source); | |
| 2476 assertNoErrors(source); | |
| 2477 verify([source]); | |
| 2478 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 2479 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; | 2332 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; |
| 2480 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; | 2333 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; |
| 2481 ReturnStatement statement = body.block.statements[11] as ReturnStatement; | 2334 ReturnStatement statement = body.block.statements[11] as ReturnStatement; |
| 2482 NodeList<Expression> elements = | 2335 NodeList<Expression> elements = |
| 2483 (statement.expression as ListLiteral).elements; | 2336 (statement.expression as ListLiteral).elements; |
| 2484 expect(resolutionMap.propagatedTypeForExpression(elements[0]).name, | 2337 expect(resolutionMap.propagatedTypeForExpression(elements[0]).name, |
| 2485 "AnchorElement"); | 2338 "AnchorElement"); |
| 2486 expect(resolutionMap.propagatedTypeForExpression(elements[1]).name, | 2339 expect(resolutionMap.propagatedTypeForExpression(elements[1]).name, |
| 2487 "AnchorElement"); | 2340 "AnchorElement"); |
| 2488 expect(resolutionMap.propagatedTypeForExpression(elements[2]).name, | 2341 expect(resolutionMap.propagatedTypeForExpression(elements[2]).name, |
| 2489 "BodyElement"); | 2342 "BodyElement"); |
| 2490 expect(resolutionMap.propagatedTypeForExpression(elements[3]).name, | 2343 expect(resolutionMap.propagatedTypeForExpression(elements[3]).name, |
| 2491 "ButtonElement"); | 2344 "ButtonElement"); |
| 2492 expect(resolutionMap.propagatedTypeForExpression(elements[4]).name, | 2345 expect(resolutionMap.propagatedTypeForExpression(elements[4]).name, |
| 2493 "DivElement"); | 2346 "DivElement"); |
| 2494 expect(resolutionMap.propagatedTypeForExpression(elements[5]).name, | 2347 expect(resolutionMap.propagatedTypeForExpression(elements[5]).name, |
| 2495 "InputElement"); | 2348 "InputElement"); |
| 2496 expect(resolutionMap.propagatedTypeForExpression(elements[6]).name, | 2349 expect(resolutionMap.propagatedTypeForExpression(elements[6]).name, |
| 2497 "SelectElement"); | 2350 "SelectElement"); |
| 2498 expect(resolutionMap.propagatedTypeForExpression(elements[7]).name, | 2351 expect(resolutionMap.propagatedTypeForExpression(elements[7]).name, |
| 2499 "DivElement"); | 2352 "DivElement"); |
| 2500 expect( | 2353 expect( |
| 2501 resolutionMap.propagatedTypeForExpression(elements[8]).name, "Element"); | 2354 resolutionMap.propagatedTypeForExpression(elements[8]).name, "Element"); |
| 2502 expect( | 2355 expect( |
| 2503 resolutionMap.propagatedTypeForExpression(elements[9]).name, "Element"); | 2356 resolutionMap.propagatedTypeForExpression(elements[9]).name, "Element"); |
| 2504 expect(resolutionMap.propagatedTypeForExpression(elements[10]).name, | 2357 expect(resolutionMap.propagatedTypeForExpression(elements[10]).name, |
| 2505 "Element"); | 2358 "Element"); |
| 2506 } | 2359 } |
| 2360 |
| 2361 /** |
| 2362 * Return the resolved unit for the given [source]. |
| 2363 * |
| 2364 * If [noErrors] is not specified or is not `true`, [assertNoErrors]. |
| 2365 */ |
| 2366 Future<CompilationUnit> _computeResolvedUnit(Source source, |
| 2367 {bool noErrors: true}) async { |
| 2368 TestAnalysisResult analysisResult = await computeAnalysisResult(source); |
| 2369 if (noErrors) { |
| 2370 assertNoErrors(source); |
| 2371 verify([source]); |
| 2372 } |
| 2373 return analysisResult.unit; |
| 2374 } |
| 2507 } | 2375 } |
| 2508 | 2376 |
| 2509 @reflectiveTest | 2377 @reflectiveTest |
| 2378 class TypePropagationTest_Driver extends TypePropagationTest { |
| 2379 @override |
| 2380 bool get enableNewAnalysisDriver => true; |
| 2381 |
| 2382 @failingTest |
| 2383 @override |
| 2384 test_query() { |
| 2385 return super.test_query(); |
| 2386 } |
| 2387 } |
| 2388 |
| 2389 @reflectiveTest |
| 2510 class TypeProviderImplTest extends EngineTestCase { | 2390 class TypeProviderImplTest extends EngineTestCase { |
| 2511 void test_creation() { | 2391 void test_creation() { |
| 2512 // | 2392 // |
| 2513 // Create a mock library element with the types expected to be in dart:core. | 2393 // Create a mock library element with the types expected to be in dart:core. |
| 2514 // We cannot use either ElementFactory or TestTypeProvider (which uses | 2394 // We cannot use either ElementFactory or TestTypeProvider (which uses |
| 2515 // ElementFactory) because we side-effect the elements in ways that would | 2395 // ElementFactory) because we side-effect the elements in ways that would |
| 2516 // break other tests. | 2396 // break other tests. |
| 2517 // | 2397 // |
| 2518 InterfaceType objectType = _classElement("Object", null).type; | 2398 InterfaceType objectType = _classElement("Object", null).type; |
| 2519 InterfaceType boolType = _classElement("bool", objectType).type; | 2399 InterfaceType boolType = _classElement("bool", objectType).type; |
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3710 */ | 3590 */ |
| 3711 class _StaleElement extends ElementImpl { | 3591 class _StaleElement extends ElementImpl { |
| 3712 _StaleElement() : super("_StaleElement", -1); | 3592 _StaleElement() : super("_StaleElement", -1); |
| 3713 | 3593 |
| 3714 @override | 3594 @override |
| 3715 get kind => throw "_StaleElement's kind shouldn't be accessed"; | 3595 get kind => throw "_StaleElement's kind shouldn't be accessed"; |
| 3716 | 3596 |
| 3717 @override | 3597 @override |
| 3718 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; | 3598 /*=T*/ accept/*<T>*/(_) => throw "_StaleElement shouldn't be visited"; |
| 3719 } | 3599 } |
| OLD | NEW |