| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.strong_mode_test; | 5 library analyzer.test.generated.strong_mode_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/dart/element/type.dart'; | 12 import 'package:analyzer/dart/element/type.dart'; |
| 13 import 'package:analyzer/src/dart/element/element.dart'; | 13 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/error/codes.dart'; | 14 import 'package:analyzer/src/error/codes.dart'; |
| 15 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 16 import 'package:analyzer/src/generated/source_io.dart'; | 16 import 'package:analyzer/src/generated/source_io.dart'; |
| 17 import 'package:test/test.dart'; | 17 import 'package:test/test.dart'; |
| 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 19 | 19 |
| 20 import '../utils.dart'; | 20 import '../utils.dart'; |
| 21 import 'resolver_test_case.dart'; | 21 import 'resolver_test_case.dart'; |
| 22 | 22 |
| 23 main() { | 23 main() { |
| 24 defineReflectiveSuite(() { | 24 defineReflectiveSuite(() { |
| 25 defineReflectiveTests(StrongModeDownwardsInferenceTest); | 25 defineReflectiveTests(StrongModeDownwardsInferenceTest); |
| 26 defineReflectiveTests(StrongModeStaticTypeAnalyzer2Test); | 26 defineReflectiveTests(StrongModeStaticTypeAnalyzer2Test); |
| 27 defineReflectiveTests(StrongModeTypePropagationTest); | 27 defineReflectiveTests(StrongModeTypePropagationTest); |
| 28 defineReflectiveTests(StrongModeDownwardsInferenceTest_Driver); |
| 29 defineReflectiveTests(StrongModeStaticTypeAnalyzer2Test_Driver); |
| 28 defineReflectiveTests(StrongModeTypePropagationTest_Driver); | 30 defineReflectiveTests(StrongModeTypePropagationTest_Driver); |
| 29 }); | 31 }); |
| 30 } | 32 } |
| 31 | 33 |
| 32 /** | 34 /** |
| 33 * Strong mode static analyzer downwards inference tests | 35 * Strong mode static analyzer downwards inference tests |
| 34 */ | 36 */ |
| 35 @reflectiveTest | 37 @reflectiveTest |
| 36 class StrongModeDownwardsInferenceTest extends ResolverTestCase { | 38 class StrongModeDownwardsInferenceTest extends ResolverTestCase { |
| 37 TypeAssertions _assertions; | 39 TypeAssertions _assertions; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 97 |
| 96 Future g0() { return new Future.value(3); } | 98 Future g0() { return new Future.value(3); } |
| 97 Future g1() async { return new Future.value(3); } | 99 Future g1() async { return new Future.value(3); } |
| 98 Future g2() async { return await new Future.value(3); } | 100 Future g2() async { return await new Future.value(3); } |
| 99 | 101 |
| 100 Future<int> g3() { return new Future.value(3); } | 102 Future<int> g3() { return new Future.value(3); } |
| 101 Future<int> g4() async { return new Future.value(3); } | 103 Future<int> g4() async { return new Future.value(3); } |
| 102 Future<int> g5() async { return await new Future.value(3); } | 104 Future<int> g5() async { return await new Future.value(3); } |
| 103 } | 105 } |
| 104 '''; | 106 '''; |
| 105 CompilationUnit unit = resolveSource(code); | 107 CompilationUnit unit = await resolveSource(code); |
| 106 | 108 |
| 107 void check(String name, Asserter<InterfaceType> typeTest) { | 109 void check(String name, Asserter<InterfaceType> typeTest) { |
| 108 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name); | 110 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name); |
| 109 FunctionBody body = test.body; | 111 FunctionBody body = test.body; |
| 110 Expression returnExp; | 112 Expression returnExp; |
| 111 if (body is ExpressionFunctionBody) { | 113 if (body is ExpressionFunctionBody) { |
| 112 returnExp = body.expression; | 114 returnExp = body.expression; |
| 113 } else { | 115 } else { |
| 114 ReturnStatement stmt = (body as BlockFunctionBody).block.statements[0]; | 116 ReturnStatement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 115 returnExp = stmt.expression; | 117 returnExp = stmt.expression; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 Future<int> f5() async => await new Future.value(3); | 153 Future<int> f5() async => await new Future.value(3); |
| 152 | 154 |
| 153 Future g0() { return new Future.value(3); } | 155 Future g0() { return new Future.value(3); } |
| 154 Future g1() async { return new Future.value(3); } | 156 Future g1() async { return new Future.value(3); } |
| 155 Future g2() async { return await new Future.value(3); } | 157 Future g2() async { return await new Future.value(3); } |
| 156 | 158 |
| 157 Future<int> g3() { return new Future.value(3); } | 159 Future<int> g3() { return new Future.value(3); } |
| 158 Future<int> g4() async { return new Future.value(3); } | 160 Future<int> g4() async { return new Future.value(3); } |
| 159 Future<int> g5() async { return await new Future.value(3); } | 161 Future<int> g5() async { return await new Future.value(3); } |
| 160 '''; | 162 '''; |
| 161 CompilationUnit unit = resolveSource(code); | 163 CompilationUnit unit = await resolveSource(code); |
| 162 | 164 |
| 163 void check(String name, Asserter<InterfaceType> typeTest) { | 165 void check(String name, Asserter<InterfaceType> typeTest) { |
| 164 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name); | 166 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name); |
| 165 FunctionBody body = test.functionExpression.body; | 167 FunctionBody body = test.functionExpression.body; |
| 166 Expression returnExp; | 168 Expression returnExp; |
| 167 if (body is ExpressionFunctionBody) { | 169 if (body is ExpressionFunctionBody) { |
| 168 returnExp = body.expression; | 170 returnExp = body.expression; |
| 169 } else { | 171 } else { |
| 170 ReturnStatement stmt = (body as BlockFunctionBody).block.statements[0]; | 172 ReturnStatement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 171 returnExp = stmt.expression; | 173 returnExp = stmt.expression; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 198 String code = r''' | 200 String code = r''' |
| 199 import "dart:async"; | 201 import "dart:async"; |
| 200 class A { | 202 class A { |
| 201 Stream g0() async* { yield []; } | 203 Stream g0() async* { yield []; } |
| 202 Stream g1() async* { yield* new Stream(); } | 204 Stream g1() async* { yield* new Stream(); } |
| 203 | 205 |
| 204 Stream<List<int>> g2() async* { yield []; } | 206 Stream<List<int>> g2() async* { yield []; } |
| 205 Stream<List<int>> g3() async* { yield* new Stream(); } | 207 Stream<List<int>> g3() async* { yield* new Stream(); } |
| 206 } | 208 } |
| 207 '''; | 209 '''; |
| 208 CompilationUnit unit = resolveSource(code); | 210 CompilationUnit unit = await resolveSource(code); |
| 209 | 211 |
| 210 void check(String name, Asserter<InterfaceType> typeTest) { | 212 void check(String name, Asserter<InterfaceType> typeTest) { |
| 211 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name); | 213 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name); |
| 212 BlockFunctionBody body = test.body; | 214 BlockFunctionBody body = test.body; |
| 213 YieldStatement stmt = body.block.statements[0]; | 215 YieldStatement stmt = body.block.statements[0]; |
| 214 Expression exp = stmt.expression; | 216 Expression exp = stmt.expression; |
| 215 typeTest(exp.staticType); | 217 typeTest(exp.staticType); |
| 216 } | 218 } |
| 217 | 219 |
| 218 check("g0", _isListOf(_isDynamic)); | 220 check("g0", _isListOf(_isDynamic)); |
| 219 check("g1", _isStreamOf([_isDynamic])); | 221 check("g1", _isStreamOf([_isDynamic])); |
| 220 | 222 |
| 221 check("g2", _isListOf(_isInt)); | 223 check("g2", _isListOf(_isInt)); |
| 222 check("g3", _isStreamOf([(DartType type) => _isListOf(_isInt)(type)])); | 224 check("g3", _isStreamOf([(DartType type) => _isListOf(_isInt)(type)])); |
| 223 } | 225 } |
| 224 | 226 |
| 225 test_async_star_propagation() async { | 227 test_async_star_propagation() async { |
| 226 String code = r''' | 228 String code = r''' |
| 227 import "dart:async"; | 229 import "dart:async"; |
| 228 | 230 |
| 229 Stream g0() async* { yield []; } | 231 Stream g0() async* { yield []; } |
| 230 Stream g1() async* { yield* new Stream(); } | 232 Stream g1() async* { yield* new Stream(); } |
| 231 | 233 |
| 232 Stream<List<int>> g2() async* { yield []; } | 234 Stream<List<int>> g2() async* { yield []; } |
| 233 Stream<List<int>> g3() async* { yield* new Stream(); } | 235 Stream<List<int>> g3() async* { yield* new Stream(); } |
| 234 '''; | 236 '''; |
| 235 CompilationUnit unit = resolveSource(code); | 237 CompilationUnit unit = await resolveSource(code); |
| 236 | 238 |
| 237 void check(String name, Asserter<InterfaceType> typeTest) { | 239 void check(String name, Asserter<InterfaceType> typeTest) { |
| 238 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name); | 240 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name); |
| 239 BlockFunctionBody body = test.functionExpression.body; | 241 BlockFunctionBody body = test.functionExpression.body; |
| 240 YieldStatement stmt = body.block.statements[0]; | 242 YieldStatement stmt = body.block.statements[0]; |
| 241 Expression exp = stmt.expression; | 243 Expression exp = stmt.expression; |
| 242 typeTest(exp.staticType); | 244 typeTest(exp.staticType); |
| 243 } | 245 } |
| 244 | 246 |
| 245 check("g0", _isListOf(_isDynamic)); | 247 check("g0", _isListOf(_isDynamic)); |
| 246 check("g1", _isStreamOf([_isDynamic])); | 248 check("g1", _isStreamOf([_isDynamic])); |
| 247 | 249 |
| 248 check("g2", _isListOf(_isInt)); | 250 check("g2", _isListOf(_isInt)); |
| 249 check("g3", _isStreamOf([(DartType type) => _isListOf(_isInt)(type)])); | 251 check("g3", _isStreamOf([(DartType type) => _isListOf(_isInt)(type)])); |
| 250 } | 252 } |
| 251 | 253 |
| 252 test_cascadeExpression() async { | 254 test_cascadeExpression() async { |
| 253 String code = r''' | 255 String code = r''' |
| 254 class A<T> { | 256 class A<T> { |
| 255 List<T> map(T a, List<T> mapper(T x)) => mapper(a); | 257 List<T> map(T a, List<T> mapper(T x)) => mapper(a); |
| 256 } | 258 } |
| 257 | 259 |
| 258 void main () { | 260 void main () { |
| 259 A<int> a = new A()..map(0, (x) => [x]); | 261 A<int> a = new A()..map(0, (x) => [x]); |
| 260 } | 262 } |
| 261 '''; | 263 '''; |
| 262 CompilationUnit unit = resolveSource(code); | 264 CompilationUnit unit = await resolveSource(code); |
| 263 List<Statement> statements = | 265 List<Statement> statements = |
| 264 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 266 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 265 CascadeExpression fetch(int i) { | 267 CascadeExpression fetch(int i) { |
| 266 VariableDeclarationStatement stmt = statements[i]; | 268 VariableDeclarationStatement stmt = statements[i]; |
| 267 VariableDeclaration decl = stmt.variables.variables[0]; | 269 VariableDeclaration decl = stmt.variables.variables[0]; |
| 268 CascadeExpression exp = decl.initializer; | 270 CascadeExpression exp = decl.initializer; |
| 269 return exp; | 271 return exp; |
| 270 } | 272 } |
| 271 | 273 |
| 272 Element elementA = AstFinder.getClass(unit, "A").element; | 274 Element elementA = AstFinder.getClass(unit, "A").element; |
| 273 | 275 |
| 274 CascadeExpression cascade = fetch(0); | 276 CascadeExpression cascade = fetch(0); |
| 275 _isInstantiationOf(_hasElement(elementA))([_isInt])(cascade.staticType); | 277 _isInstantiationOf(_hasElement(elementA))([_isInt])(cascade.staticType); |
| 276 MethodInvocation invoke = cascade.cascadeSections[0]; | 278 MethodInvocation invoke = cascade.cascadeSections[0]; |
| 277 FunctionExpression function = invoke.argumentList.arguments[1]; | 279 FunctionExpression function = invoke.argumentList.arguments[1]; |
| 278 ExecutableElement f0 = function.element; | 280 ExecutableElement f0 = function.element; |
| 279 _isListOf(_isInt)(f0.type.returnType); | 281 _isListOf(_isInt)(f0.type.returnType); |
| 280 expect(f0.type.normalParameterTypes[0], typeProvider.intType); | 282 expect(f0.type.normalParameterTypes[0], typeProvider.intType); |
| 281 } | 283 } |
| 282 | 284 |
| 283 test_constructorInitializer_propagation() async { | 285 test_constructorInitializer_propagation() async { |
| 284 String code = r''' | 286 String code = r''' |
| 285 class A { | 287 class A { |
| 286 List<String> x; | 288 List<String> x; |
| 287 A() : this.x = []; | 289 A() : this.x = []; |
| 288 } | 290 } |
| 289 '''; | 291 '''; |
| 290 CompilationUnit unit = resolveSource(code); | 292 CompilationUnit unit = await resolveSource(code); |
| 291 ConstructorDeclaration constructor = | 293 ConstructorDeclaration constructor = |
| 292 AstFinder.getConstructorInClass(unit, "A", null); | 294 AstFinder.getConstructorInClass(unit, "A", null); |
| 293 ConstructorFieldInitializer assignment = constructor.initializers[0]; | 295 ConstructorFieldInitializer assignment = constructor.initializers[0]; |
| 294 Expression exp = assignment.expression; | 296 Expression exp = assignment.expression; |
| 295 _isListOf(_isString)(exp.staticType); | 297 _isListOf(_isString)(exp.staticType); |
| 296 } | 298 } |
| 297 | 299 |
| 298 test_factoryConstructor_propagation() async { | 300 test_factoryConstructor_propagation() async { |
| 299 String code = r''' | 301 String code = r''' |
| 300 class A<T> { | 302 class A<T> { |
| 301 factory A() { return new B(); } | 303 factory A() { return new B(); } |
| 302 } | 304 } |
| 303 class B<S> extends A<S> {} | 305 class B<S> extends A<S> {} |
| 304 '''; | 306 '''; |
| 305 CompilationUnit unit = resolveSource(code); | 307 CompilationUnit unit = await resolveSource(code); |
| 306 | 308 |
| 307 ConstructorDeclaration constructor = | 309 ConstructorDeclaration constructor = |
| 308 AstFinder.getConstructorInClass(unit, "A", null); | 310 AstFinder.getConstructorInClass(unit, "A", null); |
| 309 BlockFunctionBody body = constructor.body; | 311 BlockFunctionBody body = constructor.body; |
| 310 ReturnStatement stmt = body.block.statements[0]; | 312 ReturnStatement stmt = body.block.statements[0]; |
| 311 InstanceCreationExpression exp = stmt.expression; | 313 InstanceCreationExpression exp = stmt.expression; |
| 312 ClassElement elementB = AstFinder.getClass(unit, "B").element; | 314 ClassElement elementB = AstFinder.getClass(unit, "B").element; |
| 313 ClassElement elementA = AstFinder.getClass(unit, "A").element; | 315 ClassElement elementA = AstFinder.getClass(unit, "A").element; |
| 314 expect(resolutionMap.typeForTypeName(exp.constructorName.type).element, | 316 expect(resolutionMap.typeForTypeName(exp.constructorName.type).element, |
| 315 elementB); | 317 elementB); |
| 316 _isInstantiationOf(_hasElement(elementB))( | 318 _isInstantiationOf(_hasElement(elementB))( |
| 317 [_isType(elementA.typeParameters[0].type)])(exp.staticType); | 319 [_isType(elementA.typeParameters[0].type)])(exp.staticType); |
| 318 } | 320 } |
| 319 | 321 |
| 320 test_fieldDeclaration_propagation() async { | 322 test_fieldDeclaration_propagation() async { |
| 321 String code = r''' | 323 String code = r''' |
| 322 class A { | 324 class A { |
| 323 List<String> f0 = ["hello"]; | 325 List<String> f0 = ["hello"]; |
| 324 } | 326 } |
| 325 '''; | 327 '''; |
| 326 CompilationUnit unit = resolveSource(code); | 328 CompilationUnit unit = await resolveSource(code); |
| 327 | 329 |
| 328 VariableDeclaration field = AstFinder.getFieldInClass(unit, "A", "f0"); | 330 VariableDeclaration field = AstFinder.getFieldInClass(unit, "A", "f0"); |
| 329 | 331 |
| 330 _isListOf(_isString)(field.initializer.staticType); | 332 _isListOf(_isString)(field.initializer.staticType); |
| 331 } | 333 } |
| 332 | 334 |
| 333 test_functionDeclaration_body_propagation() async { | 335 test_functionDeclaration_body_propagation() async { |
| 334 String code = r''' | 336 String code = r''' |
| 335 typedef T Function2<S, T>(S x); | 337 typedef T Function2<S, T>(S x); |
| 336 | 338 |
| 337 List<int> test1() => []; | 339 List<int> test1() => []; |
| 338 | 340 |
| 339 Function2<int, int> test2 (int x) { | 341 Function2<int, int> test2 (int x) { |
| 340 Function2<String, int> inner() { | 342 Function2<String, int> inner() { |
| 341 return (x) => x.length; | 343 return (x) => x.length; |
| 342 } | 344 } |
| 343 return (x) => x; | 345 return (x) => x; |
| 344 } | 346 } |
| 345 '''; | 347 '''; |
| 346 CompilationUnit unit = resolveSource(code); | 348 CompilationUnit unit = await resolveSource(code); |
| 347 | 349 |
| 348 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 350 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 349 | 351 |
| 350 FunctionDeclaration test1 = AstFinder.getTopLevelFunction(unit, "test1"); | 352 FunctionDeclaration test1 = AstFinder.getTopLevelFunction(unit, "test1"); |
| 351 ExpressionFunctionBody body = test1.functionExpression.body; | 353 ExpressionFunctionBody body = test1.functionExpression.body; |
| 352 assertListOfInt(body.expression.staticType); | 354 assertListOfInt(body.expression.staticType); |
| 353 | 355 |
| 354 List<Statement> statements = | 356 List<Statement> statements = |
| 355 AstFinder.getStatementsInTopLevelFunction(unit, "test2"); | 357 AstFinder.getStatementsInTopLevelFunction(unit, "test2"); |
| 356 | 358 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 375 typedef T Function2<S, T>(S x); | 377 typedef T Function2<S, T>(S x); |
| 376 | 378 |
| 377 void main () { | 379 void main () { |
| 378 Function2<int, String> l0 = (int x) => null; | 380 Function2<int, String> l0 = (int x) => null; |
| 379 Function2<int, String> l1 = (int x) => "hello"; | 381 Function2<int, String> l1 = (int x) => "hello"; |
| 380 Function2<int, String> l2 = (String x) => "hello"; | 382 Function2<int, String> l2 = (String x) => "hello"; |
| 381 Function2<int, String> l3 = (int x) => 3; | 383 Function2<int, String> l3 = (int x) => 3; |
| 382 Function2<int, String> l4 = (int x) {return 3;}; | 384 Function2<int, String> l4 = (int x) {return 3;}; |
| 383 } | 385 } |
| 384 '''; | 386 '''; |
| 385 CompilationUnit unit = resolveSource(code); | 387 CompilationUnit unit = await resolveSource(code); |
| 386 List<Statement> statements = | 388 List<Statement> statements = |
| 387 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 389 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 388 DartType literal(int i) { | 390 DartType literal(int i) { |
| 389 VariableDeclarationStatement stmt = statements[i]; | 391 VariableDeclarationStatement stmt = statements[i]; |
| 390 VariableDeclaration decl = stmt.variables.variables[0]; | 392 VariableDeclaration decl = stmt.variables.variables[0]; |
| 391 FunctionExpression exp = decl.initializer; | 393 FunctionExpression exp = decl.initializer; |
| 392 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; | 394 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; |
| 393 } | 395 } |
| 394 | 396 |
| 395 _isFunction2Of(_isInt, _isString)(literal(0)); | 397 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 396 _isFunction2Of(_isInt, _isString)(literal(1)); | 398 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 397 _isFunction2Of(_isString, _isString)(literal(2)); | 399 _isFunction2Of(_isString, _isString)(literal(2)); |
| 398 _isFunction2Of(_isInt, _isInt)(literal(3)); | 400 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 399 _isFunction2Of(_isInt, _isString)(literal(4)); | 401 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 400 } | 402 } |
| 401 | 403 |
| 402 test_functionLiteral_assignment_unTypedArguments() async { | 404 test_functionLiteral_assignment_unTypedArguments() async { |
| 403 String code = r''' | 405 String code = r''' |
| 404 typedef T Function2<S, T>(S x); | 406 typedef T Function2<S, T>(S x); |
| 405 | 407 |
| 406 void main () { | 408 void main () { |
| 407 Function2<int, String> l0 = (x) => null; | 409 Function2<int, String> l0 = (x) => null; |
| 408 Function2<int, String> l1 = (x) => "hello"; | 410 Function2<int, String> l1 = (x) => "hello"; |
| 409 Function2<int, String> l2 = (x) => "hello"; | 411 Function2<int, String> l2 = (x) => "hello"; |
| 410 Function2<int, String> l3 = (x) => 3; | 412 Function2<int, String> l3 = (x) => 3; |
| 411 Function2<int, String> l4 = (x) {return 3;}; | 413 Function2<int, String> l4 = (x) {return 3;}; |
| 412 } | 414 } |
| 413 '''; | 415 '''; |
| 414 CompilationUnit unit = resolveSource(code); | 416 CompilationUnit unit = await resolveSource(code); |
| 415 List<Statement> statements = | 417 List<Statement> statements = |
| 416 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 418 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 417 DartType literal(int i) { | 419 DartType literal(int i) { |
| 418 VariableDeclarationStatement stmt = statements[i]; | 420 VariableDeclarationStatement stmt = statements[i]; |
| 419 VariableDeclaration decl = stmt.variables.variables[0]; | 421 VariableDeclaration decl = stmt.variables.variables[0]; |
| 420 FunctionExpression exp = decl.initializer; | 422 FunctionExpression exp = decl.initializer; |
| 421 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; | 423 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; |
| 422 } | 424 } |
| 423 | 425 |
| 424 _isFunction2Of(_isInt, _isString)(literal(0)); | 426 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 425 _isFunction2Of(_isInt, _isString)(literal(1)); | 427 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 426 _isFunction2Of(_isInt, _isString)(literal(2)); | 428 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 427 _isFunction2Of(_isInt, _isInt)(literal(3)); | 429 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 428 _isFunction2Of(_isInt, _isString)(literal(4)); | 430 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 429 } | 431 } |
| 430 | 432 |
| 431 test_functionLiteral_body_propagation() async { | 433 test_functionLiteral_body_propagation() async { |
| 432 String code = r''' | 434 String code = r''' |
| 433 typedef T Function2<S, T>(S x); | 435 typedef T Function2<S, T>(S x); |
| 434 | 436 |
| 435 void main () { | 437 void main () { |
| 436 Function2<int, List<String>> l0 = (int x) => ["hello"]; | 438 Function2<int, List<String>> l0 = (int x) => ["hello"]; |
| 437 Function2<int, List<String>> l1 = (String x) => ["hello"]; | 439 Function2<int, List<String>> l1 = (String x) => ["hello"]; |
| 438 Function2<int, List<String>> l2 = (int x) => [3]; | 440 Function2<int, List<String>> l2 = (int x) => [3]; |
| 439 Function2<int, List<String>> l3 = (int x) {return [3];}; | 441 Function2<int, List<String>> l3 = (int x) {return [3];}; |
| 440 } | 442 } |
| 441 '''; | 443 '''; |
| 442 CompilationUnit unit = resolveSource(code); | 444 CompilationUnit unit = await resolveSource(code); |
| 443 List<Statement> statements = | 445 List<Statement> statements = |
| 444 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 446 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 445 Expression functionReturnValue(int i) { | 447 Expression functionReturnValue(int i) { |
| 446 VariableDeclarationStatement stmt = statements[i]; | 448 VariableDeclarationStatement stmt = statements[i]; |
| 447 VariableDeclaration decl = stmt.variables.variables[0]; | 449 VariableDeclaration decl = stmt.variables.variables[0]; |
| 448 FunctionExpression exp = decl.initializer; | 450 FunctionExpression exp = decl.initializer; |
| 449 FunctionBody body = exp.body; | 451 FunctionBody body = exp.body; |
| 450 if (body is ExpressionFunctionBody) { | 452 if (body is ExpressionFunctionBody) { |
| 451 return body.expression; | 453 return body.expression; |
| 452 } else { | 454 } else { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 469 } | 471 } |
| 470 | 472 |
| 471 void main () { | 473 void main () { |
| 472 (new Mapper<int, String>().map)((int x) => null); | 474 (new Mapper<int, String>().map)((int x) => null); |
| 473 (new Mapper<int, String>().map)((int x) => "hello"); | 475 (new Mapper<int, String>().map)((int x) => "hello"); |
| 474 (new Mapper<int, String>().map)((String x) => "hello"); | 476 (new Mapper<int, String>().map)((String x) => "hello"); |
| 475 (new Mapper<int, String>().map)((int x) => 3); | 477 (new Mapper<int, String>().map)((int x) => 3); |
| 476 (new Mapper<int, String>().map)((int x) {return 3;}); | 478 (new Mapper<int, String>().map)((int x) {return 3;}); |
| 477 } | 479 } |
| 478 '''; | 480 '''; |
| 479 CompilationUnit unit = resolveSource(code); | 481 CompilationUnit unit = await resolveSource(code); |
| 480 List<Statement> statements = | 482 List<Statement> statements = |
| 481 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 483 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 482 DartType literal(int i) { | 484 DartType literal(int i) { |
| 483 ExpressionStatement stmt = statements[i]; | 485 ExpressionStatement stmt = statements[i]; |
| 484 FunctionExpressionInvocation invk = stmt.expression; | 486 FunctionExpressionInvocation invk = stmt.expression; |
| 485 FunctionExpression exp = invk.argumentList.arguments[0]; | 487 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 486 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; | 488 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; |
| 487 } | 489 } |
| 488 | 490 |
| 489 _isFunction2Of(_isInt, _isString)(literal(0)); | 491 _isFunction2Of(_isInt, _isString)(literal(0)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 500 } | 502 } |
| 501 | 503 |
| 502 void main () { | 504 void main () { |
| 503 (new Mapper<int, String>().map)((x) => null); | 505 (new Mapper<int, String>().map)((x) => null); |
| 504 (new Mapper<int, String>().map)((x) => "hello"); | 506 (new Mapper<int, String>().map)((x) => "hello"); |
| 505 (new Mapper<int, String>().map)((x) => "hello"); | 507 (new Mapper<int, String>().map)((x) => "hello"); |
| 506 (new Mapper<int, String>().map)((x) => 3); | 508 (new Mapper<int, String>().map)((x) => 3); |
| 507 (new Mapper<int, String>().map)((x) {return 3;}); | 509 (new Mapper<int, String>().map)((x) {return 3;}); |
| 508 } | 510 } |
| 509 '''; | 511 '''; |
| 510 CompilationUnit unit = resolveSource(code); | 512 CompilationUnit unit = await resolveSource(code); |
| 511 List<Statement> statements = | 513 List<Statement> statements = |
| 512 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 514 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 513 DartType literal(int i) { | 515 DartType literal(int i) { |
| 514 ExpressionStatement stmt = statements[i]; | 516 ExpressionStatement stmt = statements[i]; |
| 515 FunctionExpressionInvocation invk = stmt.expression; | 517 FunctionExpressionInvocation invk = stmt.expression; |
| 516 FunctionExpression exp = invk.argumentList.arguments[0]; | 518 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 517 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; | 519 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; |
| 518 } | 520 } |
| 519 | 521 |
| 520 _isFunction2Of(_isInt, _isString)(literal(0)); | 522 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 521 _isFunction2Of(_isInt, _isString)(literal(1)); | 523 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 522 _isFunction2Of(_isInt, _isString)(literal(2)); | 524 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 523 _isFunction2Of(_isInt, _isInt)(literal(3)); | 525 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 524 _isFunction2Of(_isInt, _isString)(literal(4)); | 526 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 525 } | 527 } |
| 526 | 528 |
| 527 test_functionLiteral_functionInvocation_typedArguments() async { | 529 test_functionLiteral_functionInvocation_typedArguments() async { |
| 528 String code = r''' | 530 String code = r''' |
| 529 String map(String mapper(int x)) => mapper(null); | 531 String map(String mapper(int x)) => mapper(null); |
| 530 | 532 |
| 531 void main () { | 533 void main () { |
| 532 map((int x) => null); | 534 map((int x) => null); |
| 533 map((int x) => "hello"); | 535 map((int x) => "hello"); |
| 534 map((String x) => "hello"); | 536 map((String x) => "hello"); |
| 535 map((int x) => 3); | 537 map((int x) => 3); |
| 536 map((int x) {return 3;}); | 538 map((int x) {return 3;}); |
| 537 } | 539 } |
| 538 '''; | 540 '''; |
| 539 CompilationUnit unit = resolveSource(code); | 541 CompilationUnit unit = await resolveSource(code); |
| 540 List<Statement> statements = | 542 List<Statement> statements = |
| 541 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 543 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 542 DartType literal(int i) { | 544 DartType literal(int i) { |
| 543 ExpressionStatement stmt = statements[i]; | 545 ExpressionStatement stmt = statements[i]; |
| 544 MethodInvocation invk = stmt.expression; | 546 MethodInvocation invk = stmt.expression; |
| 545 FunctionExpression exp = invk.argumentList.arguments[0]; | 547 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 546 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; | 548 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; |
| 547 } | 549 } |
| 548 | 550 |
| 549 _isFunction2Of(_isInt, _isString)(literal(0)); | 551 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 550 _isFunction2Of(_isInt, _isString)(literal(1)); | 552 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 551 _isFunction2Of(_isString, _isString)(literal(2)); | 553 _isFunction2Of(_isString, _isString)(literal(2)); |
| 552 _isFunction2Of(_isInt, _isInt)(literal(3)); | 554 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 553 _isFunction2Of(_isInt, _isString)(literal(4)); | 555 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 554 } | 556 } |
| 555 | 557 |
| 556 test_functionLiteral_functionInvocation_unTypedArguments() async { | 558 test_functionLiteral_functionInvocation_unTypedArguments() async { |
| 557 String code = r''' | 559 String code = r''' |
| 558 String map(String mapper(int x)) => mapper(null); | 560 String map(String mapper(int x)) => mapper(null); |
| 559 | 561 |
| 560 void main () { | 562 void main () { |
| 561 map((x) => null); | 563 map((x) => null); |
| 562 map((x) => "hello"); | 564 map((x) => "hello"); |
| 563 map((x) => "hello"); | 565 map((x) => "hello"); |
| 564 map((x) => 3); | 566 map((x) => 3); |
| 565 map((x) {return 3;}); | 567 map((x) {return 3;}); |
| 566 } | 568 } |
| 567 '''; | 569 '''; |
| 568 CompilationUnit unit = resolveSource(code); | 570 CompilationUnit unit = await resolveSource(code); |
| 569 List<Statement> statements = | 571 List<Statement> statements = |
| 570 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 572 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 571 DartType literal(int i) { | 573 DartType literal(int i) { |
| 572 ExpressionStatement stmt = statements[i]; | 574 ExpressionStatement stmt = statements[i]; |
| 573 MethodInvocation invk = stmt.expression; | 575 MethodInvocation invk = stmt.expression; |
| 574 FunctionExpression exp = invk.argumentList.arguments[0]; | 576 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 575 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; | 577 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; |
| 576 } | 578 } |
| 577 | 579 |
| 578 _isFunction2Of(_isInt, _isString)(literal(0)); | 580 _isFunction2Of(_isInt, _isString)(literal(0)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 589 } | 591 } |
| 590 | 592 |
| 591 void main () { | 593 void main () { |
| 592 new Mapper<int, String>().map((int x) => null); | 594 new Mapper<int, String>().map((int x) => null); |
| 593 new Mapper<int, String>().map((int x) => "hello"); | 595 new Mapper<int, String>().map((int x) => "hello"); |
| 594 new Mapper<int, String>().map((String x) => "hello"); | 596 new Mapper<int, String>().map((String x) => "hello"); |
| 595 new Mapper<int, String>().map((int x) => 3); | 597 new Mapper<int, String>().map((int x) => 3); |
| 596 new Mapper<int, String>().map((int x) {return 3;}); | 598 new Mapper<int, String>().map((int x) {return 3;}); |
| 597 } | 599 } |
| 598 '''; | 600 '''; |
| 599 CompilationUnit unit = resolveSource(code); | 601 CompilationUnit unit = await resolveSource(code); |
| 600 List<Statement> statements = | 602 List<Statement> statements = |
| 601 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 603 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 602 DartType literal(int i) { | 604 DartType literal(int i) { |
| 603 ExpressionStatement stmt = statements[i]; | 605 ExpressionStatement stmt = statements[i]; |
| 604 MethodInvocation invk = stmt.expression; | 606 MethodInvocation invk = stmt.expression; |
| 605 FunctionExpression exp = invk.argumentList.arguments[0]; | 607 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 606 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; | 608 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; |
| 607 } | 609 } |
| 608 | 610 |
| 609 _isFunction2Of(_isInt, _isString)(literal(0)); | 611 _isFunction2Of(_isInt, _isString)(literal(0)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 620 } | 622 } |
| 621 | 623 |
| 622 void main () { | 624 void main () { |
| 623 new Mapper<int, String>().map((x) => null); | 625 new Mapper<int, String>().map((x) => null); |
| 624 new Mapper<int, String>().map((x) => "hello"); | 626 new Mapper<int, String>().map((x) => "hello"); |
| 625 new Mapper<int, String>().map((x) => "hello"); | 627 new Mapper<int, String>().map((x) => "hello"); |
| 626 new Mapper<int, String>().map((x) => 3); | 628 new Mapper<int, String>().map((x) => 3); |
| 627 new Mapper<int, String>().map((x) {return 3;}); | 629 new Mapper<int, String>().map((x) {return 3;}); |
| 628 } | 630 } |
| 629 '''; | 631 '''; |
| 630 CompilationUnit unit = resolveSource(code); | 632 CompilationUnit unit = await resolveSource(code); |
| 631 List<Statement> statements = | 633 List<Statement> statements = |
| 632 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 634 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 633 DartType literal(int i) { | 635 DartType literal(int i) { |
| 634 ExpressionStatement stmt = statements[i]; | 636 ExpressionStatement stmt = statements[i]; |
| 635 MethodInvocation invk = stmt.expression; | 637 MethodInvocation invk = stmt.expression; |
| 636 FunctionExpression exp = invk.argumentList.arguments[0]; | 638 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 637 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; | 639 return resolutionMap.elementDeclaredByFunctionExpression(exp).type; |
| 638 } | 640 } |
| 639 | 641 |
| 640 _isFunction2Of(_isInt, _isString)(literal(0)); | 642 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 641 _isFunction2Of(_isInt, _isString)(literal(1)); | 643 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 642 _isFunction2Of(_isInt, _isString)(literal(2)); | 644 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 643 _isFunction2Of(_isInt, _isInt)(literal(3)); | 645 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 644 _isFunction2Of(_isInt, _isString)(literal(4)); | 646 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 645 } | 647 } |
| 646 | 648 |
| 647 test_functionLiteral_unTypedArgument_propagation() async { | 649 test_functionLiteral_unTypedArgument_propagation() async { |
| 648 String code = r''' | 650 String code = r''' |
| 649 typedef T Function2<S, T>(S x); | 651 typedef T Function2<S, T>(S x); |
| 650 | 652 |
| 651 void main () { | 653 void main () { |
| 652 Function2<int, int> l0 = (x) => x; | 654 Function2<int, int> l0 = (x) => x; |
| 653 Function2<int, int> l1 = (x) => x+1; | 655 Function2<int, int> l1 = (x) => x+1; |
| 654 Function2<int, String> l2 = (x) => x; | 656 Function2<int, String> l2 = (x) => x; |
| 655 Function2<int, String> l3 = (x) => x.toLowerCase(); | 657 Function2<int, String> l3 = (x) => x.toLowerCase(); |
| 656 Function2<String, String> l4 = (x) => x.toLowerCase(); | 658 Function2<String, String> l4 = (x) => x.toLowerCase(); |
| 657 } | 659 } |
| 658 '''; | 660 '''; |
| 659 CompilationUnit unit = resolveSource(code); | 661 CompilationUnit unit = await resolveSource(code); |
| 660 List<Statement> statements = | 662 List<Statement> statements = |
| 661 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 663 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 662 Expression functionReturnValue(int i) { | 664 Expression functionReturnValue(int i) { |
| 663 VariableDeclarationStatement stmt = statements[i]; | 665 VariableDeclarationStatement stmt = statements[i]; |
| 664 VariableDeclaration decl = stmt.variables.variables[0]; | 666 VariableDeclaration decl = stmt.variables.variables[0]; |
| 665 FunctionExpression exp = decl.initializer; | 667 FunctionExpression exp = decl.initializer; |
| 666 FunctionBody body = exp.body; | 668 FunctionBody body = exp.body; |
| 667 if (body is ExpressionFunctionBody) { | 669 if (body is ExpressionFunctionBody) { |
| 668 return body.expression; | 670 return body.expression; |
| 669 } else { | 671 } else { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 698 abstract class A { | 700 abstract class A { |
| 699 Map<int, List<int>> get map; | 701 Map<int, List<int>> get map; |
| 700 } | 702 } |
| 701 class B extends A { | 703 class B extends A { |
| 702 var map = { 42: [] }; | 704 var map = { 42: [] }; |
| 703 } | 705 } |
| 704 class C extends A { | 706 class C extends A { |
| 705 get map => { 43: [] }; | 707 get map => { 43: [] }; |
| 706 } | 708 } |
| 707 '''; | 709 '''; |
| 708 CompilationUnit unit = resolveSource(code); | 710 CompilationUnit unit = await resolveSource(code); |
| 709 | 711 |
| 710 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 712 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 711 Asserter<InterfaceType> assertMapOfIntToListOfInt = | 713 Asserter<InterfaceType> assertMapOfIntToListOfInt = |
| 712 _isMapOf(_isInt, (DartType type) => assertListOfInt(type)); | 714 _isMapOf(_isInt, (DartType type) => assertListOfInt(type)); |
| 713 | 715 |
| 714 VariableDeclaration mapB = AstFinder.getFieldInClass(unit, "B", "map"); | 716 VariableDeclaration mapB = AstFinder.getFieldInClass(unit, "B", "map"); |
| 715 MethodDeclaration mapC = AstFinder.getMethodInClass(unit, "C", "map"); | 717 MethodDeclaration mapC = AstFinder.getMethodInClass(unit, "C", "map"); |
| 716 assertMapOfIntToListOfInt( | 718 assertMapOfIntToListOfInt( |
| 717 resolutionMap.elementDeclaredByVariableDeclaration(mapB).type); | 719 resolutionMap.elementDeclaredByVariableDeclaration(mapB).type); |
| 718 assertMapOfIntToListOfInt( | 720 assertMapOfIntToListOfInt( |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 } | 817 } |
| 816 void test9() { // Check named and optional arguments | 818 void test9() { // Check named and optional arguments |
| 817 A<int, String> a0 = new F(3, "hello", a: [3], b: ["hello"]); | 819 A<int, String> a0 = new F(3, "hello", a: [3], b: ["hello"]); |
| 818 A<int, String> a1 = new F(3, "hello", a: ["hello"], b:[3]); | 820 A<int, String> a1 = new F(3, "hello", a: ["hello"], b:[3]); |
| 819 A<int, String> a2 = new F.named(3, "hello", 3, "hello"); | 821 A<int, String> a2 = new F.named(3, "hello", 3, "hello"); |
| 820 A<int, String> a3 = new F.named(3, "hello"); | 822 A<int, String> a3 = new F.named(3, "hello"); |
| 821 A<int, String> a4 = new F.named(3, "hello", "hello", 3); | 823 A<int, String> a4 = new F.named(3, "hello", "hello", 3); |
| 822 A<int, String> a5 = new F.named(3, "hello", "hello"); | 824 A<int, String> a5 = new F.named(3, "hello", "hello"); |
| 823 } | 825 } |
| 824 }'''; | 826 }'''; |
| 825 CompilationUnit unit = resolveSource(code); | 827 CompilationUnit unit = await resolveSource(code); |
| 826 | 828 |
| 827 Expression rhs(VariableDeclarationStatement stmt) { | 829 Expression rhs(VariableDeclarationStatement stmt) { |
| 828 VariableDeclaration decl = stmt.variables.variables[0]; | 830 VariableDeclaration decl = stmt.variables.variables[0]; |
| 829 Expression exp = decl.initializer; | 831 Expression exp = decl.initializer; |
| 830 return exp; | 832 return exp; |
| 831 } | 833 } |
| 832 | 834 |
| 833 void hasType(Asserter<DartType> assertion, Expression exp) => | 835 void hasType(Asserter<DartType> assertion, Expression exp) => |
| 834 assertion(exp.staticType); | 836 assertion(exp.staticType); |
| 835 | 837 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 | 952 |
| 951 test_listLiteral_nested() async { | 953 test_listLiteral_nested() async { |
| 952 String code = r''' | 954 String code = r''' |
| 953 void main () { | 955 void main () { |
| 954 List<List<int>> l0 = [[]]; | 956 List<List<int>> l0 = [[]]; |
| 955 Iterable<List<int>> l1 = [[3]]; | 957 Iterable<List<int>> l1 = [[3]]; |
| 956 Iterable<List<int>> l2 = [[3], [4]]; | 958 Iterable<List<int>> l2 = [[3], [4]]; |
| 957 List<List<int>> l3 = [["hello", 3], []]; | 959 List<List<int>> l3 = [["hello", 3], []]; |
| 958 } | 960 } |
| 959 '''; | 961 '''; |
| 960 CompilationUnit unit = resolveSource(code); | 962 CompilationUnit unit = await resolveSource(code); |
| 961 List<Statement> statements = | 963 List<Statement> statements = |
| 962 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 964 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 963 ListLiteral literal(int i) { | 965 ListLiteral literal(int i) { |
| 964 VariableDeclarationStatement stmt = statements[i]; | 966 VariableDeclarationStatement stmt = statements[i]; |
| 965 VariableDeclaration decl = stmt.variables.variables[0]; | 967 VariableDeclaration decl = stmt.variables.variables[0]; |
| 966 ListLiteral exp = decl.initializer; | 968 ListLiteral exp = decl.initializer; |
| 967 return exp; | 969 return exp; |
| 968 } | 970 } |
| 969 | 971 |
| 970 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 972 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 983 | 985 |
| 984 test_listLiteral_simple() async { | 986 test_listLiteral_simple() async { |
| 985 String code = r''' | 987 String code = r''' |
| 986 void main () { | 988 void main () { |
| 987 List<int> l0 = []; | 989 List<int> l0 = []; |
| 988 List<int> l1 = [3]; | 990 List<int> l1 = [3]; |
| 989 List<int> l2 = ["hello"]; | 991 List<int> l2 = ["hello"]; |
| 990 List<int> l3 = ["hello", 3]; | 992 List<int> l3 = ["hello", 3]; |
| 991 } | 993 } |
| 992 '''; | 994 '''; |
| 993 CompilationUnit unit = resolveSource(code); | 995 CompilationUnit unit = await resolveSource(code); |
| 994 List<Statement> statements = | 996 List<Statement> statements = |
| 995 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 997 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 996 DartType literal(int i) { | 998 DartType literal(int i) { |
| 997 VariableDeclarationStatement stmt = statements[i]; | 999 VariableDeclarationStatement stmt = statements[i]; |
| 998 VariableDeclaration decl = stmt.variables.variables[0]; | 1000 VariableDeclaration decl = stmt.variables.variables[0]; |
| 999 ListLiteral exp = decl.initializer; | 1001 ListLiteral exp = decl.initializer; |
| 1000 return exp.staticType; | 1002 return exp.staticType; |
| 1001 } | 1003 } |
| 1002 | 1004 |
| 1003 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 1005 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 1004 | 1006 |
| 1005 assertListOfInt(literal(0)); | 1007 assertListOfInt(literal(0)); |
| 1006 assertListOfInt(literal(1)); | 1008 assertListOfInt(literal(1)); |
| 1007 assertListOfInt(literal(2)); | 1009 assertListOfInt(literal(2)); |
| 1008 assertListOfInt(literal(3)); | 1010 assertListOfInt(literal(3)); |
| 1009 } | 1011 } |
| 1010 | 1012 |
| 1011 test_listLiteral_simple_const() async { | 1013 test_listLiteral_simple_const() async { |
| 1012 String code = r''' | 1014 String code = r''' |
| 1013 void main () { | 1015 void main () { |
| 1014 const List<int> c0 = const []; | 1016 const List<int> c0 = const []; |
| 1015 const List<int> c1 = const [3]; | 1017 const List<int> c1 = const [3]; |
| 1016 const List<int> c2 = const ["hello"]; | 1018 const List<int> c2 = const ["hello"]; |
| 1017 const List<int> c3 = const ["hello", 3]; | 1019 const List<int> c3 = const ["hello", 3]; |
| 1018 } | 1020 } |
| 1019 '''; | 1021 '''; |
| 1020 CompilationUnit unit = resolveSource(code); | 1022 CompilationUnit unit = await resolveSource(code); |
| 1021 List<Statement> statements = | 1023 List<Statement> statements = |
| 1022 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1024 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1023 DartType literal(int i) { | 1025 DartType literal(int i) { |
| 1024 VariableDeclarationStatement stmt = statements[i]; | 1026 VariableDeclarationStatement stmt = statements[i]; |
| 1025 VariableDeclaration decl = stmt.variables.variables[0]; | 1027 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1026 ListLiteral exp = decl.initializer; | 1028 ListLiteral exp = decl.initializer; |
| 1027 return exp.staticType; | 1029 return exp.staticType; |
| 1028 } | 1030 } |
| 1029 | 1031 |
| 1030 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 1032 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 1031 | 1033 |
| 1032 assertListOfInt(literal(0)); | 1034 assertListOfInt(literal(0)); |
| 1033 assertListOfInt(literal(1)); | 1035 assertListOfInt(literal(1)); |
| 1034 assertListOfInt(literal(2)); | 1036 assertListOfInt(literal(2)); |
| 1035 assertListOfInt(literal(3)); | 1037 assertListOfInt(literal(3)); |
| 1036 } | 1038 } |
| 1037 | 1039 |
| 1038 test_listLiteral_simple_disabled() async { | 1040 test_listLiteral_simple_disabled() async { |
| 1039 String code = r''' | 1041 String code = r''' |
| 1040 void main () { | 1042 void main () { |
| 1041 List<int> l0 = <num>[]; | 1043 List<int> l0 = <num>[]; |
| 1042 List<int> l1 = <num>[3]; | 1044 List<int> l1 = <num>[3]; |
| 1043 List<int> l2 = <String>["hello"]; | 1045 List<int> l2 = <String>["hello"]; |
| 1044 List<int> l3 = <dynamic>["hello", 3]; | 1046 List<int> l3 = <dynamic>["hello", 3]; |
| 1045 } | 1047 } |
| 1046 '''; | 1048 '''; |
| 1047 CompilationUnit unit = resolveSource(code); | 1049 CompilationUnit unit = await resolveSource(code); |
| 1048 List<Statement> statements = | 1050 List<Statement> statements = |
| 1049 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1051 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1050 DartType literal(int i) { | 1052 DartType literal(int i) { |
| 1051 VariableDeclarationStatement stmt = statements[i]; | 1053 VariableDeclarationStatement stmt = statements[i]; |
| 1052 VariableDeclaration decl = stmt.variables.variables[0]; | 1054 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1053 ListLiteral exp = decl.initializer; | 1055 ListLiteral exp = decl.initializer; |
| 1054 return exp.staticType; | 1056 return exp.staticType; |
| 1055 } | 1057 } |
| 1056 | 1058 |
| 1057 _isListOf(_isNum)(literal(0)); | 1059 _isListOf(_isNum)(literal(0)); |
| 1058 _isListOf(_isNum)(literal(1)); | 1060 _isListOf(_isNum)(literal(1)); |
| 1059 _isListOf(_isString)(literal(2)); | 1061 _isListOf(_isString)(literal(2)); |
| 1060 _isListOf(_isDynamic)(literal(3)); | 1062 _isListOf(_isDynamic)(literal(3)); |
| 1061 } | 1063 } |
| 1062 | 1064 |
| 1063 test_listLiteral_simple_subtype() async { | 1065 test_listLiteral_simple_subtype() async { |
| 1064 String code = r''' | 1066 String code = r''' |
| 1065 void main () { | 1067 void main () { |
| 1066 Iterable<int> l0 = []; | 1068 Iterable<int> l0 = []; |
| 1067 Iterable<int> l1 = [3]; | 1069 Iterable<int> l1 = [3]; |
| 1068 Iterable<int> l2 = ["hello"]; | 1070 Iterable<int> l2 = ["hello"]; |
| 1069 Iterable<int> l3 = ["hello", 3]; | 1071 Iterable<int> l3 = ["hello", 3]; |
| 1070 } | 1072 } |
| 1071 '''; | 1073 '''; |
| 1072 CompilationUnit unit = resolveSource(code); | 1074 CompilationUnit unit = await resolveSource(code); |
| 1073 List<Statement> statements = | 1075 List<Statement> statements = |
| 1074 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1076 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1075 DartType literal(int i) { | 1077 DartType literal(int i) { |
| 1076 VariableDeclarationStatement stmt = statements[i]; | 1078 VariableDeclarationStatement stmt = statements[i]; |
| 1077 VariableDeclaration decl = stmt.variables.variables[0]; | 1079 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1078 ListLiteral exp = decl.initializer; | 1080 ListLiteral exp = decl.initializer; |
| 1079 return exp.staticType; | 1081 return exp.staticType; |
| 1080 } | 1082 } |
| 1081 | 1083 |
| 1082 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 1084 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 1083 | 1085 |
| 1084 assertListOfInt(literal(0)); | 1086 assertListOfInt(literal(0)); |
| 1085 assertListOfInt(literal(1)); | 1087 assertListOfInt(literal(1)); |
| 1086 assertListOfInt(literal(2)); | 1088 assertListOfInt(literal(2)); |
| 1087 assertListOfInt(literal(3)); | 1089 assertListOfInt(literal(3)); |
| 1088 } | 1090 } |
| 1089 | 1091 |
| 1090 test_mapLiteral_nested() async { | 1092 test_mapLiteral_nested() async { |
| 1091 String code = r''' | 1093 String code = r''' |
| 1092 void main () { | 1094 void main () { |
| 1093 Map<int, List<String>> l0 = {}; | 1095 Map<int, List<String>> l0 = {}; |
| 1094 Map<int, List<String>> l1 = {3: ["hello"]}; | 1096 Map<int, List<String>> l1 = {3: ["hello"]}; |
| 1095 Map<int, List<String>> l2 = {"hello": ["hello"]}; | 1097 Map<int, List<String>> l2 = {"hello": ["hello"]}; |
| 1096 Map<int, List<String>> l3 = {3: [3]}; | 1098 Map<int, List<String>> l3 = {3: [3]}; |
| 1097 Map<int, List<String>> l4 = {3:["hello"], "hello": [3]}; | 1099 Map<int, List<String>> l4 = {3:["hello"], "hello": [3]}; |
| 1098 } | 1100 } |
| 1099 '''; | 1101 '''; |
| 1100 CompilationUnit unit = resolveSource(code); | 1102 CompilationUnit unit = await resolveSource(code); |
| 1101 List<Statement> statements = | 1103 List<Statement> statements = |
| 1102 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1104 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1103 MapLiteral literal(int i) { | 1105 MapLiteral literal(int i) { |
| 1104 VariableDeclarationStatement stmt = statements[i]; | 1106 VariableDeclarationStatement stmt = statements[i]; |
| 1105 VariableDeclaration decl = stmt.variables.variables[0]; | 1107 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1106 MapLiteral exp = decl.initializer; | 1108 MapLiteral exp = decl.initializer; |
| 1107 return exp; | 1109 return exp; |
| 1108 } | 1110 } |
| 1109 | 1111 |
| 1110 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); | 1112 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1126 test_mapLiteral_simple() async { | 1128 test_mapLiteral_simple() async { |
| 1127 String code = r''' | 1129 String code = r''' |
| 1128 void main () { | 1130 void main () { |
| 1129 Map<int, String> l0 = {}; | 1131 Map<int, String> l0 = {}; |
| 1130 Map<int, String> l1 = {3: "hello"}; | 1132 Map<int, String> l1 = {3: "hello"}; |
| 1131 Map<int, String> l2 = {"hello": "hello"}; | 1133 Map<int, String> l2 = {"hello": "hello"}; |
| 1132 Map<int, String> l3 = {3: 3}; | 1134 Map<int, String> l3 = {3: 3}; |
| 1133 Map<int, String> l4 = {3:"hello", "hello": 3}; | 1135 Map<int, String> l4 = {3:"hello", "hello": 3}; |
| 1134 } | 1136 } |
| 1135 '''; | 1137 '''; |
| 1136 CompilationUnit unit = resolveSource(code); | 1138 CompilationUnit unit = await resolveSource(code); |
| 1137 List<Statement> statements = | 1139 List<Statement> statements = |
| 1138 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1140 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1139 DartType literal(int i) { | 1141 DartType literal(int i) { |
| 1140 VariableDeclarationStatement stmt = statements[i]; | 1142 VariableDeclarationStatement stmt = statements[i]; |
| 1141 VariableDeclaration decl = stmt.variables.variables[0]; | 1143 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1142 MapLiteral exp = decl.initializer; | 1144 MapLiteral exp = decl.initializer; |
| 1143 return exp.staticType; | 1145 return exp.staticType; |
| 1144 } | 1146 } |
| 1145 | 1147 |
| 1146 Asserter<InterfaceType> assertMapOfIntToString = | 1148 Asserter<InterfaceType> assertMapOfIntToString = |
| 1147 _isMapOf(_isInt, _isString); | 1149 _isMapOf(_isInt, _isString); |
| 1148 | 1150 |
| 1149 assertMapOfIntToString(literal(0)); | 1151 assertMapOfIntToString(literal(0)); |
| 1150 assertMapOfIntToString(literal(1)); | 1152 assertMapOfIntToString(literal(1)); |
| 1151 assertMapOfIntToString(literal(2)); | 1153 assertMapOfIntToString(literal(2)); |
| 1152 assertMapOfIntToString(literal(3)); | 1154 assertMapOfIntToString(literal(3)); |
| 1153 } | 1155 } |
| 1154 | 1156 |
| 1155 test_mapLiteral_simple_disabled() async { | 1157 test_mapLiteral_simple_disabled() async { |
| 1156 String code = r''' | 1158 String code = r''' |
| 1157 void main () { | 1159 void main () { |
| 1158 Map<int, String> l0 = <int, dynamic>{}; | 1160 Map<int, String> l0 = <int, dynamic>{}; |
| 1159 Map<int, String> l1 = <int, dynamic>{3: "hello"}; | 1161 Map<int, String> l1 = <int, dynamic>{3: "hello"}; |
| 1160 Map<int, String> l2 = <int, dynamic>{"hello": "hello"}; | 1162 Map<int, String> l2 = <int, dynamic>{"hello": "hello"}; |
| 1161 Map<int, String> l3 = <int, dynamic>{3: 3}; | 1163 Map<int, String> l3 = <int, dynamic>{3: 3}; |
| 1162 } | 1164 } |
| 1163 '''; | 1165 '''; |
| 1164 CompilationUnit unit = resolveSource(code); | 1166 CompilationUnit unit = await resolveSource(code); |
| 1165 List<Statement> statements = | 1167 List<Statement> statements = |
| 1166 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1168 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1167 DartType literal(int i) { | 1169 DartType literal(int i) { |
| 1168 VariableDeclarationStatement stmt = statements[i]; | 1170 VariableDeclarationStatement stmt = statements[i]; |
| 1169 VariableDeclaration decl = stmt.variables.variables[0]; | 1171 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1170 MapLiteral exp = decl.initializer; | 1172 MapLiteral exp = decl.initializer; |
| 1171 return exp.staticType; | 1173 return exp.staticType; |
| 1172 } | 1174 } |
| 1173 | 1175 |
| 1174 Asserter<InterfaceType> assertMapOfIntToDynamic = | 1176 Asserter<InterfaceType> assertMapOfIntToDynamic = |
| 1175 _isMapOf(_isInt, _isDynamic); | 1177 _isMapOf(_isInt, _isDynamic); |
| 1176 | 1178 |
| 1177 assertMapOfIntToDynamic(literal(0)); | 1179 assertMapOfIntToDynamic(literal(0)); |
| 1178 assertMapOfIntToDynamic(literal(1)); | 1180 assertMapOfIntToDynamic(literal(1)); |
| 1179 assertMapOfIntToDynamic(literal(2)); | 1181 assertMapOfIntToDynamic(literal(2)); |
| 1180 assertMapOfIntToDynamic(literal(3)); | 1182 assertMapOfIntToDynamic(literal(3)); |
| 1181 } | 1183 } |
| 1182 | 1184 |
| 1183 test_methodDeclaration_body_propagation() async { | 1185 test_methodDeclaration_body_propagation() async { |
| 1184 String code = r''' | 1186 String code = r''' |
| 1185 class A { | 1187 class A { |
| 1186 List<String> m0(int x) => ["hello"]; | 1188 List<String> m0(int x) => ["hello"]; |
| 1187 List<String> m1(int x) {return [3];}; | 1189 List<String> m1(int x) {return [3];}; |
| 1188 } | 1190 } |
| 1189 '''; | 1191 '''; |
| 1190 CompilationUnit unit = resolveSource(code); | 1192 CompilationUnit unit = await resolveSource(code); |
| 1191 Expression methodReturnValue(String methodName) { | 1193 Expression methodReturnValue(String methodName) { |
| 1192 MethodDeclaration method = | 1194 MethodDeclaration method = |
| 1193 AstFinder.getMethodInClass(unit, "A", methodName); | 1195 AstFinder.getMethodInClass(unit, "A", methodName); |
| 1194 FunctionBody body = method.body; | 1196 FunctionBody body = method.body; |
| 1195 if (body is ExpressionFunctionBody) { | 1197 if (body is ExpressionFunctionBody) { |
| 1196 return body.expression; | 1198 return body.expression; |
| 1197 } else { | 1199 } else { |
| 1198 Statement stmt = (body as BlockFunctionBody).block.statements[0]; | 1200 Statement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 1199 return (stmt as ReturnStatement).expression; | 1201 return (stmt as ReturnStatement).expression; |
| 1200 } | 1202 } |
| 1201 } | 1203 } |
| 1202 | 1204 |
| 1203 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); | 1205 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); |
| 1204 assertListOfString(methodReturnValue("m0").staticType); | 1206 assertListOfString(methodReturnValue("m0").staticType); |
| 1205 assertListOfString(methodReturnValue("m1").staticType); | 1207 assertListOfString(methodReturnValue("m1").staticType); |
| 1206 } | 1208 } |
| 1207 | 1209 |
| 1208 test_redirectingConstructor_propagation() async { | 1210 test_redirectingConstructor_propagation() async { |
| 1209 String code = r''' | 1211 String code = r''' |
| 1210 class A { | 1212 class A { |
| 1211 A() : this.named([]); | 1213 A() : this.named([]); |
| 1212 A.named(List<String> x); | 1214 A.named(List<String> x); |
| 1213 } | 1215 } |
| 1214 '''; | 1216 '''; |
| 1215 CompilationUnit unit = resolveSource(code); | 1217 CompilationUnit unit = await resolveSource(code); |
| 1216 | 1218 |
| 1217 ConstructorDeclaration constructor = | 1219 ConstructorDeclaration constructor = |
| 1218 AstFinder.getConstructorInClass(unit, "A", null); | 1220 AstFinder.getConstructorInClass(unit, "A", null); |
| 1219 RedirectingConstructorInvocation invocation = constructor.initializers[0]; | 1221 RedirectingConstructorInvocation invocation = constructor.initializers[0]; |
| 1220 Expression exp = invocation.argumentList.arguments[0]; | 1222 Expression exp = invocation.argumentList.arguments[0]; |
| 1221 _isListOf(_isString)(exp.staticType); | 1223 _isListOf(_isString)(exp.staticType); |
| 1222 } | 1224 } |
| 1223 | 1225 |
| 1224 test_superConstructorInvocation_propagation() async { | 1226 test_superConstructorInvocation_propagation() async { |
| 1225 String code = r''' | 1227 String code = r''' |
| 1226 class B { | 1228 class B { |
| 1227 B(List<String>); | 1229 B(List<String>); |
| 1228 } | 1230 } |
| 1229 class A extends B { | 1231 class A extends B { |
| 1230 A() : super([]); | 1232 A() : super([]); |
| 1231 } | 1233 } |
| 1232 '''; | 1234 '''; |
| 1233 CompilationUnit unit = resolveSource(code); | 1235 CompilationUnit unit = await resolveSource(code); |
| 1234 | 1236 |
| 1235 ConstructorDeclaration constructor = | 1237 ConstructorDeclaration constructor = |
| 1236 AstFinder.getConstructorInClass(unit, "A", null); | 1238 AstFinder.getConstructorInClass(unit, "A", null); |
| 1237 SuperConstructorInvocation invocation = constructor.initializers[0]; | 1239 SuperConstructorInvocation invocation = constructor.initializers[0]; |
| 1238 Expression exp = invocation.argumentList.arguments[0]; | 1240 Expression exp = invocation.argumentList.arguments[0]; |
| 1239 _isListOf(_isString)(exp.staticType); | 1241 _isListOf(_isString)(exp.staticType); |
| 1240 } | 1242 } |
| 1241 | 1243 |
| 1242 test_sync_star_method_propagation() async { | 1244 test_sync_star_method_propagation() async { |
| 1243 String code = r''' | 1245 String code = r''' |
| 1244 import "dart:async"; | 1246 import "dart:async"; |
| 1245 class A { | 1247 class A { |
| 1246 Iterable f0() sync* { yield []; } | 1248 Iterable f0() sync* { yield []; } |
| 1247 Iterable f1() sync* { yield* new List(); } | 1249 Iterable f1() sync* { yield* new List(); } |
| 1248 | 1250 |
| 1249 Iterable<List<int>> f2() sync* { yield []; } | 1251 Iterable<List<int>> f2() sync* { yield []; } |
| 1250 Iterable<List<int>> f3() sync* { yield* new List(); } | 1252 Iterable<List<int>> f3() sync* { yield* new List(); } |
| 1251 } | 1253 } |
| 1252 '''; | 1254 '''; |
| 1253 CompilationUnit unit = resolveSource(code); | 1255 CompilationUnit unit = await resolveSource(code); |
| 1254 | 1256 |
| 1255 void check(String name, Asserter<InterfaceType> typeTest) { | 1257 void check(String name, Asserter<InterfaceType> typeTest) { |
| 1256 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name); | 1258 MethodDeclaration test = AstFinder.getMethodInClass(unit, "A", name); |
| 1257 BlockFunctionBody body = test.body; | 1259 BlockFunctionBody body = test.body; |
| 1258 YieldStatement stmt = body.block.statements[0]; | 1260 YieldStatement stmt = body.block.statements[0]; |
| 1259 Expression exp = stmt.expression; | 1261 Expression exp = stmt.expression; |
| 1260 typeTest(exp.staticType); | 1262 typeTest(exp.staticType); |
| 1261 } | 1263 } |
| 1262 | 1264 |
| 1263 check("f0", _isListOf(_isDynamic)); | 1265 check("f0", _isListOf(_isDynamic)); |
| 1264 check("f1", _isListOf(_isDynamic)); | 1266 check("f1", _isListOf(_isDynamic)); |
| 1265 | 1267 |
| 1266 check("f2", _isListOf(_isInt)); | 1268 check("f2", _isListOf(_isInt)); |
| 1267 check("f3", _isListOf((DartType type) => _isListOf(_isInt)(type))); | 1269 check("f3", _isListOf((DartType type) => _isListOf(_isInt)(type))); |
| 1268 } | 1270 } |
| 1269 | 1271 |
| 1270 test_sync_star_propagation() async { | 1272 test_sync_star_propagation() async { |
| 1271 String code = r''' | 1273 String code = r''' |
| 1272 import "dart:async"; | 1274 import "dart:async"; |
| 1273 | 1275 |
| 1274 Iterable f0() sync* { yield []; } | 1276 Iterable f0() sync* { yield []; } |
| 1275 Iterable f1() sync* { yield* new List(); } | 1277 Iterable f1() sync* { yield* new List(); } |
| 1276 | 1278 |
| 1277 Iterable<List<int>> f2() sync* { yield []; } | 1279 Iterable<List<int>> f2() sync* { yield []; } |
| 1278 Iterable<List<int>> f3() sync* { yield* new List(); } | 1280 Iterable<List<int>> f3() sync* { yield* new List(); } |
| 1279 '''; | 1281 '''; |
| 1280 CompilationUnit unit = resolveSource(code); | 1282 CompilationUnit unit = await resolveSource(code); |
| 1281 | 1283 |
| 1282 void check(String name, Asserter<InterfaceType> typeTest) { | 1284 void check(String name, Asserter<InterfaceType> typeTest) { |
| 1283 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name); | 1285 FunctionDeclaration test = AstFinder.getTopLevelFunction(unit, name); |
| 1284 BlockFunctionBody body = test.functionExpression.body; | 1286 BlockFunctionBody body = test.functionExpression.body; |
| 1285 YieldStatement stmt = body.block.statements[0]; | 1287 YieldStatement stmt = body.block.statements[0]; |
| 1286 Expression exp = stmt.expression; | 1288 Expression exp = stmt.expression; |
| 1287 typeTest(exp.staticType); | 1289 typeTest(exp.staticType); |
| 1288 } | 1290 } |
| 1289 | 1291 |
| 1290 check("f0", _isListOf(_isDynamic)); | 1292 check("f0", _isListOf(_isDynamic)); |
| 1291 check("f1", _isListOf(_isDynamic)); | 1293 check("f1", _isListOf(_isDynamic)); |
| 1292 | 1294 |
| 1293 check("f2", _isListOf(_isInt)); | 1295 check("f2", _isListOf(_isInt)); |
| 1294 check("f3", _isListOf((DartType type) => _isListOf(_isInt)(type))); | 1296 check("f3", _isListOf((DartType type) => _isListOf(_isInt)(type))); |
| 1295 } | 1297 } |
| 1296 } | 1298 } |
| 1297 | 1299 |
| 1300 @reflectiveTest |
| 1301 class StrongModeDownwardsInferenceTest_Driver |
| 1302 extends StrongModeDownwardsInferenceTest { |
| 1303 @override |
| 1304 bool get enableNewAnalysisDriver => true; |
| 1305 |
| 1306 @failingTest |
| 1307 @override |
| 1308 test_inference_hints() { |
| 1309 return super.test_inference_hints(); |
| 1310 } |
| 1311 } |
| 1312 |
| 1298 /** | 1313 /** |
| 1299 * Strong mode static analyzer end to end tests | 1314 * Strong mode static analyzer end to end tests |
| 1300 */ | 1315 */ |
| 1301 @reflectiveTest | 1316 @reflectiveTest |
| 1302 class StrongModeStaticTypeAnalyzer2Test extends StaticTypeAnalyzer2TestShared { | 1317 class StrongModeStaticTypeAnalyzer2Test extends StaticTypeAnalyzer2TestShared { |
| 1303 fail_genericMethod_tearoff_instantiated() async { | 1318 fail_genericMethod_tearoff_instantiated() async { |
| 1304 await resolveTestUnit(r''' | 1319 await resolveTestUnit(r''' |
| 1305 class C<E> { | 1320 class C<E> { |
| 1306 /*=T*/ f/*<T>*/(E e) => null; | 1321 /*=T*/ f/*<T>*/(E e) => null; |
| 1307 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; | 1322 static /*=T*/ g/*<T>*/(/*=T*/ e) => null; |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2167 expectIdentifierType('t0', "String"); | 2182 expectIdentifierType('t0', "String"); |
| 2168 expectIdentifierType('t1', "() → String"); | 2183 expectIdentifierType('t1', "() → String"); |
| 2169 expectIdentifierType('t2', "int"); | 2184 expectIdentifierType('t2', "int"); |
| 2170 expectIdentifierType('t3', "String"); | 2185 expectIdentifierType('t3', "String"); |
| 2171 expectIdentifierType('t4', "() → String"); | 2186 expectIdentifierType('t4', "() → String"); |
| 2172 expectIdentifierType('t5', "int"); | 2187 expectIdentifierType('t5', "int"); |
| 2173 } | 2188 } |
| 2174 } | 2189 } |
| 2175 | 2190 |
| 2176 @reflectiveTest | 2191 @reflectiveTest |
| 2192 class StrongModeStaticTypeAnalyzer2Test_Driver |
| 2193 extends StrongModeStaticTypeAnalyzer2Test { |
| 2194 @override |
| 2195 bool get enableNewAnalysisDriver => true; |
| 2196 |
| 2197 @failingTest |
| 2198 @override |
| 2199 test_genericFunction_parameter() { |
| 2200 return super.test_genericFunction_parameter(); |
| 2201 } |
| 2202 |
| 2203 @failingTest |
| 2204 @override |
| 2205 test_genericMethod_functionExpressionInvocation_explicit() { |
| 2206 return super.test_genericMethod_functionExpressionInvocation_explicit(); |
| 2207 } |
| 2208 |
| 2209 @failingTest |
| 2210 @override |
| 2211 test_genericMethod_functionExpressionInvocation_inferred() { |
| 2212 return super.test_genericMethod_functionExpressionInvocation_inferred(); |
| 2213 } |
| 2214 |
| 2215 @failingTest |
| 2216 @override |
| 2217 test_genericMethod_functionInvocation_explicit() { |
| 2218 return super.test_genericMethod_functionInvocation_explicit(); |
| 2219 } |
| 2220 |
| 2221 @failingTest |
| 2222 @override |
| 2223 test_genericMethod_functionInvocation_inferred() { |
| 2224 return super.test_genericMethod_functionInvocation_inferred(); |
| 2225 } |
| 2226 |
| 2227 @failingTest |
| 2228 @override |
| 2229 test_genericMethod_tearoff() { |
| 2230 return super.test_genericMethod_tearoff(); |
| 2231 } |
| 2232 } |
| 2233 |
| 2234 @reflectiveTest |
| 2177 class StrongModeTypePropagationTest extends ResolverTestCase { | 2235 class StrongModeTypePropagationTest extends ResolverTestCase { |
| 2178 @override | 2236 @override |
| 2179 void setUp() { | 2237 void setUp() { |
| 2180 super.setUp(); | 2238 super.setUp(); |
| 2181 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 2239 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2182 options.strongMode = true; | 2240 options.strongMode = true; |
| 2183 resetWith(options: options); | 2241 resetWith(options: options); |
| 2184 } | 2242 } |
| 2185 | 2243 |
| 2186 test_foreachInference_dynamic_disabled() async { | 2244 test_foreachInference_dynamic_disabled() async { |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2478 await assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 2421 } | 2479 } |
| 2422 } | 2480 } |
| 2423 | 2481 |
| 2424 @reflectiveTest | 2482 @reflectiveTest |
| 2425 class StrongModeTypePropagationTest_Driver | 2483 class StrongModeTypePropagationTest_Driver |
| 2426 extends StrongModeTypePropagationTest { | 2484 extends StrongModeTypePropagationTest { |
| 2427 @override | 2485 @override |
| 2428 bool get enableNewAnalysisDriver => true; | 2486 bool get enableNewAnalysisDriver => true; |
| 2429 } | 2487 } |
| OLD | NEW |