| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 '''; | 256 '''; |
| 257 CompilationUnit unit = resolveSource(code); | 257 CompilationUnit unit = resolveSource(code); |
| 258 List<Statement> statements = | 258 List<Statement> statements = |
| 259 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 259 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 260 CascadeExpression fetch(int i) { | 260 CascadeExpression fetch(int i) { |
| 261 VariableDeclarationStatement stmt = statements[i]; | 261 VariableDeclarationStatement stmt = statements[i]; |
| 262 VariableDeclaration decl = stmt.variables.variables[0]; | 262 VariableDeclaration decl = stmt.variables.variables[0]; |
| 263 CascadeExpression exp = decl.initializer; | 263 CascadeExpression exp = decl.initializer; |
| 264 return exp; | 264 return exp; |
| 265 } | 265 } |
| 266 |
| 266 Element elementA = AstFinder.getClass(unit, "A").element; | 267 Element elementA = AstFinder.getClass(unit, "A").element; |
| 267 | 268 |
| 268 CascadeExpression cascade = fetch(0); | 269 CascadeExpression cascade = fetch(0); |
| 269 _isInstantiationOf(_hasElement(elementA))([_isInt])(cascade.staticType); | 270 _isInstantiationOf(_hasElement(elementA))([_isInt])(cascade.staticType); |
| 270 MethodInvocation invoke = cascade.cascadeSections[0]; | 271 MethodInvocation invoke = cascade.cascadeSections[0]; |
| 271 FunctionExpression function = invoke.argumentList.arguments[1]; | 272 FunctionExpression function = invoke.argumentList.arguments[1]; |
| 272 ExecutableElement f0 = function.element; | 273 ExecutableElement f0 = function.element; |
| 273 _isListOf(_isInt)(f0.type.returnType); | 274 _isListOf(_isInt)(f0.type.returnType); |
| 274 expect(f0.type.normalParameterTypes[0], typeProvider.intType); | 275 expect(f0.type.normalParameterTypes[0], typeProvider.intType); |
| 275 } | 276 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 '''; | 377 '''; |
| 377 CompilationUnit unit = resolveSource(code); | 378 CompilationUnit unit = resolveSource(code); |
| 378 List<Statement> statements = | 379 List<Statement> statements = |
| 379 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 380 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 380 DartType literal(int i) { | 381 DartType literal(int i) { |
| 381 VariableDeclarationStatement stmt = statements[i]; | 382 VariableDeclarationStatement stmt = statements[i]; |
| 382 VariableDeclaration decl = stmt.variables.variables[0]; | 383 VariableDeclaration decl = stmt.variables.variables[0]; |
| 383 FunctionExpression exp = decl.initializer; | 384 FunctionExpression exp = decl.initializer; |
| 384 return exp.element.type; | 385 return exp.element.type; |
| 385 } | 386 } |
| 387 |
| 386 _isFunction2Of(_isInt, _isString)(literal(0)); | 388 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 387 _isFunction2Of(_isInt, _isString)(literal(1)); | 389 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 388 _isFunction2Of(_isString, _isString)(literal(2)); | 390 _isFunction2Of(_isString, _isString)(literal(2)); |
| 389 _isFunction2Of(_isInt, _isInt)(literal(3)); | 391 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 390 _isFunction2Of(_isInt, _isString)(literal(4)); | 392 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 391 } | 393 } |
| 392 | 394 |
| 393 void test_functionLiteral_assignment_unTypedArguments() { | 395 void test_functionLiteral_assignment_unTypedArguments() { |
| 394 String code = r''' | 396 String code = r''' |
| 395 typedef T Function2<S, T>(S x); | 397 typedef T Function2<S, T>(S x); |
| 396 | 398 |
| 397 void main () { | 399 void main () { |
| 398 Function2<int, String> l0 = (x) => null; | 400 Function2<int, String> l0 = (x) => null; |
| 399 Function2<int, String> l1 = (x) => "hello"; | 401 Function2<int, String> l1 = (x) => "hello"; |
| 400 Function2<int, String> l2 = (x) => "hello"; | 402 Function2<int, String> l2 = (x) => "hello"; |
| 401 Function2<int, String> l3 = (x) => 3; | 403 Function2<int, String> l3 = (x) => 3; |
| 402 Function2<int, String> l4 = (x) {return 3;}; | 404 Function2<int, String> l4 = (x) {return 3;}; |
| 403 } | 405 } |
| 404 '''; | 406 '''; |
| 405 CompilationUnit unit = resolveSource(code); | 407 CompilationUnit unit = resolveSource(code); |
| 406 List<Statement> statements = | 408 List<Statement> statements = |
| 407 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 409 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 408 DartType literal(int i) { | 410 DartType literal(int i) { |
| 409 VariableDeclarationStatement stmt = statements[i]; | 411 VariableDeclarationStatement stmt = statements[i]; |
| 410 VariableDeclaration decl = stmt.variables.variables[0]; | 412 VariableDeclaration decl = stmt.variables.variables[0]; |
| 411 FunctionExpression exp = decl.initializer; | 413 FunctionExpression exp = decl.initializer; |
| 412 return exp.element.type; | 414 return exp.element.type; |
| 413 } | 415 } |
| 416 |
| 414 _isFunction2Of(_isInt, _isString)(literal(0)); | 417 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 415 _isFunction2Of(_isInt, _isString)(literal(1)); | 418 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 416 _isFunction2Of(_isInt, _isString)(literal(2)); | 419 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 417 _isFunction2Of(_isInt, _isInt)(literal(3)); | 420 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 418 _isFunction2Of(_isInt, _isString)(literal(4)); | 421 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 419 } | 422 } |
| 420 | 423 |
| 421 void test_functionLiteral_body_propagation() { | 424 void test_functionLiteral_body_propagation() { |
| 422 String code = r''' | 425 String code = r''' |
| 423 typedef T Function2<S, T>(S x); | 426 typedef T Function2<S, T>(S x); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 437 VariableDeclaration decl = stmt.variables.variables[0]; | 440 VariableDeclaration decl = stmt.variables.variables[0]; |
| 438 FunctionExpression exp = decl.initializer; | 441 FunctionExpression exp = decl.initializer; |
| 439 FunctionBody body = exp.body; | 442 FunctionBody body = exp.body; |
| 440 if (body is ExpressionFunctionBody) { | 443 if (body is ExpressionFunctionBody) { |
| 441 return body.expression; | 444 return body.expression; |
| 442 } else { | 445 } else { |
| 443 Statement stmt = (body as BlockFunctionBody).block.statements[0]; | 446 Statement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 444 return (stmt as ReturnStatement).expression; | 447 return (stmt as ReturnStatement).expression; |
| 445 } | 448 } |
| 446 } | 449 } |
| 450 |
| 447 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); | 451 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); |
| 448 assertListOfString(functionReturnValue(0).staticType); | 452 assertListOfString(functionReturnValue(0).staticType); |
| 449 assertListOfString(functionReturnValue(1).staticType); | 453 assertListOfString(functionReturnValue(1).staticType); |
| 450 assertListOfString(functionReturnValue(2).staticType); | 454 assertListOfString(functionReturnValue(2).staticType); |
| 451 assertListOfString(functionReturnValue(3).staticType); | 455 assertListOfString(functionReturnValue(3).staticType); |
| 452 } | 456 } |
| 453 | 457 |
| 454 void test_functionLiteral_functionExpressionInvocation_typedArguments() { | 458 void test_functionLiteral_functionExpressionInvocation_typedArguments() { |
| 455 String code = r''' | 459 String code = r''' |
| 456 class Mapper<F, T> { | 460 class Mapper<F, T> { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 467 '''; | 471 '''; |
| 468 CompilationUnit unit = resolveSource(code); | 472 CompilationUnit unit = resolveSource(code); |
| 469 List<Statement> statements = | 473 List<Statement> statements = |
| 470 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 474 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 471 DartType literal(int i) { | 475 DartType literal(int i) { |
| 472 ExpressionStatement stmt = statements[i]; | 476 ExpressionStatement stmt = statements[i]; |
| 473 FunctionExpressionInvocation invk = stmt.expression; | 477 FunctionExpressionInvocation invk = stmt.expression; |
| 474 FunctionExpression exp = invk.argumentList.arguments[0]; | 478 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 475 return exp.element.type; | 479 return exp.element.type; |
| 476 } | 480 } |
| 481 |
| 477 _isFunction2Of(_isInt, _isString)(literal(0)); | 482 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 478 _isFunction2Of(_isInt, _isString)(literal(1)); | 483 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 479 _isFunction2Of(_isString, _isString)(literal(2)); | 484 _isFunction2Of(_isString, _isString)(literal(2)); |
| 480 _isFunction2Of(_isInt, _isInt)(literal(3)); | 485 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 481 _isFunction2Of(_isInt, _isString)(literal(4)); | 486 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 482 } | 487 } |
| 483 | 488 |
| 484 void test_functionLiteral_functionExpressionInvocation_unTypedArguments() { | 489 void test_functionLiteral_functionExpressionInvocation_unTypedArguments() { |
| 485 String code = r''' | 490 String code = r''' |
| 486 class Mapper<F, T> { | 491 class Mapper<F, T> { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 497 '''; | 502 '''; |
| 498 CompilationUnit unit = resolveSource(code); | 503 CompilationUnit unit = resolveSource(code); |
| 499 List<Statement> statements = | 504 List<Statement> statements = |
| 500 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 505 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 501 DartType literal(int i) { | 506 DartType literal(int i) { |
| 502 ExpressionStatement stmt = statements[i]; | 507 ExpressionStatement stmt = statements[i]; |
| 503 FunctionExpressionInvocation invk = stmt.expression; | 508 FunctionExpressionInvocation invk = stmt.expression; |
| 504 FunctionExpression exp = invk.argumentList.arguments[0]; | 509 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 505 return exp.element.type; | 510 return exp.element.type; |
| 506 } | 511 } |
| 512 |
| 507 _isFunction2Of(_isInt, _isString)(literal(0)); | 513 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 508 _isFunction2Of(_isInt, _isString)(literal(1)); | 514 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 509 _isFunction2Of(_isInt, _isString)(literal(2)); | 515 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 510 _isFunction2Of(_isInt, _isInt)(literal(3)); | 516 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 511 _isFunction2Of(_isInt, _isString)(literal(4)); | 517 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 512 } | 518 } |
| 513 | 519 |
| 514 void test_functionLiteral_functionInvocation_typedArguments() { | 520 void test_functionLiteral_functionInvocation_typedArguments() { |
| 515 String code = r''' | 521 String code = r''' |
| 516 String map(String mapper(int x)) => mapper(null); | 522 String map(String mapper(int x)) => mapper(null); |
| 517 | 523 |
| 518 void main () { | 524 void main () { |
| 519 map((int x) => null); | 525 map((int x) => null); |
| 520 map((int x) => "hello"); | 526 map((int x) => "hello"); |
| 521 map((String x) => "hello"); | 527 map((String x) => "hello"); |
| 522 map((int x) => 3); | 528 map((int x) => 3); |
| 523 map((int x) {return 3;}); | 529 map((int x) {return 3;}); |
| 524 } | 530 } |
| 525 '''; | 531 '''; |
| 526 CompilationUnit unit = resolveSource(code); | 532 CompilationUnit unit = resolveSource(code); |
| 527 List<Statement> statements = | 533 List<Statement> statements = |
| 528 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 534 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 529 DartType literal(int i) { | 535 DartType literal(int i) { |
| 530 ExpressionStatement stmt = statements[i]; | 536 ExpressionStatement stmt = statements[i]; |
| 531 MethodInvocation invk = stmt.expression; | 537 MethodInvocation invk = stmt.expression; |
| 532 FunctionExpression exp = invk.argumentList.arguments[0]; | 538 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 533 return exp.element.type; | 539 return exp.element.type; |
| 534 } | 540 } |
| 541 |
| 535 _isFunction2Of(_isInt, _isString)(literal(0)); | 542 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 536 _isFunction2Of(_isInt, _isString)(literal(1)); | 543 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 537 _isFunction2Of(_isString, _isString)(literal(2)); | 544 _isFunction2Of(_isString, _isString)(literal(2)); |
| 538 _isFunction2Of(_isInt, _isInt)(literal(3)); | 545 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 539 _isFunction2Of(_isInt, _isString)(literal(4)); | 546 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 540 } | 547 } |
| 541 | 548 |
| 542 void test_functionLiteral_functionInvocation_unTypedArguments() { | 549 void test_functionLiteral_functionInvocation_unTypedArguments() { |
| 543 String code = r''' | 550 String code = r''' |
| 544 String map(String mapper(int x)) => mapper(null); | 551 String map(String mapper(int x)) => mapper(null); |
| 545 | 552 |
| 546 void main () { | 553 void main () { |
| 547 map((x) => null); | 554 map((x) => null); |
| 548 map((x) => "hello"); | 555 map((x) => "hello"); |
| 549 map((x) => "hello"); | 556 map((x) => "hello"); |
| 550 map((x) => 3); | 557 map((x) => 3); |
| 551 map((x) {return 3;}); | 558 map((x) {return 3;}); |
| 552 } | 559 } |
| 553 '''; | 560 '''; |
| 554 CompilationUnit unit = resolveSource(code); | 561 CompilationUnit unit = resolveSource(code); |
| 555 List<Statement> statements = | 562 List<Statement> statements = |
| 556 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 563 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 557 DartType literal(int i) { | 564 DartType literal(int i) { |
| 558 ExpressionStatement stmt = statements[i]; | 565 ExpressionStatement stmt = statements[i]; |
| 559 MethodInvocation invk = stmt.expression; | 566 MethodInvocation invk = stmt.expression; |
| 560 FunctionExpression exp = invk.argumentList.arguments[0]; | 567 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 561 return exp.element.type; | 568 return exp.element.type; |
| 562 } | 569 } |
| 570 |
| 563 _isFunction2Of(_isInt, _isString)(literal(0)); | 571 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 564 _isFunction2Of(_isInt, _isString)(literal(1)); | 572 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 565 _isFunction2Of(_isInt, _isString)(literal(2)); | 573 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 566 _isFunction2Of(_isInt, _isInt)(literal(3)); | 574 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 567 _isFunction2Of(_isInt, _isString)(literal(4)); | 575 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 568 } | 576 } |
| 569 | 577 |
| 570 void test_functionLiteral_methodInvocation_typedArguments() { | 578 void test_functionLiteral_methodInvocation_typedArguments() { |
| 571 String code = r''' | 579 String code = r''' |
| 572 class Mapper<F, T> { | 580 class Mapper<F, T> { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 583 '''; | 591 '''; |
| 584 CompilationUnit unit = resolveSource(code); | 592 CompilationUnit unit = resolveSource(code); |
| 585 List<Statement> statements = | 593 List<Statement> statements = |
| 586 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 594 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 587 DartType literal(int i) { | 595 DartType literal(int i) { |
| 588 ExpressionStatement stmt = statements[i]; | 596 ExpressionStatement stmt = statements[i]; |
| 589 MethodInvocation invk = stmt.expression; | 597 MethodInvocation invk = stmt.expression; |
| 590 FunctionExpression exp = invk.argumentList.arguments[0]; | 598 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 591 return exp.element.type; | 599 return exp.element.type; |
| 592 } | 600 } |
| 601 |
| 593 _isFunction2Of(_isInt, _isString)(literal(0)); | 602 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 594 _isFunction2Of(_isInt, _isString)(literal(1)); | 603 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 595 _isFunction2Of(_isString, _isString)(literal(2)); | 604 _isFunction2Of(_isString, _isString)(literal(2)); |
| 596 _isFunction2Of(_isInt, _isInt)(literal(3)); | 605 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 597 _isFunction2Of(_isInt, _isString)(literal(4)); | 606 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 598 } | 607 } |
| 599 | 608 |
| 600 void test_functionLiteral_methodInvocation_unTypedArguments() { | 609 void test_functionLiteral_methodInvocation_unTypedArguments() { |
| 601 String code = r''' | 610 String code = r''' |
| 602 class Mapper<F, T> { | 611 class Mapper<F, T> { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 613 '''; | 622 '''; |
| 614 CompilationUnit unit = resolveSource(code); | 623 CompilationUnit unit = resolveSource(code); |
| 615 List<Statement> statements = | 624 List<Statement> statements = |
| 616 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 625 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 617 DartType literal(int i) { | 626 DartType literal(int i) { |
| 618 ExpressionStatement stmt = statements[i]; | 627 ExpressionStatement stmt = statements[i]; |
| 619 MethodInvocation invk = stmt.expression; | 628 MethodInvocation invk = stmt.expression; |
| 620 FunctionExpression exp = invk.argumentList.arguments[0]; | 629 FunctionExpression exp = invk.argumentList.arguments[0]; |
| 621 return exp.element.type; | 630 return exp.element.type; |
| 622 } | 631 } |
| 632 |
| 623 _isFunction2Of(_isInt, _isString)(literal(0)); | 633 _isFunction2Of(_isInt, _isString)(literal(0)); |
| 624 _isFunction2Of(_isInt, _isString)(literal(1)); | 634 _isFunction2Of(_isInt, _isString)(literal(1)); |
| 625 _isFunction2Of(_isInt, _isString)(literal(2)); | 635 _isFunction2Of(_isInt, _isString)(literal(2)); |
| 626 _isFunction2Of(_isInt, _isInt)(literal(3)); | 636 _isFunction2Of(_isInt, _isInt)(literal(3)); |
| 627 _isFunction2Of(_isInt, _isString)(literal(4)); | 637 _isFunction2Of(_isInt, _isString)(literal(4)); |
| 628 } | 638 } |
| 629 | 639 |
| 630 void test_functionLiteral_unTypedArgument_propagation() { | 640 void test_functionLiteral_unTypedArgument_propagation() { |
| 631 String code = r''' | 641 String code = r''' |
| 632 typedef T Function2<S, T>(S x); | 642 typedef T Function2<S, T>(S x); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 647 VariableDeclaration decl = stmt.variables.variables[0]; | 657 VariableDeclaration decl = stmt.variables.variables[0]; |
| 648 FunctionExpression exp = decl.initializer; | 658 FunctionExpression exp = decl.initializer; |
| 649 FunctionBody body = exp.body; | 659 FunctionBody body = exp.body; |
| 650 if (body is ExpressionFunctionBody) { | 660 if (body is ExpressionFunctionBody) { |
| 651 return body.expression; | 661 return body.expression; |
| 652 } else { | 662 } else { |
| 653 Statement stmt = (body as BlockFunctionBody).block.statements[0]; | 663 Statement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 654 return (stmt as ReturnStatement).expression; | 664 return (stmt as ReturnStatement).expression; |
| 655 } | 665 } |
| 656 } | 666 } |
| 667 |
| 657 expect(functionReturnValue(0).staticType, typeProvider.intType); | 668 expect(functionReturnValue(0).staticType, typeProvider.intType); |
| 658 expect(functionReturnValue(1).staticType, typeProvider.intType); | 669 expect(functionReturnValue(1).staticType, typeProvider.intType); |
| 659 expect(functionReturnValue(2).staticType, typeProvider.intType); | 670 expect(functionReturnValue(2).staticType, typeProvider.intType); |
| 660 expect(functionReturnValue(3).staticType, typeProvider.dynamicType); | 671 expect(functionReturnValue(3).staticType, typeProvider.dynamicType); |
| 661 expect(functionReturnValue(4).staticType, typeProvider.stringType); | 672 expect(functionReturnValue(4).staticType, typeProvider.stringType); |
| 662 } | 673 } |
| 663 | 674 |
| 664 void test_inference_hints() { | 675 void test_inference_hints() { |
| 665 Source source = addSource(r''' | 676 Source source = addSource(r''' |
| 666 void main () { | 677 void main () { |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 MethodDeclaration method = | 1182 MethodDeclaration method = |
| 1172 AstFinder.getMethodInClass(unit, "A", methodName); | 1183 AstFinder.getMethodInClass(unit, "A", methodName); |
| 1173 FunctionBody body = method.body; | 1184 FunctionBody body = method.body; |
| 1174 if (body is ExpressionFunctionBody) { | 1185 if (body is ExpressionFunctionBody) { |
| 1175 return body.expression; | 1186 return body.expression; |
| 1176 } else { | 1187 } else { |
| 1177 Statement stmt = (body as BlockFunctionBody).block.statements[0]; | 1188 Statement stmt = (body as BlockFunctionBody).block.statements[0]; |
| 1178 return (stmt as ReturnStatement).expression; | 1189 return (stmt as ReturnStatement).expression; |
| 1179 } | 1190 } |
| 1180 } | 1191 } |
| 1192 |
| 1181 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); | 1193 Asserter<InterfaceType> assertListOfString = _isListOf(_isString); |
| 1182 assertListOfString(methodReturnValue("m0").staticType); | 1194 assertListOfString(methodReturnValue("m0").staticType); |
| 1183 assertListOfString(methodReturnValue("m1").staticType); | 1195 assertListOfString(methodReturnValue("m1").staticType); |
| 1184 } | 1196 } |
| 1185 | 1197 |
| 1186 void test_redirectingConstructor_propagation() { | 1198 void test_redirectingConstructor_propagation() { |
| 1187 String code = r''' | 1199 String code = r''' |
| 1188 class A { | 1200 class A { |
| 1189 A() : this.named([]); | 1201 A() : this.named([]); |
| 1190 A.named(List<String> x); | 1202 A.named(List<String> x); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 '''); | 1314 '''); |
| 1303 expectIdentifierType('methodTearOffInst', "(int) → int"); | 1315 expectIdentifierType('methodTearOffInst', "(int) → int"); |
| 1304 expectIdentifierType('staticTearOffInst', "(int) → int"); | 1316 expectIdentifierType('staticTearOffInst', "(int) → int"); |
| 1305 expectIdentifierType('staticFieldTearOffInst', "(int) → int"); | 1317 expectIdentifierType('staticFieldTearOffInst', "(int) → int"); |
| 1306 expectIdentifierType('topFunTearOffInst', "(int) → int"); | 1318 expectIdentifierType('topFunTearOffInst', "(int) → int"); |
| 1307 expectIdentifierType('topFieldTearOffInst', "(int) → int"); | 1319 expectIdentifierType('topFieldTearOffInst', "(int) → int"); |
| 1308 expectIdentifierType('localTearOffInst', "(int) → int"); | 1320 expectIdentifierType('localTearOffInst', "(int) → int"); |
| 1309 expectIdentifierType('paramTearOffInst', "(int) → int"); | 1321 expectIdentifierType('paramTearOffInst', "(int) → int"); |
| 1310 } | 1322 } |
| 1311 | 1323 |
| 1324 void objectMethodOnFunctions_helper(String code) { |
| 1325 resolveTestUnit(code); |
| 1326 expectIdentifierType('t0', "String"); |
| 1327 expectIdentifierType('t1', "() → String"); |
| 1328 expectIdentifierType('t2', "int"); |
| 1329 expectIdentifierType('t3', "String"); |
| 1330 expectIdentifierType('t4', "() → String"); |
| 1331 expectIdentifierType('t5', "int"); |
| 1332 } |
| 1333 |
| 1312 void setUp() { | 1334 void setUp() { |
| 1313 super.setUp(); | 1335 super.setUp(); |
| 1314 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 1336 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 1315 options.strongMode = true; | 1337 options.strongMode = true; |
| 1316 resetWithOptions(options); | 1338 resetWithOptions(options); |
| 1317 } | 1339 } |
| 1318 | 1340 |
| 1319 void test_dynamicObjectGetter_hashCode() { | 1341 void test_dynamicObjectGetter_hashCode() { |
| 1320 String code = r''' | 1342 String code = r''' |
| 1321 main() { | 1343 main() { |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 '''; | 1976 '''; |
| 1955 resolveTestUnit(code); | 1977 resolveTestUnit(code); |
| 1956 expectIdentifierType('ai', "A<dynamic>"); | 1978 expectIdentifierType('ai', "A<dynamic>"); |
| 1957 expectIdentifierType('bi', "B<num>"); | 1979 expectIdentifierType('bi', "B<num>"); |
| 1958 expectIdentifierType('ci', "C<int, B<int>, B<dynamic>>"); | 1980 expectIdentifierType('ci', "C<int, B<int>, B<dynamic>>"); |
| 1959 expectIdentifierType('aa', "A<dynamic>"); | 1981 expectIdentifierType('aa', "A<dynamic>"); |
| 1960 expectIdentifierType('bb', "B<num>"); | 1982 expectIdentifierType('bb', "B<num>"); |
| 1961 expectIdentifierType('cc', "C<int, B<int>, B<dynamic>>"); | 1983 expectIdentifierType('cc', "C<int, B<int>, B<dynamic>>"); |
| 1962 } | 1984 } |
| 1963 | 1985 |
| 1986 void test_objectMethodOnFunctions_Anonymous() { |
| 1987 String code = r''' |
| 1988 void main() { |
| 1989 var f = (x) => 3; |
| 1990 // No errors, correct type |
| 1991 var t0 = f.toString(); |
| 1992 var t1 = f.toString; |
| 1993 var t2 = f.hashCode; |
| 1994 |
| 1995 // Expressions, no errors, correct type |
| 1996 var t3 = (f).toString(); |
| 1997 var t4 = (f).toString; |
| 1998 var t5 = (f).hashCode; |
| 1999 |
| 2000 // Cascades, no errors |
| 2001 f..toString(); |
| 2002 f..toString; |
| 2003 f..hashCode; |
| 2004 |
| 2005 // Expression cascades, no errors |
| 2006 (f)..toString(); |
| 2007 (f)..toString; |
| 2008 (f)..hashCode; |
| 2009 }'''; |
| 2010 objectMethodOnFunctions_helper(code); |
| 2011 } |
| 2012 |
| 2013 void test_objectMethodOnFunctions_Function() { |
| 2014 String code = r''' |
| 2015 void main() { |
| 2016 Function f; |
| 2017 // No errors, correct type |
| 2018 var t0 = f.toString(); |
| 2019 var t1 = f.toString; |
| 2020 var t2 = f.hashCode; |
| 2021 |
| 2022 // Expressions, no errors, correct type |
| 2023 var t3 = (f).toString(); |
| 2024 var t4 = (f).toString; |
| 2025 var t5 = (f).hashCode; |
| 2026 |
| 2027 // Cascades, no errors |
| 2028 f..toString(); |
| 2029 f..toString; |
| 2030 f..hashCode; |
| 2031 |
| 2032 // Expression cascades, no errors |
| 2033 (f)..toString(); |
| 2034 (f)..toString; |
| 2035 (f)..hashCode; |
| 2036 }'''; |
| 2037 objectMethodOnFunctions_helper(code); |
| 2038 } |
| 2039 |
| 2040 void test_objectMethodOnFunctions_Static() { |
| 2041 String code = r''' |
| 2042 int f(int x) => null; |
| 2043 void main() { |
| 2044 // No errors, correct type |
| 2045 var t0 = f.toString(); |
| 2046 var t1 = f.toString; |
| 2047 var t2 = f.hashCode; |
| 2048 |
| 2049 // Expressions, no errors, correct type |
| 2050 var t3 = (f).toString(); |
| 2051 var t4 = (f).toString; |
| 2052 var t5 = (f).hashCode; |
| 2053 |
| 2054 // Cascades, no errors |
| 2055 f..toString(); |
| 2056 f..toString; |
| 2057 f..hashCode; |
| 2058 |
| 2059 // Expression cascades, no errors |
| 2060 (f)..toString(); |
| 2061 (f)..toString; |
| 2062 (f)..hashCode; |
| 2063 }'''; |
| 2064 objectMethodOnFunctions_helper(code); |
| 2065 } |
| 2066 |
| 2067 void test_objectMethodOnFunctions_Typedef() { |
| 2068 String code = r''' |
| 2069 typedef bool Predicate<T>(T object); |
| 2070 |
| 2071 void main() { |
| 2072 Predicate<int> f; |
| 2073 // No errors, correct type |
| 2074 var t0 = f.toString(); |
| 2075 var t1 = f.toString; |
| 2076 var t2 = f.hashCode; |
| 2077 |
| 2078 // Expressions, no errors, correct type |
| 2079 var t3 = (f).toString(); |
| 2080 var t4 = (f).toString; |
| 2081 var t5 = (f).hashCode; |
| 2082 |
| 2083 // Cascades, no errors |
| 2084 f..toString(); |
| 2085 f..toString; |
| 2086 f..hashCode; |
| 2087 |
| 2088 // Expression cascades, no errors |
| 2089 (f)..toString(); |
| 2090 (f)..toString; |
| 2091 (f)..hashCode; |
| 2092 }'''; |
| 2093 objectMethodOnFunctions_helper(code); |
| 2094 } |
| 2095 |
| 1964 void test_setterWithDynamicTypeIsError() { | 2096 void test_setterWithDynamicTypeIsError() { |
| 1965 Source source = addSource(r''' | 2097 Source source = addSource(r''' |
| 1966 class A { | 2098 class A { |
| 1967 dynamic set f(String s) => null; | 2099 dynamic set f(String s) => null; |
| 1968 } | 2100 } |
| 1969 dynamic set g(int x) => null; | 2101 dynamic set g(int x) => null; |
| 1970 '''); | 2102 '''); |
| 1971 computeLibrarySourceErrors(source); | 2103 computeLibrarySourceErrors(source); |
| 1972 assertErrors(source, [ | 2104 assertErrors(source, [ |
| 1973 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER, | 2105 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1992 void test_setterWithNoVoidType() { | 2124 void test_setterWithNoVoidType() { |
| 1993 Source source = addSource(r''' | 2125 Source source = addSource(r''' |
| 1994 class A { | 2126 class A { |
| 1995 set f(String s) { | 2127 set f(String s) { |
| 1996 return '42'; | 2128 return '42'; |
| 1997 } | 2129 } |
| 1998 } | 2130 } |
| 1999 set g(int x) => 42; | 2131 set g(int x) => 42; |
| 2000 '''); | 2132 '''); |
| 2001 computeLibrarySourceErrors(source); | 2133 computeLibrarySourceErrors(source); |
| 2002 assertErrors(source, [StaticTypeWarningCode.RETURN_OF_INVALID_TYPE,]); | 2134 assertErrors(source, [ |
| 2135 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
| 2136 ]); |
| 2003 verify([source]); | 2137 verify([source]); |
| 2004 } | 2138 } |
| 2005 | 2139 |
| 2006 void test_setterWithNoVoidType_returningVoid() { | 2140 void test_setterWithNoVoidType_returningVoid() { |
| 2007 Source source = addSource(r''' | 2141 Source source = addSource(r''' |
| 2008 void returnsVoid() {} | 2142 void returnsVoid() {} |
| 2009 class A { | 2143 class A { |
| 2010 set f(String s) => returnsVoid(); | 2144 set f(String s) => returnsVoid(); |
| 2011 } | 2145 } |
| 2012 set g(int x) => returnsVoid(); | 2146 set g(int x) => returnsVoid(); |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2300 main() { | 2434 main() { |
| 2301 var v = x; | 2435 var v = x; |
| 2302 v; // marker | 2436 v; // marker |
| 2303 } | 2437 } |
| 2304 int x = 3; | 2438 int x = 3; |
| 2305 '''; | 2439 '''; |
| 2306 assertPropagatedAssignedType(code, typeProvider.intType, null); | 2440 assertPropagatedAssignedType(code, typeProvider.intType, null); |
| 2307 assertTypeOfMarkedExpression(code, typeProvider.intType, null); | 2441 assertTypeOfMarkedExpression(code, typeProvider.intType, null); |
| 2308 } | 2442 } |
| 2309 } | 2443 } |
| OLD | NEW |