| 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 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/dart/element/type.dart'; | 9 import 'package:analyzer/dart/element/type.dart'; |
| 10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 TypeAssertions _assertions; | 32 TypeAssertions _assertions; |
| 33 | 33 |
| 34 Asserter<DartType> _isDynamic; | 34 Asserter<DartType> _isDynamic; |
| 35 Asserter<InterfaceType> _isFutureOfDynamic; | 35 Asserter<InterfaceType> _isFutureOfDynamic; |
| 36 Asserter<InterfaceType> _isFutureOfInt; | 36 Asserter<InterfaceType> _isFutureOfInt; |
| 37 Asserter<DartType> _isInt; | 37 Asserter<DartType> _isInt; |
| 38 Asserter<DartType> _isNum; | 38 Asserter<DartType> _isNum; |
| 39 Asserter<DartType> _isString; | 39 Asserter<DartType> _isString; |
| 40 | 40 |
| 41 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, DartType> | 41 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, DartType> |
| 42 _isFunction2Of; | 42 _isFunction2Of; |
| 43 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isFutureOf; | 43 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isFutureOf; |
| 44 AsserterBuilderBuilder<Asserter<DartType>, List<Asserter<DartType>>, DartType> | 44 AsserterBuilderBuilder<Asserter<DartType>, List<Asserter<DartType>>, DartType> |
| 45 _isInstantiationOf; | 45 _isInstantiationOf; |
| 46 AsserterBuilder<Asserter<DartType>, InterfaceType> _isListOf; | 46 AsserterBuilder<Asserter<DartType>, InterfaceType> _isListOf; |
| 47 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, InterfaceType> | 47 AsserterBuilder2<Asserter<DartType>, Asserter<DartType>, InterfaceType> |
| 48 _isMapOf; | 48 _isMapOf; |
| 49 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isStreamOf; | 49 AsserterBuilder<List<Asserter<DartType>>, InterfaceType> _isStreamOf; |
| 50 AsserterBuilder<DartType, DartType> _isType; | 50 AsserterBuilder<DartType, DartType> _isType; |
| 51 | 51 |
| 52 AsserterBuilder<Element, DartType> _hasElement; | 52 AsserterBuilder<Element, DartType> _hasElement; |
| 53 AsserterBuilder<DartType, DartType> _sameElement; | 53 AsserterBuilder<DartType, DartType> _sameElement; |
| 54 | 54 |
| 55 @override | 55 @override |
| 56 void setUp() { | 56 void setUp() { |
| 57 super.setUp(); | 57 super.setUp(); |
| 58 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 58 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 class A<T> { | 257 class A<T> { |
| 258 List<T> map(T a, List<T> mapper(T x)) => mapper(a); | 258 List<T> map(T a, List<T> mapper(T x)) => mapper(a); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void main () { | 261 void main () { |
| 262 A<int> a = new A()..map(0, (x) => [x]); | 262 A<int> a = new A()..map(0, (x) => [x]); |
| 263 } | 263 } |
| 264 '''; | 264 '''; |
| 265 CompilationUnit unit = resolveSource(code); | 265 CompilationUnit unit = resolveSource(code); |
| 266 List<Statement> statements = | 266 List<Statement> statements = |
| 267 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 267 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 268 CascadeExpression fetch(int i) { | 268 CascadeExpression fetch(int i) { |
| 269 VariableDeclarationStatement stmt = statements[i]; | 269 VariableDeclarationStatement stmt = statements[i]; |
| 270 VariableDeclaration decl = stmt.variables.variables[0]; | 270 VariableDeclaration decl = stmt.variables.variables[0]; |
| 271 CascadeExpression exp = decl.initializer; | 271 CascadeExpression exp = decl.initializer; |
| 272 return exp; | 272 return exp; |
| 273 } | 273 } |
| 274 Element elementA = AstFinder.getClass(unit, "A").element; | 274 Element elementA = AstFinder.getClass(unit, "A").element; |
| 275 | 275 |
| 276 CascadeExpression cascade = fetch(0); | 276 CascadeExpression cascade = fetch(0); |
| 277 _isInstantiationOf(_hasElement(elementA))([_isInt])(cascade.staticType); | 277 _isInstantiationOf(_hasElement(elementA))([_isInt])(cascade.staticType); |
| 278 MethodInvocation invoke = cascade.cascadeSections[0]; | 278 MethodInvocation invoke = cascade.cascadeSections[0]; |
| 279 FunctionExpression function = invoke.argumentList.arguments[1]; | 279 FunctionExpression function = invoke.argumentList.arguments[1]; |
| 280 ExecutableElement f0 = function.element; | 280 ExecutableElement f0 = function.element; |
| 281 _isListOf(_isInt)(f0.type.returnType); | 281 _isListOf(_isInt)(f0.type.returnType); |
| 282 expect(f0.type.normalParameterTypes[0], typeProvider.intType); | 282 expect(f0.type.normalParameterTypes[0], typeProvider.intType); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void test_constructorInitializer_propagation() { | 285 void test_constructorInitializer_propagation() { |
| 286 String code = r''' | 286 String code = r''' |
| 287 class A { | 287 class A { |
| 288 List<String> x; | 288 List<String> x; |
| 289 A() : this.x = []; | 289 A() : this.x = []; |
| 290 } | 290 } |
| 291 '''; | 291 '''; |
| 292 CompilationUnit unit = resolveSource(code); | 292 CompilationUnit unit = resolveSource(code); |
| 293 ConstructorDeclaration constructor = | 293 ConstructorDeclaration constructor = |
| 294 AstFinder.getConstructorInClass(unit, "A", null); | 294 AstFinder.getConstructorInClass(unit, "A", null); |
| 295 ConstructorFieldInitializer assignment = constructor.initializers[0]; | 295 ConstructorFieldInitializer assignment = constructor.initializers[0]; |
| 296 Expression exp = assignment.expression; | 296 Expression exp = assignment.expression; |
| 297 _isListOf(_isString)(exp.staticType); | 297 _isListOf(_isString)(exp.staticType); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void test_factoryConstructor_propagation() { | 300 void test_factoryConstructor_propagation() { |
| 301 String code = r''' | 301 String code = r''' |
| 302 class A<T> { | 302 class A<T> { |
| 303 factory A() { return new B(); } | 303 factory A() { return new B(); } |
| 304 } | 304 } |
| 305 class B<S> extends A<S> {} | 305 class B<S> extends A<S> {} |
| 306 '''; | 306 '''; |
| 307 CompilationUnit unit = resolveSource(code); | 307 CompilationUnit unit = resolveSource(code); |
| 308 | 308 |
| 309 ConstructorDeclaration constructor = | 309 ConstructorDeclaration constructor = |
| 310 AstFinder.getConstructorInClass(unit, "A", null); | 310 AstFinder.getConstructorInClass(unit, "A", null); |
| 311 BlockFunctionBody body = constructor.body; | 311 BlockFunctionBody body = constructor.body; |
| 312 ReturnStatement stmt = body.block.statements[0]; | 312 ReturnStatement stmt = body.block.statements[0]; |
| 313 InstanceCreationExpression exp = stmt.expression; | 313 InstanceCreationExpression exp = stmt.expression; |
| 314 ClassElement elementB = AstFinder.getClass(unit, "B").element; | 314 ClassElement elementB = AstFinder.getClass(unit, "B").element; |
| 315 ClassElement elementA = AstFinder.getClass(unit, "A").element; | 315 ClassElement elementA = AstFinder.getClass(unit, "A").element; |
| 316 expect(exp.constructorName.type.type.element, elementB); | 316 expect(exp.constructorName.type.type.element, elementB); |
| 317 _isInstantiationOf(_hasElement(elementB))( | 317 _isInstantiationOf(_hasElement(elementB))( |
| 318 [_isType(elementA.typeParameters[0].type)])(exp.staticType); | 318 [_isType(elementA.typeParameters[0].type)])(exp.staticType); |
| 319 } | 319 } |
| 320 | 320 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 346 '''; | 346 '''; |
| 347 CompilationUnit unit = resolveSource(code); | 347 CompilationUnit unit = resolveSource(code); |
| 348 | 348 |
| 349 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 349 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 350 | 350 |
| 351 FunctionDeclaration test1 = AstFinder.getTopLevelFunction(unit, "test1"); | 351 FunctionDeclaration test1 = AstFinder.getTopLevelFunction(unit, "test1"); |
| 352 ExpressionFunctionBody body = test1.functionExpression.body; | 352 ExpressionFunctionBody body = test1.functionExpression.body; |
| 353 assertListOfInt(body.expression.staticType); | 353 assertListOfInt(body.expression.staticType); |
| 354 | 354 |
| 355 List<Statement> statements = | 355 List<Statement> statements = |
| 356 AstFinder.getStatementsInTopLevelFunction(unit, "test2"); | 356 AstFinder.getStatementsInTopLevelFunction(unit, "test2"); |
| 357 | 357 |
| 358 FunctionDeclaration inner = | 358 FunctionDeclaration inner = |
| 359 (statements[0] as FunctionDeclarationStatement).functionDeclaration; | 359 (statements[0] as FunctionDeclarationStatement).functionDeclaration; |
| 360 BlockFunctionBody body0 = inner.functionExpression.body; | 360 BlockFunctionBody body0 = inner.functionExpression.body; |
| 361 ReturnStatement return0 = body0.block.statements[0]; | 361 ReturnStatement return0 = body0.block.statements[0]; |
| 362 Expression anon0 = return0.expression; | 362 Expression anon0 = return0.expression; |
| 363 FunctionType type0 = anon0.staticType; | 363 FunctionType type0 = anon0.staticType; |
| 364 expect(type0.returnType, typeProvider.intType); | 364 expect(type0.returnType, typeProvider.intType); |
| 365 expect(type0.normalParameterTypes[0], typeProvider.stringType); | 365 expect(type0.normalParameterTypes[0], typeProvider.stringType); |
| 366 | 366 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 377 void main () { | 377 void main () { |
| 378 Function2<int, String> l0 = (int x) => null; | 378 Function2<int, String> l0 = (int x) => null; |
| 379 Function2<int, String> l1 = (int x) => "hello"; | 379 Function2<int, String> l1 = (int x) => "hello"; |
| 380 Function2<int, String> l2 = (String x) => "hello"; | 380 Function2<int, String> l2 = (String x) => "hello"; |
| 381 Function2<int, String> l3 = (int x) => 3; | 381 Function2<int, String> l3 = (int x) => 3; |
| 382 Function2<int, String> l4 = (int x) {return 3;}; | 382 Function2<int, String> l4 = (int x) {return 3;}; |
| 383 } | 383 } |
| 384 '''; | 384 '''; |
| 385 CompilationUnit unit = resolveSource(code); | 385 CompilationUnit unit = resolveSource(code); |
| 386 List<Statement> statements = | 386 List<Statement> statements = |
| 387 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 387 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 388 DartType literal(int i) { | 388 DartType literal(int i) { |
| 389 VariableDeclarationStatement stmt = statements[i]; | 389 VariableDeclarationStatement stmt = statements[i]; |
| 390 VariableDeclaration decl = stmt.variables.variables[0]; | 390 VariableDeclaration decl = stmt.variables.variables[0]; |
| 391 FunctionExpression exp = decl.initializer; | 391 FunctionExpression exp = decl.initializer; |
| 392 return exp.element.type; | 392 return exp.element.type; |
| 393 } | 393 } |
| 394 _isFunction2Of(_isInt, _isString)(literal(0)); | 394 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 395 _isFunction2Of(_isInt, _isString)(literal(1)); | 395 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 396 _isFunction2Of(_isString, _isString)(literal(2)); | 396 _isFunction2Of(_isString, _isString)(literal(2)); |
| 397 _isFunction2Of(_isInt, _isInt)(literal(3)); | 397 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 398 _isFunction2Of(_isInt, _isString)(literal(4)); | 398 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void test_functionLiteral_assignment_unTypedArguments() { | 401 void test_functionLiteral_assignment_unTypedArguments() { |
| 402 String code = r''' | 402 String code = r''' |
| 403 typedef T Function2<S, T>(S x); | 403 typedef T Function2<S, T>(S x); |
| 404 | 404 |
| 405 void main () { | 405 void main () { |
| 406 Function2<int, String> l0 = (x) => null; | 406 Function2<int, String> l0 = (x) => null; |
| 407 Function2<int, String> l1 = (x) => "hello"; | 407 Function2<int, String> l1 = (x) => "hello"; |
| 408 Function2<int, String> l2 = (x) => "hello"; | 408 Function2<int, String> l2 = (x) => "hello"; |
| 409 Function2<int, String> l3 = (x) => 3; | 409 Function2<int, String> l3 = (x) => 3; |
| 410 Function2<int, String> l4 = (x) {return 3;}; | 410 Function2<int, String> l4 = (x) {return 3;}; |
| 411 } | 411 } |
| 412 '''; | 412 '''; |
| 413 CompilationUnit unit = resolveSource(code); | 413 CompilationUnit unit = resolveSource(code); |
| 414 List<Statement> statements = | 414 List<Statement> statements = |
| 415 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 415 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 416 DartType literal(int i) { | 416 DartType literal(int i) { |
| 417 VariableDeclarationStatement stmt = statements[i]; | 417 VariableDeclarationStatement stmt = statements[i]; |
| 418 VariableDeclaration decl = stmt.variables.variables[0]; | 418 VariableDeclaration decl = stmt.variables.variables[0]; |
| 419 FunctionExpression exp = decl.initializer; | 419 FunctionExpression exp = decl.initializer; |
| 420 return exp.element.type; | 420 return exp.element.type; |
| 421 } | 421 } |
| 422 _isFunction2Of(_isInt, _isString)(literal(0)); | 422 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 423 _isFunction2Of(_isInt, _isString)(literal(1)); | 423 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 424 _isFunction2Of(_isInt, _isString)(literal(2)); | 424 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 425 _isFunction2Of(_isInt, _isInt)(literal(3)); | 425 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 426 _isFunction2Of(_isInt, _isString)(literal(4)); | 426 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 427 } | 427 } |
| 428 | 428 |
| 429 void test_functionLiteral_body_propagation() { | 429 void test_functionLiteral_body_propagation() { |
| 430 String code = r''' | 430 String code = r''' |
| 431 typedef T Function2<S, T>(S x); | 431 typedef T Function2<S, T>(S x); |
| 432 | 432 |
| 433 void main () { | 433 void main () { |
| 434 Function2<int, List<String>> l0 = (int x) => ["hello"]; | 434 Function2<int, List<String>> l0 = (int x) => ["hello"]; |
| 435 Function2<int, List<String>> l1 = (String x) => ["hello"]; | 435 Function2<int, List<String>> l1 = (String x) => ["hello"]; |
| 436 Function2<int, List<String>> l2 = (int x) => [3]; | 436 Function2<int, List<String>> l2 = (int x) => [3]; |
| 437 Function2<int, List<String>> l3 = (int x) {return [3];}; | 437 Function2<int, List<String>> l3 = (int x) {return [3];}; |
| 438 } | 438 } |
| 439 '''; | 439 '''; |
| 440 CompilationUnit unit = resolveSource(code); | 440 CompilationUnit unit = resolveSource(code); |
| 441 List<Statement> statements = | 441 List<Statement> statements = |
| 442 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 442 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 443 Expression functionReturnValue(int i) { | 443 Expression functionReturnValue(int i) { |
| 444 VariableDeclarationStatement stmt = statements[i]; | 444 VariableDeclarationStatement stmt = statements[i]; |
| 445 VariableDeclaration decl = stmt.variables.variables[0]; | 445 VariableDeclaration decl = stmt.variables.variables[0]; |
| 446 FunctionExpression exp = decl.initializer; | 446 FunctionExpression exp = decl.initializer; |
| 447 FunctionBody body = exp.body; | 447 FunctionBody body = exp.body; |
| 448 if (body is ExpressionFunctionBody) { | 448 if (body is ExpressionFunctionBody) { |
| 449 return body.expression; | 449 return body.expression; |
| 450 } else { | 450 } else { |
| 451 Statement stmt = (body as BlockFunctionBody).block.statements[0]; | 451 Statement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 452 return (stmt as ReturnStatement).expression; | 452 return (stmt as ReturnStatement).expression; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 468 void main () { | 468 void main () { |
| 469 (new Mapper<int, String>().map)((int x) => null); | 469 (new Mapper<int, String>().map)((int x) => null); |
| 470 (new Mapper<int, String>().map)((int x) => "hello"); | 470 (new Mapper<int, String>().map)((int x) => "hello"); |
| 471 (new Mapper<int, String>().map)((String x) => "hello"); | 471 (new Mapper<int, String>().map)((String x) => "hello"); |
| 472 (new Mapper<int, String>().map)((int x) => 3); | 472 (new Mapper<int, String>().map)((int x) => 3); |
| 473 (new Mapper<int, String>().map)((int x) {return 3;}); | 473 (new Mapper<int, String>().map)((int x) {return 3;}); |
| 474 } | 474 } |
| 475 '''; | 475 '''; |
| 476 CompilationUnit unit = resolveSource(code); | 476 CompilationUnit unit = resolveSource(code); |
| 477 List<Statement> statements = | 477 List<Statement> statements = |
| 478 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 478 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 479 DartType literal(int i) { | 479 DartType literal(int i) { |
| 480 ExpressionStatement stmt = statements[i]; | 480 ExpressionStatement stmt = statements[i]; |
| 481 FunctionExpressionInvocation invk = stmt.expression; | 481 FunctionExpressionInvocation invk = stmt.expression; |
| 482 FunctionExpression exp = invk.argumentList.arguments[0]; | 482 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 483 return exp.element.type; | 483 return exp.element.type; |
| 484 } | 484 } |
| 485 _isFunction2Of(_isInt, _isString)(literal(0)); | 485 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 486 _isFunction2Of(_isInt, _isString)(literal(1)); | 486 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 487 _isFunction2Of(_isString, _isString)(literal(2)); | 487 _isFunction2Of(_isString, _isString)(literal(2)); |
| 488 _isFunction2Of(_isInt, _isInt)(literal(3)); | 488 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 489 _isFunction2Of(_isInt, _isString)(literal(4)); | 489 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 490 } | 490 } |
| 491 | 491 |
| 492 void test_functionLiteral_functionExpressionInvocation_unTypedArguments() { | 492 void test_functionLiteral_functionExpressionInvocation_unTypedArguments() { |
| 493 String code = r''' | 493 String code = r''' |
| 494 class Mapper<F, T> { | 494 class Mapper<F, T> { |
| 495 T map(T mapper(F x)) => mapper(null); | 495 T map(T mapper(F x)) => mapper(null); |
| 496 } | 496 } |
| 497 | 497 |
| 498 void main () { | 498 void main () { |
| 499 (new Mapper<int, String>().map)((x) => null); | 499 (new Mapper<int, String>().map)((x) => null); |
| 500 (new Mapper<int, String>().map)((x) => "hello"); | 500 (new Mapper<int, String>().map)((x) => "hello"); |
| 501 (new Mapper<int, String>().map)((x) => "hello"); | 501 (new Mapper<int, String>().map)((x) => "hello"); |
| 502 (new Mapper<int, String>().map)((x) => 3); | 502 (new Mapper<int, String>().map)((x) => 3); |
| 503 (new Mapper<int, String>().map)((x) {return 3;}); | 503 (new Mapper<int, String>().map)((x) {return 3;}); |
| 504 } | 504 } |
| 505 '''; | 505 '''; |
| 506 CompilationUnit unit = resolveSource(code); | 506 CompilationUnit unit = resolveSource(code); |
| 507 List<Statement> statements = | 507 List<Statement> statements = |
| 508 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 508 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 509 DartType literal(int i) { | 509 DartType literal(int i) { |
| 510 ExpressionStatement stmt = statements[i]; | 510 ExpressionStatement stmt = statements[i]; |
| 511 FunctionExpressionInvocation invk = stmt.expression; | 511 FunctionExpressionInvocation invk = stmt.expression; |
| 512 FunctionExpression exp = invk.argumentList.arguments[0]; | 512 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 513 return exp.element.type; | 513 return exp.element.type; |
| 514 } | 514 } |
| 515 _isFunction2Of(_isInt, _isString)(literal(0)); | 515 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 516 _isFunction2Of(_isInt, _isString)(literal(1)); | 516 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 517 _isFunction2Of(_isInt, _isString)(literal(2)); | 517 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 518 _isFunction2Of(_isInt, _isInt)(literal(3)); | 518 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 519 _isFunction2Of(_isInt, _isString)(literal(4)); | 519 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void test_functionLiteral_functionInvocation_typedArguments() { | 522 void test_functionLiteral_functionInvocation_typedArguments() { |
| 523 String code = r''' | 523 String code = r''' |
| 524 String map(String mapper(int x)) => mapper(null); | 524 String map(String mapper(int x)) => mapper(null); |
| 525 | 525 |
| 526 void main () { | 526 void main () { |
| 527 map((int x) => null); | 527 map((int x) => null); |
| 528 map((int x) => "hello"); | 528 map((int x) => "hello"); |
| 529 map((String x) => "hello"); | 529 map((String x) => "hello"); |
| 530 map((int x) => 3); | 530 map((int x) => 3); |
| 531 map((int x) {return 3;}); | 531 map((int x) {return 3;}); |
| 532 } | 532 } |
| 533 '''; | 533 '''; |
| 534 CompilationUnit unit = resolveSource(code); | 534 CompilationUnit unit = resolveSource(code); |
| 535 List<Statement> statements = | 535 List<Statement> statements = |
| 536 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 536 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 537 DartType literal(int i) { | 537 DartType literal(int i) { |
| 538 ExpressionStatement stmt = statements[i]; | 538 ExpressionStatement stmt = statements[i]; |
| 539 MethodInvocation invk = stmt.expression; | 539 MethodInvocation invk = stmt.expression; |
| 540 FunctionExpression exp = invk.argumentList.arguments[0]; | 540 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 541 return exp.element.type; | 541 return exp.element.type; |
| 542 } | 542 } |
| 543 _isFunction2Of(_isInt, _isString)(literal(0)); | 543 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 544 _isFunction2Of(_isInt, _isString)(literal(1)); | 544 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 545 _isFunction2Of(_isString, _isString)(literal(2)); | 545 _isFunction2Of(_isString, _isString)(literal(2)); |
| 546 _isFunction2Of(_isInt, _isInt)(literal(3)); | 546 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 547 _isFunction2Of(_isInt, _isString)(literal(4)); | 547 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 548 } | 548 } |
| 549 | 549 |
| 550 void test_functionLiteral_functionInvocation_unTypedArguments() { | 550 void test_functionLiteral_functionInvocation_unTypedArguments() { |
| 551 String code = r''' | 551 String code = r''' |
| 552 String map(String mapper(int x)) => mapper(null); | 552 String map(String mapper(int x)) => mapper(null); |
| 553 | 553 |
| 554 void main () { | 554 void main () { |
| 555 map((x) => null); | 555 map((x) => null); |
| 556 map((x) => "hello"); | 556 map((x) => "hello"); |
| 557 map((x) => "hello"); | 557 map((x) => "hello"); |
| 558 map((x) => 3); | 558 map((x) => 3); |
| 559 map((x) {return 3;}); | 559 map((x) {return 3;}); |
| 560 } | 560 } |
| 561 '''; | 561 '''; |
| 562 CompilationUnit unit = resolveSource(code); | 562 CompilationUnit unit = resolveSource(code); |
| 563 List<Statement> statements = | 563 List<Statement> statements = |
| 564 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 564 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 565 DartType literal(int i) { | 565 DartType literal(int i) { |
| 566 ExpressionStatement stmt = statements[i]; | 566 ExpressionStatement stmt = statements[i]; |
| 567 MethodInvocation invk = stmt.expression; | 567 MethodInvocation invk = stmt.expression; |
| 568 FunctionExpression exp = invk.argumentList.arguments[0]; | 568 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 569 return exp.element.type; | 569 return exp.element.type; |
| 570 } | 570 } |
| 571 _isFunction2Of(_isInt, _isString)(literal(0)); | 571 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 572 _isFunction2Of(_isInt, _isString)(literal(1)); | 572 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 573 _isFunction2Of(_isInt, _isString)(literal(2)); | 573 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 574 _isFunction2Of(_isInt, _isInt)(literal(3)); | 574 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 575 _isFunction2Of(_isInt, _isString)(literal(4)); | 575 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 576 } | 576 } |
| 577 | 577 |
| 578 void test_functionLiteral_methodInvocation_typedArguments() { | 578 void test_functionLiteral_methodInvocation_typedArguments() { |
| 579 String code = r''' | 579 String code = r''' |
| 580 class Mapper<F, T> { | 580 class Mapper<F, T> { |
| 581 T map(T mapper(F x)) => mapper(null); | 581 T map(T mapper(F x)) => mapper(null); |
| 582 } | 582 } |
| 583 | 583 |
| 584 void main () { | 584 void main () { |
| 585 new Mapper<int, String>().map((int x) => null); | 585 new Mapper<int, String>().map((int x) => null); |
| 586 new Mapper<int, String>().map((int x) => "hello"); | 586 new Mapper<int, String>().map((int x) => "hello"); |
| 587 new Mapper<int, String>().map((String x) => "hello"); | 587 new Mapper<int, String>().map((String x) => "hello"); |
| 588 new Mapper<int, String>().map((int x) => 3); | 588 new Mapper<int, String>().map((int x) => 3); |
| 589 new Mapper<int, String>().map((int x) {return 3;}); | 589 new Mapper<int, String>().map((int x) {return 3;}); |
| 590 } | 590 } |
| 591 '''; | 591 '''; |
| 592 CompilationUnit unit = resolveSource(code); | 592 CompilationUnit unit = resolveSource(code); |
| 593 List<Statement> statements = | 593 List<Statement> statements = |
| 594 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 594 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 595 DartType literal(int i) { | 595 DartType literal(int i) { |
| 596 ExpressionStatement stmt = statements[i]; | 596 ExpressionStatement stmt = statements[i]; |
| 597 MethodInvocation invk = stmt.expression; | 597 MethodInvocation invk = stmt.expression; |
| 598 FunctionExpression exp = invk.argumentList.arguments[0]; | 598 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 599 return exp.element.type; | 599 return exp.element.type; |
| 600 } | 600 } |
| 601 _isFunction2Of(_isInt, _isString)(literal(0)); | 601 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 602 _isFunction2Of(_isInt, _isString)(literal(1)); | 602 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 603 _isFunction2Of(_isString, _isString)(literal(2)); | 603 _isFunction2Of(_isString, _isString)(literal(2)); |
| 604 _isFunction2Of(_isInt, _isInt)(literal(3)); | 604 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 605 _isFunction2Of(_isInt, _isString)(literal(4)); | 605 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 606 } | 606 } |
| 607 | 607 |
| 608 void test_functionLiteral_methodInvocation_unTypedArguments() { | 608 void test_functionLiteral_methodInvocation_unTypedArguments() { |
| 609 String code = r''' | 609 String code = r''' |
| 610 class Mapper<F, T> { | 610 class Mapper<F, T> { |
| 611 T map(T mapper(F x)) => mapper(null); | 611 T map(T mapper(F x)) => mapper(null); |
| 612 } | 612 } |
| 613 | 613 |
| 614 void main () { | 614 void main () { |
| 615 new Mapper<int, String>().map((x) => null); | 615 new Mapper<int, String>().map((x) => null); |
| 616 new Mapper<int, String>().map((x) => "hello"); | 616 new Mapper<int, String>().map((x) => "hello"); |
| 617 new Mapper<int, String>().map((x) => "hello"); | 617 new Mapper<int, String>().map((x) => "hello"); |
| 618 new Mapper<int, String>().map((x) => 3); | 618 new Mapper<int, String>().map((x) => 3); |
| 619 new Mapper<int, String>().map((x) {return 3;}); | 619 new Mapper<int, String>().map((x) {return 3;}); |
| 620 } | 620 } |
| 621 '''; | 621 '''; |
| 622 CompilationUnit unit = resolveSource(code); | 622 CompilationUnit unit = resolveSource(code); |
| 623 List<Statement> statements = | 623 List<Statement> statements = |
| 624 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 624 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 625 DartType literal(int i) { | 625 DartType literal(int i) { |
| 626 ExpressionStatement stmt = statements[i]; | 626 ExpressionStatement stmt = statements[i]; |
| 627 MethodInvocation invk = stmt.expression; | 627 MethodInvocation invk = stmt.expression; |
| 628 FunctionExpression exp = invk.argumentList.arguments[0]; | 628 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 629 return exp.element.type; | 629 return exp.element.type; |
| 630 } | 630 } |
| 631 _isFunction2Of(_isInt, _isString)(literal(0)); | 631 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 632 _isFunction2Of(_isInt, _isString)(literal(1)); | 632 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 633 _isFunction2Of(_isInt, _isString)(literal(2)); | 633 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 634 _isFunction2Of(_isInt, _isInt)(literal(3)); | 634 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 635 _isFunction2Of(_isInt, _isString)(literal(4)); | 635 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 636 } | 636 } |
| 637 | 637 |
| 638 void test_functionLiteral_unTypedArgument_propagation() { | 638 void test_functionLiteral_unTypedArgument_propagation() { |
| 639 String code = r''' | 639 String code = r''' |
| 640 typedef T Function2<S, T>(S x); | 640 typedef T Function2<S, T>(S x); |
| 641 | 641 |
| 642 void main () { | 642 void main () { |
| 643 Function2<int, int> l0 = (x) => x; | 643 Function2<int, int> l0 = (x) => x; |
| 644 Function2<int, int> l1 = (x) => x+1; | 644 Function2<int, int> l1 = (x) => x+1; |
| 645 Function2<int, String> l2 = (x) => x; | 645 Function2<int, String> l2 = (x) => x; |
| 646 Function2<int, String> l3 = (x) => x.toLowerCase(); | 646 Function2<int, String> l3 = (x) => x.toLowerCase(); |
| 647 Function2<String, String> l4 = (x) => x.toLowerCase(); | 647 Function2<String, String> l4 = (x) => x.toLowerCase(); |
| 648 } | 648 } |
| 649 '''; | 649 '''; |
| 650 CompilationUnit unit = resolveSource(code); | 650 CompilationUnit unit = resolveSource(code); |
| 651 List<Statement> statements = | 651 List<Statement> statements = |
| 652 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 652 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 653 Expression functionReturnValue(int i) { | 653 Expression functionReturnValue(int i) { |
| 654 VariableDeclarationStatement stmt = statements[i]; | 654 VariableDeclarationStatement stmt = statements[i]; |
| 655 VariableDeclaration decl = stmt.variables.variables[0]; | 655 VariableDeclaration decl = stmt.variables.variables[0]; |
| 656 FunctionExpression exp = decl.initializer; | 656 FunctionExpression exp = decl.initializer; |
| 657 FunctionBody body = exp.body; | 657 FunctionBody body = exp.body; |
| 658 if (body is ExpressionFunctionBody) { | 658 if (body is ExpressionFunctionBody) { |
| 659 return body.expression; | 659 return body.expression; |
| 660 } else { | 660 } else { |
| 661 Statement stmt = (body as BlockFunctionBody).block.statements[0]; | 661 Statement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 662 return (stmt as ReturnStatement).expression; | 662 return (stmt as ReturnStatement).expression; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 assertion(exp.staticType); | 787 assertion(exp.staticType); |
| 788 | 788 |
| 789 Element elementA = AstFinder.getClass(unit, "A").element; | 789 Element elementA = AstFinder.getClass(unit, "A").element; |
| 790 Element elementB = AstFinder.getClass(unit, "B").element; | 790 Element elementB = AstFinder.getClass(unit, "B").element; |
| 791 Element elementC = AstFinder.getClass(unit, "C").element; | 791 Element elementC = AstFinder.getClass(unit, "C").element; |
| 792 Element elementD = AstFinder.getClass(unit, "D").element; | 792 Element elementD = AstFinder.getClass(unit, "D").element; |
| 793 Element elementE = AstFinder.getClass(unit, "E").element; | 793 Element elementE = AstFinder.getClass(unit, "E").element; |
| 794 Element elementF = AstFinder.getClass(unit, "F").element; | 794 Element elementF = AstFinder.getClass(unit, "F").element; |
| 795 | 795 |
| 796 AsserterBuilder<List<Asserter<DartType>>, DartType> assertAOf = | 796 AsserterBuilder<List<Asserter<DartType>>, DartType> assertAOf = |
| 797 _isInstantiationOf(_hasElement(elementA)); | 797 _isInstantiationOf(_hasElement(elementA)); |
| 798 AsserterBuilder<List<Asserter<DartType>>, DartType> assertBOf = | 798 AsserterBuilder<List<Asserter<DartType>>, DartType> assertBOf = |
| 799 _isInstantiationOf(_hasElement(elementB)); | 799 _isInstantiationOf(_hasElement(elementB)); |
| 800 AsserterBuilder<List<Asserter<DartType>>, DartType> assertCOf = | 800 AsserterBuilder<List<Asserter<DartType>>, DartType> assertCOf = |
| 801 _isInstantiationOf(_hasElement(elementC)); | 801 _isInstantiationOf(_hasElement(elementC)); |
| 802 AsserterBuilder<List<Asserter<DartType>>, DartType> assertDOf = | 802 AsserterBuilder<List<Asserter<DartType>>, DartType> assertDOf = |
| 803 _isInstantiationOf(_hasElement(elementD)); | 803 _isInstantiationOf(_hasElement(elementD)); |
| 804 AsserterBuilder<List<Asserter<DartType>>, DartType> assertEOf = | 804 AsserterBuilder<List<Asserter<DartType>>, DartType> assertEOf = |
| 805 _isInstantiationOf(_hasElement(elementE)); | 805 _isInstantiationOf(_hasElement(elementE)); |
| 806 AsserterBuilder<List<Asserter<DartType>>, DartType> assertFOf = | 806 AsserterBuilder<List<Asserter<DartType>>, DartType> assertFOf = |
| 807 _isInstantiationOf(_hasElement(elementF)); | 807 _isInstantiationOf(_hasElement(elementF)); |
| 808 | 808 |
| 809 { | 809 { |
| 810 List<Statement> statements = | 810 List<Statement> statements = |
| 811 AstFinder.getStatementsInTopLevelFunction(unit, "test0"); | 811 AstFinder.getStatementsInTopLevelFunction(unit, "test0"); |
| 812 | 812 |
| 813 hasType(assertAOf([_isInt, _isString]), rhs(statements[0])); | 813 hasType(assertAOf([_isInt, _isString]), rhs(statements[0])); |
| 814 hasType(assertAOf([_isInt, _isString]), rhs(statements[0])); | 814 hasType(assertAOf([_isInt, _isString]), rhs(statements[0])); |
| 815 hasType(assertAOf([_isInt, _isString]), rhs(statements[1])); | 815 hasType(assertAOf([_isInt, _isString]), rhs(statements[1])); |
| 816 hasType(assertAOf([_isInt, _isString]), rhs(statements[2])); | 816 hasType(assertAOf([_isInt, _isString]), rhs(statements[2])); |
| 817 hasType(assertAOf([_isInt, _isString]), rhs(statements[3])); | 817 hasType(assertAOf([_isInt, _isString]), rhs(statements[3])); |
| 818 hasType(assertAOf([_isInt, _isDynamic]), rhs(statements[4])); | 818 hasType(assertAOf([_isInt, _isDynamic]), rhs(statements[4])); |
| 819 hasType(assertAOf([_isDynamic, _isDynamic]), rhs(statements[5])); | 819 hasType(assertAOf([_isDynamic, _isDynamic]), rhs(statements[5])); |
| 820 } | 820 } |
| 821 | 821 |
| 822 { | 822 { |
| 823 List<Statement> statements = | 823 List<Statement> statements = |
| 824 AstFinder.getStatementsInTopLevelFunction(unit, "test1"); | 824 AstFinder.getStatementsInTopLevelFunction(unit, "test1"); |
| 825 hasType(assertAOf([_isInt, _isString]), rhs(statements[0])); | 825 hasType(assertAOf([_isInt, _isString]), rhs(statements[0])); |
| 826 hasType(assertAOf([_isInt, _isString]), rhs(statements[1])); | 826 hasType(assertAOf([_isInt, _isString]), rhs(statements[1])); |
| 827 } | 827 } |
| 828 | 828 |
| 829 { | 829 { |
| 830 List<Statement> statements = | 830 List<Statement> statements = |
| 831 AstFinder.getStatementsInTopLevelFunction(unit, "test2"); | 831 AstFinder.getStatementsInTopLevelFunction(unit, "test2"); |
| 832 hasType(assertBOf([_isString, _isInt]), rhs(statements[0])); | 832 hasType(assertBOf([_isString, _isInt]), rhs(statements[0])); |
| 833 hasType(assertBOf([_isString, _isInt]), rhs(statements[1])); | 833 hasType(assertBOf([_isString, _isInt]), rhs(statements[1])); |
| 834 hasType(assertBOf([_isString, _isInt]), rhs(statements[2])); | 834 hasType(assertBOf([_isString, _isInt]), rhs(statements[2])); |
| 835 hasType(assertBOf([_isString, _isInt]), rhs(statements[3])); | 835 hasType(assertBOf([_isString, _isInt]), rhs(statements[3])); |
| 836 hasType(assertBOf([_isString, _isDynamic]), rhs(statements[4])); | 836 hasType(assertBOf([_isString, _isDynamic]), rhs(statements[4])); |
| 837 hasType(assertBOf([_isDynamic, _isDynamic]), rhs(statements[5])); | 837 hasType(assertBOf([_isDynamic, _isDynamic]), rhs(statements[5])); |
| 838 } | 838 } |
| 839 | 839 |
| 840 { | 840 { |
| 841 List<Statement> statements = | 841 List<Statement> statements = |
| 842 AstFinder.getStatementsInTopLevelFunction(unit, "test3"); | 842 AstFinder.getStatementsInTopLevelFunction(unit, "test3"); |
| 843 hasType(assertBOf([_isString, _isInt]), rhs(statements[0])); | 843 hasType(assertBOf([_isString, _isInt]), rhs(statements[0])); |
| 844 hasType(assertBOf([_isString, _isInt]), rhs(statements[1])); | 844 hasType(assertBOf([_isString, _isInt]), rhs(statements[1])); |
| 845 } | 845 } |
| 846 | 846 |
| 847 { | 847 { |
| 848 List<Statement> statements = | 848 List<Statement> statements = |
| 849 AstFinder.getStatementsInTopLevelFunction(unit, "test4"); | 849 AstFinder.getStatementsInTopLevelFunction(unit, "test4"); |
| 850 hasType(assertCOf([_isInt]), rhs(statements[0])); | 850 hasType(assertCOf([_isInt]), rhs(statements[0])); |
| 851 hasType(assertCOf([_isInt]), rhs(statements[1])); | 851 hasType(assertCOf([_isInt]), rhs(statements[1])); |
| 852 hasType(assertCOf([_isInt]), rhs(statements[2])); | 852 hasType(assertCOf([_isInt]), rhs(statements[2])); |
| 853 hasType(assertCOf([_isInt]), rhs(statements[3])); | 853 hasType(assertCOf([_isInt]), rhs(statements[3])); |
| 854 hasType(assertCOf([_isDynamic]), rhs(statements[4])); | 854 hasType(assertCOf([_isDynamic]), rhs(statements[4])); |
| 855 hasType(assertCOf([_isDynamic]), rhs(statements[5])); | 855 hasType(assertCOf([_isDynamic]), rhs(statements[5])); |
| 856 } | 856 } |
| 857 | 857 |
| 858 { | 858 { |
| 859 List<Statement> statements = | 859 List<Statement> statements = |
| 860 AstFinder.getStatementsInTopLevelFunction(unit, "test5"); | 860 AstFinder.getStatementsInTopLevelFunction(unit, "test5"); |
| 861 hasType(assertCOf([_isInt]), rhs(statements[0])); | 861 hasType(assertCOf([_isInt]), rhs(statements[0])); |
| 862 hasType(assertCOf([_isInt]), rhs(statements[1])); | 862 hasType(assertCOf([_isInt]), rhs(statements[1])); |
| 863 } | 863 } |
| 864 | 864 |
| 865 { | 865 { |
| 866 // The first type parameter is not constrained by the | 866 // The first type parameter is not constrained by the |
| 867 // context. We could choose a tighter type, but currently | 867 // context. We could choose a tighter type, but currently |
| 868 // we just use dynamic. | 868 // we just use dynamic. |
| 869 List<Statement> statements = | 869 List<Statement> statements = |
| 870 AstFinder.getStatementsInTopLevelFunction(unit, "test6"); | 870 AstFinder.getStatementsInTopLevelFunction(unit, "test6"); |
| 871 hasType(assertDOf([_isDynamic, _isString]), rhs(statements[0])); | 871 hasType(assertDOf([_isDynamic, _isString]), rhs(statements[0])); |
| 872 hasType(assertDOf([_isDynamic, _isString]), rhs(statements[1])); | 872 hasType(assertDOf([_isDynamic, _isString]), rhs(statements[1])); |
| 873 hasType(assertDOf([_isInt, _isString]), rhs(statements[2])); | 873 hasType(assertDOf([_isInt, _isString]), rhs(statements[2])); |
| 874 hasType(assertDOf([_isString, _isString]), rhs(statements[3])); | 874 hasType(assertDOf([_isString, _isString]), rhs(statements[3])); |
| 875 hasType(assertDOf([_isNum, _isDynamic]), rhs(statements[4])); | 875 hasType(assertDOf([_isNum, _isDynamic]), rhs(statements[4])); |
| 876 hasType(assertDOf([_isDynamic, _isDynamic]), rhs(statements[5])); | 876 hasType(assertDOf([_isDynamic, _isDynamic]), rhs(statements[5])); |
| 877 } | 877 } |
| 878 | 878 |
| 879 { | 879 { |
| 880 List<Statement> statements = | 880 List<Statement> statements = |
| 881 AstFinder.getStatementsInTopLevelFunction(unit, "test7"); | 881 AstFinder.getStatementsInTopLevelFunction(unit, "test7"); |
| 882 hasType(assertDOf([_isDynamic, _isString]), rhs(statements[0])); | 882 hasType(assertDOf([_isDynamic, _isString]), rhs(statements[0])); |
| 883 hasType(assertDOf([_isDynamic, _isString]), rhs(statements[1])); | 883 hasType(assertDOf([_isDynamic, _isString]), rhs(statements[1])); |
| 884 } | 884 } |
| 885 | 885 |
| 886 { | 886 { |
| 887 List<Statement> statements = | 887 List<Statement> statements = |
| 888 AstFinder.getStatementsInTopLevelFunction(unit, "test8"); | 888 AstFinder.getStatementsInTopLevelFunction(unit, "test8"); |
| 889 hasType(assertEOf([_isDynamic, _isDynamic]), rhs(statements[0])); | 889 hasType(assertEOf([_isDynamic, _isDynamic]), rhs(statements[0])); |
| 890 } | 890 } |
| 891 | 891 |
| 892 { | 892 { |
| 893 List<Statement> statements = | 893 List<Statement> statements = |
| 894 AstFinder.getStatementsInTopLevelFunction(unit, "test9"); | 894 AstFinder.getStatementsInTopLevelFunction(unit, "test9"); |
| 895 hasType(assertFOf([_isInt, _isString]), rhs(statements[0])); | 895 hasType(assertFOf([_isInt, _isString]), rhs(statements[0])); |
| 896 hasType(assertFOf([_isInt, _isString]), rhs(statements[1])); | 896 hasType(assertFOf([_isInt, _isString]), rhs(statements[1])); |
| 897 hasType(assertFOf([_isInt, _isString]), rhs(statements[2])); | 897 hasType(assertFOf([_isInt, _isString]), rhs(statements[2])); |
| 898 hasType(assertFOf([_isInt, _isString]), rhs(statements[3])); | 898 hasType(assertFOf([_isInt, _isString]), rhs(statements[3])); |
| 899 hasType(assertFOf([_isInt, _isString]), rhs(statements[4])); | 899 hasType(assertFOf([_isInt, _isString]), rhs(statements[4])); |
| 900 hasType(assertFOf([_isInt, _isString]), rhs(statements[5])); | 900 hasType(assertFOf([_isInt, _isString]), rhs(statements[5])); |
| 901 } | 901 } |
| 902 } | 902 } |
| 903 | 903 |
| 904 void test_listLiteral_nested() { | 904 void test_listLiteral_nested() { |
| 905 String code = r''' | 905 String code = r''' |
| 906 void main () { | 906 void main () { |
| 907 List<List<int>> l0 = [[]]; | 907 List<List<int>> l0 = [[]]; |
| 908 Iterable<List<int>> l1 = [[3]]; | 908 Iterable<List<int>> l1 = [[3]]; |
| 909 Iterable<List<int>> l2 = [[3], [4]]; | 909 Iterable<List<int>> l2 = [[3], [4]]; |
| 910 List<List<int>> l3 = [["hello", 3], []]; | 910 List<List<int>> l3 = [["hello", 3], []]; |
| 911 } | 911 } |
| 912 '''; | 912 '''; |
| 913 CompilationUnit unit = resolveSource(code); | 913 CompilationUnit unit = resolveSource(code); |
| 914 List<Statement> statements = | 914 List<Statement> statements = |
| 915 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 915 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 916 ListLiteral literal(int i) { | 916 ListLiteral literal(int i) { |
| 917 VariableDeclarationStatement stmt = statements[i]; | 917 VariableDeclarationStatement stmt = statements[i]; |
| 918 VariableDeclaration decl = stmt.variables.variables[0]; | 918 VariableDeclaration decl = stmt.variables.variables[0]; |
| 919 ListLiteral exp = decl.initializer; | 919 ListLiteral exp = decl.initializer; |
| 920 return exp; | 920 return exp; |
| 921 } | 921 } |
| 922 | 922 |
| 923 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 923 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 924 Asserter<InterfaceType> assertListOfListOfInt = _isListOf(assertListOfInt); | 924 Asserter<InterfaceType> assertListOfListOfInt = _isListOf(assertListOfInt); |
| 925 | 925 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 937 String code = r''' | 937 String code = r''' |
| 938 void main () { | 938 void main () { |
| 939 List<int> l0 = []; | 939 List<int> l0 = []; |
| 940 List<int> l1 = [3]; | 940 List<int> l1 = [3]; |
| 941 List<int> l2 = ["hello"]; | 941 List<int> l2 = ["hello"]; |
| 942 List<int> l3 = ["hello", 3]; | 942 List<int> l3 = ["hello", 3]; |
| 943 } | 943 } |
| 944 '''; | 944 '''; |
| 945 CompilationUnit unit = resolveSource(code); | 945 CompilationUnit unit = resolveSource(code); |
| 946 List<Statement> statements = | 946 List<Statement> statements = |
| 947 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 947 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 948 DartType literal(int i) { | 948 DartType literal(int i) { |
| 949 VariableDeclarationStatement stmt = statements[i]; | 949 VariableDeclarationStatement stmt = statements[i]; |
| 950 VariableDeclaration decl = stmt.variables.variables[0]; | 950 VariableDeclaration decl = stmt.variables.variables[0]; |
| 951 ListLiteral exp = decl.initializer; | 951 ListLiteral exp = decl.initializer; |
| 952 return exp.staticType; | 952 return exp.staticType; |
| 953 } | 953 } |
| 954 | 954 |
| 955 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 955 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 956 | 956 |
| 957 assertListOfInt(literal(0)); | 957 assertListOfInt(literal(0)); |
| 958 assertListOfInt(literal(1)); | 958 assertListOfInt(literal(1)); |
| 959 assertListOfInt(literal(2)); | 959 assertListOfInt(literal(2)); |
| 960 assertListOfInt(literal(3)); | 960 assertListOfInt(literal(3)); |
| 961 } | 961 } |
| 962 | 962 |
| 963 void test_listLiteral_simple_const() { | 963 void test_listLiteral_simple_const() { |
| 964 String code = r''' | 964 String code = r''' |
| 965 void main () { | 965 void main () { |
| 966 const List<int> c0 = const []; | 966 const List<int> c0 = const []; |
| 967 const List<int> c1 = const [3]; | 967 const List<int> c1 = const [3]; |
| 968 const List<int> c2 = const ["hello"]; | 968 const List<int> c2 = const ["hello"]; |
| 969 const List<int> c3 = const ["hello", 3]; | 969 const List<int> c3 = const ["hello", 3]; |
| 970 } | 970 } |
| 971 '''; | 971 '''; |
| 972 CompilationUnit unit = resolveSource(code); | 972 CompilationUnit unit = resolveSource(code); |
| 973 List<Statement> statements = | 973 List<Statement> statements = |
| 974 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 974 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 975 DartType literal(int i) { | 975 DartType literal(int i) { |
| 976 VariableDeclarationStatement stmt = statements[i]; | 976 VariableDeclarationStatement stmt = statements[i]; |
| 977 VariableDeclaration decl = stmt.variables.variables[0]; | 977 VariableDeclaration decl = stmt.variables.variables[0]; |
| 978 ListLiteral exp = decl.initializer; | 978 ListLiteral exp = decl.initializer; |
| 979 return exp.staticType; | 979 return exp.staticType; |
| 980 } | 980 } |
| 981 | 981 |
| 982 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 982 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 983 | 983 |
| 984 assertListOfInt(literal(0)); | 984 assertListOfInt(literal(0)); |
| 985 assertListOfInt(literal(1)); | 985 assertListOfInt(literal(1)); |
| 986 assertListOfInt(literal(2)); | 986 assertListOfInt(literal(2)); |
| 987 assertListOfInt(literal(3)); | 987 assertListOfInt(literal(3)); |
| 988 } | 988 } |
| 989 | 989 |
| 990 void test_listLiteral_simple_disabled() { | 990 void test_listLiteral_simple_disabled() { |
| 991 String code = r''' | 991 String code = r''' |
| 992 void main () { | 992 void main () { |
| 993 List<int> l0 = <num>[]; | 993 List<int> l0 = <num>[]; |
| 994 List<int> l1 = <num>[3]; | 994 List<int> l1 = <num>[3]; |
| 995 List<int> l2 = <String>["hello"]; | 995 List<int> l2 = <String>["hello"]; |
| 996 List<int> l3 = <dynamic>["hello", 3]; | 996 List<int> l3 = <dynamic>["hello", 3]; |
| 997 } | 997 } |
| 998 '''; | 998 '''; |
| 999 CompilationUnit unit = resolveSource(code); | 999 CompilationUnit unit = resolveSource(code); |
| 1000 List<Statement> statements = | 1000 List<Statement> statements = |
| 1001 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1001 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1002 DartType literal(int i) { | 1002 DartType literal(int i) { |
| 1003 VariableDeclarationStatement stmt = statements[i]; | 1003 VariableDeclarationStatement stmt = statements[i]; |
| 1004 VariableDeclaration decl = stmt.variables.variables[0]; | 1004 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1005 ListLiteral exp = decl.initializer; | 1005 ListLiteral exp = decl.initializer; |
| 1006 return exp.staticType; | 1006 return exp.staticType; |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 _isListOf(_isNum)(literal(0)); | 1009 _isListOf(_isNum)(literal(0)); |
| 1010 _isListOf(_isNum)(literal(1)); | 1010 _isListOf(_isNum)(literal(1)); |
| 1011 _isListOf(_isString)(literal(2)); | 1011 _isListOf(_isString)(literal(2)); |
| 1012 _isListOf(_isDynamic)(literal(3)); | 1012 _isListOf(_isDynamic)(literal(3)); |
| 1013 } | 1013 } |
| 1014 | 1014 |
| 1015 void test_listLiteral_simple_subtype() { | 1015 void test_listLiteral_simple_subtype() { |
| 1016 String code = r''' | 1016 String code = r''' |
| 1017 void main () { | 1017 void main () { |
| 1018 Iterable<int> l0 = []; | 1018 Iterable<int> l0 = []; |
| 1019 Iterable<int> l1 = [3]; | 1019 Iterable<int> l1 = [3]; |
| 1020 Iterable<int> l2 = ["hello"]; | 1020 Iterable<int> l2 = ["hello"]; |
| 1021 Iterable<int> l3 = ["hello", 3]; | 1021 Iterable<int> l3 = ["hello", 3]; |
| 1022 } | 1022 } |
| 1023 '''; | 1023 '''; |
| 1024 CompilationUnit unit = resolveSource(code); | 1024 CompilationUnit unit = resolveSource(code); |
| 1025 List<Statement> statements = | 1025 List<Statement> statements = |
| 1026 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1026 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1027 DartType literal(int i) { | 1027 DartType literal(int i) { |
| 1028 VariableDeclarationStatement stmt = statements[i]; | 1028 VariableDeclarationStatement stmt = statements[i]; |
| 1029 VariableDeclaration decl = stmt.variables.variables[0]; | 1029 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1030 ListLiteral exp = decl.initializer; | 1030 ListLiteral exp = decl.initializer; |
| 1031 return exp.staticType; | 1031 return exp.staticType; |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); | 1034 Asserter<InterfaceType> assertListOfInt = _isListOf(_isInt); |
| 1035 | 1035 |
| 1036 assertListOfInt(literal(0)); | 1036 assertListOfInt(literal(0)); |
| 1037 assertListOfInt(literal(1)); | 1037 assertListOfInt(literal(1)); |
| 1038 assertListOfInt(literal(2)); | 1038 assertListOfInt(literal(2)); |
| 1039 assertListOfInt(literal(3)); | 1039 assertListOfInt(literal(3)); |
| 1040 } | 1040 } |
| 1041 | 1041 |
| 1042 void test_mapLiteral_nested() { | 1042 void test_mapLiteral_nested() { |
| 1043 String code = r''' | 1043 String code = r''' |
| 1044 void main () { | 1044 void main () { |
| 1045 Map<int, List<String>> l0 = {}; | 1045 Map<int, List<String>> l0 = {}; |
| 1046 Map<int, List<String>> l1 = {3: ["hello"]}; | 1046 Map<int, List<String>> l1 = {3: ["hello"]}; |
| 1047 Map<int, List<String>> l2 = {"hello": ["hello"]}; | 1047 Map<int, List<String>> l2 = {"hello": ["hello"]}; |
| 1048 Map<int, List<String>> l3 = {3: [3]}; | 1048 Map<int, List<String>> l3 = {3: [3]}; |
| 1049 Map<int, List<String>> l4 = {3:["hello"], "hello": [3]}; | 1049 Map<int, List<String>> l4 = {3:["hello"], "hello": [3]}; |
| 1050 } | 1050 } |
| 1051 '''; | 1051 '''; |
| 1052 CompilationUnit unit = resolveSource(code); | 1052 CompilationUnit unit = resolveSource(code); |
| 1053 List<Statement> statements = | 1053 List<Statement> statements = |
| 1054 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1054 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1055 MapLiteral literal(int i) { | 1055 MapLiteral literal(int i) { |
| 1056 VariableDeclarationStatement stmt = statements[i]; | 1056 VariableDeclarationStatement stmt = statements[i]; |
| 1057 VariableDeclaration decl = stmt.variables.variables[0]; | 1057 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1058 MapLiteral exp = decl.initializer; | 1058 MapLiteral exp = decl.initializer; |
| 1059 return exp; | 1059 return exp; |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); | 1062 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); |
| 1063 Asserter<InterfaceType> assertMapOfIntToListOfString = | 1063 Asserter<InterfaceType> assertMapOfIntToListOfString = |
| 1064 _isMapOf(_isInt, assertListOfString); | 1064 _isMapOf(_isInt, assertListOfString); |
| 1065 | 1065 |
| 1066 assertMapOfIntToListOfString(literal(0).staticType); | 1066 assertMapOfIntToListOfString(literal(0).staticType); |
| 1067 assertMapOfIntToListOfString(literal(1).staticType); | 1067 assertMapOfIntToListOfString(literal(1).staticType); |
| 1068 assertMapOfIntToListOfString(literal(2).staticType); | 1068 assertMapOfIntToListOfString(literal(2).staticType); |
| 1069 assertMapOfIntToListOfString(literal(3).staticType); | 1069 assertMapOfIntToListOfString(literal(3).staticType); |
| 1070 assertMapOfIntToListOfString(literal(4).staticType); | 1070 assertMapOfIntToListOfString(literal(4).staticType); |
| 1071 | 1071 |
| 1072 assertListOfString(literal(1).entries[0].value.staticType); | 1072 assertListOfString(literal(1).entries[0].value.staticType); |
| 1073 assertListOfString(literal(2).entries[0].value.staticType); | 1073 assertListOfString(literal(2).entries[0].value.staticType); |
| 1074 assertListOfString(literal(3).entries[0].value.staticType); | 1074 assertListOfString(literal(3).entries[0].value.staticType); |
| 1075 assertListOfString(literal(4).entries[0].value.staticType); | 1075 assertListOfString(literal(4).entries[0].value.staticType); |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 void test_mapLiteral_simple() { | 1078 void test_mapLiteral_simple() { |
| 1079 String code = r''' | 1079 String code = r''' |
| 1080 void main () { | 1080 void main () { |
| 1081 Map<int, String> l0 = {}; | 1081 Map<int, String> l0 = {}; |
| 1082 Map<int, String> l1 = {3: "hello"}; | 1082 Map<int, String> l1 = {3: "hello"}; |
| 1083 Map<int, String> l2 = {"hello": "hello"}; | 1083 Map<int, String> l2 = {"hello": "hello"}; |
| 1084 Map<int, String> l3 = {3: 3}; | 1084 Map<int, String> l3 = {3: 3}; |
| 1085 Map<int, String> l4 = {3:"hello", "hello": 3}; | 1085 Map<int, String> l4 = {3:"hello", "hello": 3}; |
| 1086 } | 1086 } |
| 1087 '''; | 1087 '''; |
| 1088 CompilationUnit unit = resolveSource(code); | 1088 CompilationUnit unit = resolveSource(code); |
| 1089 List<Statement> statements = | 1089 List<Statement> statements = |
| 1090 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1090 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1091 DartType literal(int i) { | 1091 DartType literal(int i) { |
| 1092 VariableDeclarationStatement stmt = statements[i]; | 1092 VariableDeclarationStatement stmt = statements[i]; |
| 1093 VariableDeclaration decl = stmt.variables.variables[0]; | 1093 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1094 MapLiteral exp = decl.initializer; | 1094 MapLiteral exp = decl.initializer; |
| 1095 return exp.staticType; | 1095 return exp.staticType; |
| 1096 } | 1096 } |
| 1097 | 1097 |
| 1098 Asserter<InterfaceType> assertMapOfIntToString = | 1098 Asserter<InterfaceType> assertMapOfIntToString = |
| 1099 _isMapOf(_isInt, _isString); | 1099 _isMapOf(_isInt, _isString); |
| 1100 | 1100 |
| 1101 assertMapOfIntToString(literal(0)); | 1101 assertMapOfIntToString(literal(0)); |
| 1102 assertMapOfIntToString(literal(1)); | 1102 assertMapOfIntToString(literal(1)); |
| 1103 assertMapOfIntToString(literal(2)); | 1103 assertMapOfIntToString(literal(2)); |
| 1104 assertMapOfIntToString(literal(3)); | 1104 assertMapOfIntToString(literal(3)); |
| 1105 } | 1105 } |
| 1106 | 1106 |
| 1107 void test_mapLiteral_simple_disabled() { | 1107 void test_mapLiteral_simple_disabled() { |
| 1108 String code = r''' | 1108 String code = r''' |
| 1109 void main () { | 1109 void main () { |
| 1110 Map<int, String> l0 = <int, dynamic>{}; | 1110 Map<int, String> l0 = <int, dynamic>{}; |
| 1111 Map<int, String> l1 = <int, dynamic>{3: "hello"}; | 1111 Map<int, String> l1 = <int, dynamic>{3: "hello"}; |
| 1112 Map<int, String> l2 = <int, dynamic>{"hello": "hello"}; | 1112 Map<int, String> l2 = <int, dynamic>{"hello": "hello"}; |
| 1113 Map<int, String> l3 = <int, dynamic>{3: 3}; | 1113 Map<int, String> l3 = <int, dynamic>{3: 3}; |
| 1114 } | 1114 } |
| 1115 '''; | 1115 '''; |
| 1116 CompilationUnit unit = resolveSource(code); | 1116 CompilationUnit unit = resolveSource(code); |
| 1117 List<Statement> statements = | 1117 List<Statement> statements = |
| 1118 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 1118 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 1119 DartType literal(int i) { | 1119 DartType literal(int i) { |
| 1120 VariableDeclarationStatement stmt = statements[i]; | 1120 VariableDeclarationStatement stmt = statements[i]; |
| 1121 VariableDeclaration decl = stmt.variables.variables[0]; | 1121 VariableDeclaration decl = stmt.variables.variables[0]; |
| 1122 MapLiteral exp = decl.initializer; | 1122 MapLiteral exp = decl.initializer; |
| 1123 return exp.staticType; | 1123 return exp.staticType; |
| 1124 } | 1124 } |
| 1125 | 1125 |
| 1126 Asserter<InterfaceType> assertMapOfIntToDynamic = | 1126 Asserter<InterfaceType> assertMapOfIntToDynamic = |
| 1127 _isMapOf(_isInt, _isDynamic); | 1127 _isMapOf(_isInt, _isDynamic); |
| 1128 | 1128 |
| 1129 assertMapOfIntToDynamic(literal(0)); | 1129 assertMapOfIntToDynamic(literal(0)); |
| 1130 assertMapOfIntToDynamic(literal(1)); | 1130 assertMapOfIntToDynamic(literal(1)); |
| 1131 assertMapOfIntToDynamic(literal(2)); | 1131 assertMapOfIntToDynamic(literal(2)); |
| 1132 assertMapOfIntToDynamic(literal(3)); | 1132 assertMapOfIntToDynamic(literal(3)); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 void test_methodDeclaration_body_propagation() { | 1135 void test_methodDeclaration_body_propagation() { |
| 1136 String code = r''' | 1136 String code = r''' |
| 1137 class A { | 1137 class A { |
| 1138 List<String> m0(int x) => ["hello"]; | 1138 List<String> m0(int x) => ["hello"]; |
| 1139 List<String> m1(int x) {return [3];}; | 1139 List<String> m1(int x) {return [3];}; |
| 1140 } | 1140 } |
| 1141 '''; | 1141 '''; |
| 1142 CompilationUnit unit = resolveSource(code); | 1142 CompilationUnit unit = resolveSource(code); |
| 1143 Expression methodReturnValue(String methodName) { | 1143 Expression methodReturnValue(String methodName) { |
| 1144 MethodDeclaration method = | 1144 MethodDeclaration method = |
| 1145 AstFinder.getMethodInClass(unit, "A", methodName); | 1145 AstFinder.getMethodInClass(unit, "A", methodName); |
| 1146 FunctionBody body = method.body; | 1146 FunctionBody body = method.body; |
| 1147 if (body is ExpressionFunctionBody) { | 1147 if (body is ExpressionFunctionBody) { |
| 1148 return body.expression; | 1148 return body.expression; |
| 1149 } else { | 1149 } else { |
| 1150 Statement stmt = (body as BlockFunctionBody).block.statements[0]; | 1150 Statement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 1151 return (stmt as ReturnStatement).expression; | 1151 return (stmt as ReturnStatement).expression; |
| 1152 } | 1152 } |
| 1153 } | 1153 } |
| 1154 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); | 1154 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); |
| 1155 assertListOfString(methodReturnValue("m0").staticType); | 1155 assertListOfString(methodReturnValue("m0").staticType); |
| 1156 assertListOfString(methodReturnValue("m1").staticType); | 1156 assertListOfString(methodReturnValue("m1").staticType); |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 void test_redirectingConstructor_propagation() { | 1159 void test_redirectingConstructor_propagation() { |
| 1160 String code = r''' | 1160 String code = r''' |
| 1161 class A { | 1161 class A { |
| 1162 A() : this.named([]); | 1162 A() : this.named([]); |
| 1163 A.named(List<String> x); | 1163 A.named(List<String> x); |
| 1164 } | 1164 } |
| 1165 '''; | 1165 '''; |
| 1166 CompilationUnit unit = resolveSource(code); | 1166 CompilationUnit unit = resolveSource(code); |
| 1167 | 1167 |
| 1168 ConstructorDeclaration constructor = | 1168 ConstructorDeclaration constructor = |
| 1169 AstFinder.getConstructorInClass(unit, "A", null); | 1169 AstFinder.getConstructorInClass(unit, "A", null); |
| 1170 RedirectingConstructorInvocation invocation = constructor.initializers[0]; | 1170 RedirectingConstructorInvocation invocation = constructor.initializers[0]; |
| 1171 Expression exp = invocation.argumentList.arguments[0]; | 1171 Expression exp = invocation.argumentList.arguments[0]; |
| 1172 _isListOf(_isString)(exp.staticType); | 1172 _isListOf(_isString)(exp.staticType); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 void test_superConstructorInvocation_propagation() { | 1175 void test_superConstructorInvocation_propagation() { |
| 1176 String code = r''' | 1176 String code = r''' |
| 1177 class B { | 1177 class B { |
| 1178 B(List<String>); | 1178 B(List<String>); |
| 1179 } | 1179 } |
| 1180 class A extends B { | 1180 class A extends B { |
| 1181 A() : super([]); | 1181 A() : super([]); |
| 1182 } | 1182 } |
| 1183 '''; | 1183 '''; |
| 1184 CompilationUnit unit = resolveSource(code); | 1184 CompilationUnit unit = resolveSource(code); |
| 1185 | 1185 |
| 1186 ConstructorDeclaration constructor = | 1186 ConstructorDeclaration constructor = |
| 1187 AstFinder.getConstructorInClass(unit, "A", null); | 1187 AstFinder.getConstructorInClass(unit, "A", null); |
| 1188 SuperConstructorInvocation invocation = constructor.initializers[0]; | 1188 SuperConstructorInvocation invocation = constructor.initializers[0]; |
| 1189 Expression exp = invocation.argumentList.arguments[0]; | 1189 Expression exp = invocation.argumentList.arguments[0]; |
| 1190 _isListOf(_isString)(exp.staticType); | 1190 _isListOf(_isString)(exp.staticType); |
| 1191 } | 1191 } |
| 1192 | 1192 |
| 1193 void test_sync_star_method_propagation() { | 1193 void test_sync_star_method_propagation() { |
| 1194 String code = r''' | 1194 String code = r''' |
| 1195 import "dart:async"; | 1195 import "dart:async"; |
| 1196 class A { | 1196 class A { |
| 1197 Iterable f0() sync* { yield []; } | 1197 Iterable f0() sync* { yield []; } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 f2(3); | 1382 f2(3); |
| 1383 f3(3); | 1383 f3(3); |
| 1384 f4(3); | 1384 f4(3); |
| 1385 } | 1385 } |
| 1386 } | 1386 } |
| 1387 '''; | 1387 '''; |
| 1388 resolveTestUnit(code); | 1388 resolveTestUnit(code); |
| 1389 | 1389 |
| 1390 checkBody(String className) { | 1390 checkBody(String className) { |
| 1391 List<Statement> statements = | 1391 List<Statement> statements = |
| 1392 AstFinder.getStatementsInMethod(testUnit, className, "g"); | 1392 AstFinder.getStatementsInMethod(testUnit, className, "g"); |
| 1393 | 1393 |
| 1394 for (int i = 1; i <= 5; i++) { | 1394 for (int i = 1; i <= 5; i++) { |
| 1395 Expression exp = (statements[i] as ExpressionStatement).expression; | 1395 Expression exp = (statements[i] as ExpressionStatement).expression; |
| 1396 expect(exp.staticType, typeProvider.dynamicType); | 1396 expect(exp.staticType, typeProvider.dynamicType); |
| 1397 } | 1397 } |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 checkBody("C"); | 1400 checkBody("C"); |
| 1401 checkBody("D"); | 1401 checkBody("D"); |
| 1402 } | 1402 } |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 class C { | 1718 class C { |
| 1719 /*=T*/ f/*<T>*/(/*=T*/ x) => null; | 1719 /*=T*/ f/*<T>*/(/*=T*/ x) => null; |
| 1720 } | 1720 } |
| 1721 class D extends C { | 1721 class D extends C { |
| 1722 /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D | 1722 /*=T*/ f/*<T>*/(/*=T*/ x) => null; // from D |
| 1723 } | 1723 } |
| 1724 '''); | 1724 '''); |
| 1725 expectFunctionType('f/*<T>*/(/*=T*/ x) => null; // from D', '<T>(T) → T', | 1725 expectFunctionType('f/*<T>*/(/*=T*/ x) => null; // from D', '<T>(T) → T', |
| 1726 elementTypeParams: '[T]', typeFormals: '[T]'); | 1726 elementTypeParams: '[T]', typeFormals: '[T]'); |
| 1727 SimpleIdentifier f = | 1727 SimpleIdentifier f = |
| 1728 findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D'); | 1728 findIdentifier('f/*<T>*/(/*=T*/ x) => null; // from D'); |
| 1729 MethodElementImpl e = f.staticElement; | 1729 MethodElementImpl e = f.staticElement; |
| 1730 FunctionType ft = e.type.instantiate([typeProvider.stringType]); | 1730 FunctionType ft = e.type.instantiate([typeProvider.stringType]); |
| 1731 expect(ft.toString(), '(String) → String'); | 1731 expect(ft.toString(), '(String) → String'); |
| 1732 } | 1732 } |
| 1733 | 1733 |
| 1734 void test_genericMethod_override_bounds() { | 1734 void test_genericMethod_override_bounds() { |
| 1735 resolveTestUnit(r''' | 1735 resolveTestUnit(r''' |
| 1736 class A {} | 1736 class A {} |
| 1737 class B extends A {} | 1737 class B extends A {} |
| 1738 class C { | 1738 class C { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1960 void test_setterWithNoVoidType() { | 1960 void test_setterWithNoVoidType() { |
| 1961 Source source = addSource(r''' | 1961 Source source = addSource(r''' |
| 1962 class A { | 1962 class A { |
| 1963 set f(String s) { | 1963 set f(String s) { |
| 1964 return '42'; | 1964 return '42'; |
| 1965 } | 1965 } |
| 1966 } | 1966 } |
| 1967 set g(int x) => 42; | 1967 set g(int x) => 42; |
| 1968 '''); | 1968 '''); |
| 1969 computeLibrarySourceErrors(source); | 1969 computeLibrarySourceErrors(source); |
| 1970 assertErrors(source, [ | 1970 assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,]); |
| 1971 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, | |
| 1972 ]); | |
| 1973 verify([source]); | 1971 verify([source]); |
| 1974 } | 1972 } |
| 1975 | 1973 |
| 1976 void test_setterWithNoVoidType_returningVoid() { | 1974 void test_setterWithNoVoidType_returningVoid() { |
| 1977 Source source = addSource(r''' | 1975 Source source = addSource(r''' |
| 1978 void returnsVoid() {} | 1976 void returnsVoid() {} |
| 1979 class A { | 1977 class A { |
| 1980 set f(String s) => returnsVoid(); | 1978 set f(String s) => returnsVoid(); |
| 1981 } | 1979 } |
| 1982 set g(int x) => returnsVoid(); | 1980 set g(int x) => returnsVoid(); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2270 main() { | 2268 main() { |
| 2271 var v = x; | 2269 var v = x; |
| 2272 v; // marker | 2270 v; // marker |
| 2273 } | 2271 } |
| 2274 int x = 3; | 2272 int x = 3; |
| 2275 '''; | 2273 '''; |
| 2276 assertPropagatedAssignedType(code, typeProvider.intType, null); | 2274 assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 2277 assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2275 assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 2278 } | 2276 } |
| 2279 } | 2277 } |
| OLD | NEW |