| 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.simple_resolver_test; | 5 library analyzer.test.generated.simple_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 390 } |
| 391 | 391 |
| 392 test_class_definesCall() async { | 392 test_class_definesCall() async { |
| 393 Source source = addSource(r''' | 393 Source source = addSource(r''' |
| 394 class A { | 394 class A { |
| 395 int call(int x) { return x; } | 395 int call(int x) { return x; } |
| 396 } | 396 } |
| 397 int f(A a) { | 397 int f(A a) { |
| 398 return a(0); | 398 return a(0); |
| 399 }'''); | 399 }'''); |
| 400 await assertNoErrors(source); | 400 await computeAnalysisResult(source); |
| 401 assertNoErrors(source); |
| 401 verify([source]); | 402 verify([source]); |
| 402 } | 403 } |
| 403 | 404 |
| 404 test_class_extends_implements() async { | 405 test_class_extends_implements() async { |
| 405 Source source = addSource(r''' | 406 Source source = addSource(r''' |
| 406 class A extends B implements C {} | 407 class A extends B implements C {} |
| 407 class B {} | 408 class B {} |
| 408 class C {}'''); | 409 class C {}'''); |
| 409 await assertNoErrors(source); | 410 await computeAnalysisResult(source); |
| 411 assertNoErrors(source); |
| 410 verify([source]); | 412 verify([source]); |
| 411 } | 413 } |
| 412 | 414 |
| 413 test_commentReference_class() async { | 415 test_commentReference_class() async { |
| 414 Source source = addSource(r''' | 416 Source source = addSource(r''' |
| 415 f() {} | 417 f() {} |
| 416 /** [A] [new A] [A.n] [new A.n] [m] [f] */ | 418 /** [A] [new A] [A.n] [new A.n] [m] [f] */ |
| 417 class A { | 419 class A { |
| 418 A() {} | 420 A() {} |
| 419 A.n() {} | 421 A.n() {} |
| 420 m() {} | 422 m() {} |
| 421 }'''); | 423 }'''); |
| 422 await assertNoErrors(source); | 424 await computeAnalysisResult(source); |
| 425 assertNoErrors(source); |
| 423 verify([source]); | 426 verify([source]); |
| 424 } | 427 } |
| 425 | 428 |
| 426 test_commentReference_parameter() async { | 429 test_commentReference_parameter() async { |
| 427 Source source = addSource(r''' | 430 Source source = addSource(r''' |
| 428 class A { | 431 class A { |
| 429 A() {} | 432 A() {} |
| 430 A.n() {} | 433 A.n() {} |
| 431 /** [e] [f] */ | 434 /** [e] [f] */ |
| 432 m(e, f()) {} | 435 m(e, f()) {} |
| 433 }'''); | 436 }'''); |
| 434 await assertNoErrors(source); | 437 await computeAnalysisResult(source); |
| 438 assertNoErrors(source); |
| 435 verify([source]); | 439 verify([source]); |
| 436 } | 440 } |
| 437 | 441 |
| 438 test_commentReference_singleLine() async { | 442 test_commentReference_singleLine() async { |
| 439 Source source = addSource(r''' | 443 Source source = addSource(r''' |
| 440 /// [A] | 444 /// [A] |
| 441 class A {}'''); | 445 class A {}'''); |
| 442 await assertNoErrors(source); | 446 await computeAnalysisResult(source); |
| 447 assertNoErrors(source); |
| 443 verify([source]); | 448 verify([source]); |
| 444 } | 449 } |
| 445 | 450 |
| 446 test_continueTarget_labeled() async { | 451 test_continueTarget_labeled() async { |
| 447 // Verify that the target of the label is correctly found and is recorded | 452 // Verify that the target of the label is correctly found and is recorded |
| 448 // as the unlabeled portion of the statement. | 453 // as the unlabeled portion of the statement. |
| 449 String text = r''' | 454 String text = r''' |
| 450 void f() { | 455 void f() { |
| 451 loop1: while (true) { | 456 loop1: while (true) { |
| 452 loop2: for (int i = 0; i < 10; i++) { | 457 loop2: for (int i = 0; i < 10; i++) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 570 } |
| 566 '''; | 571 '''; |
| 567 CompilationUnit unit = resolveSource(text); | 572 CompilationUnit unit = resolveSource(text); |
| 568 ContinueStatement continueStatement = EngineTestCase.findNode( | 573 ContinueStatement continueStatement = EngineTestCase.findNode( |
| 569 unit, text, 'continue', (n) => n is ContinueStatement); | 574 unit, text, 'continue', (n) => n is ContinueStatement); |
| 570 expect(continueStatement.target, isNull); | 575 expect(continueStatement.target, isNull); |
| 571 } | 576 } |
| 572 | 577 |
| 573 test_empty() async { | 578 test_empty() async { |
| 574 Source source = addSource(""); | 579 Source source = addSource(""); |
| 575 await assertNoErrors(source); | 580 await computeAnalysisResult(source); |
| 581 assertNoErrors(source); |
| 576 verify([source]); | 582 verify([source]); |
| 577 } | 583 } |
| 578 | 584 |
| 579 test_entryPoint_exported() async { | 585 test_entryPoint_exported() async { |
| 580 addNamedSource( | 586 addNamedSource( |
| 581 "/two.dart", | 587 "/two.dart", |
| 582 r''' | 588 r''' |
| 583 library two; | 589 library two; |
| 584 main() {}'''); | 590 main() {}'''); |
| 585 Source source = addNamedSource( | 591 Source source = addNamedSource( |
| 586 "/one.dart", | 592 "/one.dart", |
| 587 r''' | 593 r''' |
| 588 library one; | 594 library one; |
| 589 export 'two.dart';'''); | 595 export 'two.dart';'''); |
| 590 LibraryElement library = resolve2(source); | 596 LibraryElement library = resolve2(source); |
| 591 expect(library, isNotNull); | 597 expect(library, isNotNull); |
| 592 FunctionElement main = library.entryPoint; | 598 FunctionElement main = library.entryPoint; |
| 593 expect(main, isNotNull); | 599 expect(main, isNotNull); |
| 594 expect(main.library, isNot(same(library))); | 600 expect(main.library, isNot(same(library))); |
| 595 await assertNoErrors(source); | 601 await computeAnalysisResult(source); |
| 602 assertNoErrors(source); |
| 596 verify([source]); | 603 verify([source]); |
| 597 } | 604 } |
| 598 | 605 |
| 599 test_entryPoint_local() async { | 606 test_entryPoint_local() async { |
| 600 Source source = addNamedSource( | 607 Source source = addNamedSource( |
| 601 "/one.dart", | 608 "/one.dart", |
| 602 r''' | 609 r''' |
| 603 library one; | 610 library one; |
| 604 main() {}'''); | 611 main() {}'''); |
| 605 LibraryElement library = resolve2(source); | 612 LibraryElement library = resolve2(source); |
| 606 expect(library, isNotNull); | 613 expect(library, isNotNull); |
| 607 FunctionElement main = library.entryPoint; | 614 FunctionElement main = library.entryPoint; |
| 608 expect(main, isNotNull); | 615 expect(main, isNotNull); |
| 609 expect(main.library, same(library)); | 616 expect(main.library, same(library)); |
| 610 await assertNoErrors(source); | 617 await computeAnalysisResult(source); |
| 618 assertNoErrors(source); |
| 611 verify([source]); | 619 verify([source]); |
| 612 } | 620 } |
| 613 | 621 |
| 614 test_entryPoint_none() async { | 622 test_entryPoint_none() async { |
| 615 Source source = addNamedSource("/one.dart", "library one;"); | 623 Source source = addNamedSource("/one.dart", "library one;"); |
| 616 LibraryElement library = resolve2(source); | 624 LibraryElement library = resolve2(source); |
| 617 expect(library, isNotNull); | 625 expect(library, isNotNull); |
| 618 expect(library.entryPoint, isNull); | 626 expect(library.entryPoint, isNull); |
| 619 await assertNoErrors(source); | 627 await computeAnalysisResult(source); |
| 628 assertNoErrors(source); |
| 620 verify([source]); | 629 verify([source]); |
| 621 } | 630 } |
| 622 | 631 |
| 623 test_enum_externalLibrary() async { | 632 test_enum_externalLibrary() async { |
| 624 addNamedSource( | 633 addNamedSource( |
| 625 "/my_lib.dart", | 634 "/my_lib.dart", |
| 626 r''' | 635 r''' |
| 627 library my_lib; | 636 library my_lib; |
| 628 enum EEE {A, B, C}'''); | 637 enum EEE {A, B, C}'''); |
| 629 Source source = addSource(r''' | 638 Source source = addSource(r''' |
| 630 import 'my_lib.dart'; | 639 import 'my_lib.dart'; |
| 631 main() { | 640 main() { |
| 632 EEE e = null; | 641 EEE e = null; |
| 633 }'''); | 642 }'''); |
| 634 await assertNoErrors(source); | 643 await computeAnalysisResult(source); |
| 644 assertNoErrors(source); |
| 635 verify([source]); | 645 verify([source]); |
| 636 } | 646 } |
| 637 | 647 |
| 638 test_extractedMethodAsConstant() async { | 648 test_extractedMethodAsConstant() async { |
| 639 Source source = addSource(r''' | 649 Source source = addSource(r''' |
| 640 abstract class Comparable<T> { | 650 abstract class Comparable<T> { |
| 641 int compareTo(T other); | 651 int compareTo(T other); |
| 642 static int compare(Comparable a, Comparable b) => a.compareTo(b); | 652 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 643 } | 653 } |
| 644 class A { | 654 class A { |
| 645 void sort([compare = Comparable.compare]) {} | 655 void sort([compare = Comparable.compare]) {} |
| 646 }'''); | 656 }'''); |
| 647 await assertNoErrors(source); | 657 await computeAnalysisResult(source); |
| 658 assertNoErrors(source); |
| 648 verify([source]); | 659 verify([source]); |
| 649 } | 660 } |
| 650 | 661 |
| 651 test_fieldFormalParameter() async { | 662 test_fieldFormalParameter() async { |
| 652 Source source = addSource(r''' | 663 Source source = addSource(r''' |
| 653 class A { | 664 class A { |
| 654 int x; | 665 int x; |
| 655 int y; | 666 int y; |
| 656 A(this.x) : y = x {} | 667 A(this.x) : y = x {} |
| 657 }'''); | 668 }'''); |
| 658 CompilationUnit unit = | 669 CompilationUnit unit = |
| 659 analysisContext2.resolveCompilationUnit2(source, source); | 670 analysisContext2.resolveCompilationUnit2(source, source); |
| 660 ClassDeclaration classA = unit.declarations[0]; | 671 ClassDeclaration classA = unit.declarations[0]; |
| 661 FieldDeclaration field = classA.members[0]; | 672 FieldDeclaration field = classA.members[0]; |
| 662 ConstructorDeclaration constructor = classA.members[2]; | 673 ConstructorDeclaration constructor = classA.members[2]; |
| 663 ParameterElement paramElement = | 674 ParameterElement paramElement = |
| 664 constructor.parameters.parameters[0].element; | 675 constructor.parameters.parameters[0].element; |
| 665 expect(paramElement, new isInstanceOf<FieldFormalParameterElement>()); | 676 expect(paramElement, new isInstanceOf<FieldFormalParameterElement>()); |
| 666 expect((paramElement as FieldFormalParameterElement).field, | 677 expect((paramElement as FieldFormalParameterElement).field, |
| 667 field.fields.variables[0].element); | 678 field.fields.variables[0].element); |
| 668 ConstructorFieldInitializer initializer = constructor.initializers[0]; | 679 ConstructorFieldInitializer initializer = constructor.initializers[0]; |
| 669 SimpleIdentifier identifierX = initializer.expression; | 680 SimpleIdentifier identifierX = initializer.expression; |
| 670 expect(identifierX.staticElement, paramElement); | 681 expect(identifierX.staticElement, paramElement); |
| 671 | 682 |
| 672 await assertNoErrors(source); | 683 await computeAnalysisResult(source); |
| 684 assertNoErrors(source); |
| 673 verify([source]); | 685 verify([source]); |
| 674 } | 686 } |
| 675 | 687 |
| 676 test_forEachLoops_nonConflicting() async { | 688 test_forEachLoops_nonConflicting() async { |
| 677 Source source = addSource(r''' | 689 Source source = addSource(r''' |
| 678 f() { | 690 f() { |
| 679 List list = [1,2,3]; | 691 List list = [1,2,3]; |
| 680 for (int x in list) {} | 692 for (int x in list) {} |
| 681 for (int x in list) {} | 693 for (int x in list) {} |
| 682 }'''); | 694 }'''); |
| 683 await assertNoErrors(source); | 695 await computeAnalysisResult(source); |
| 696 assertNoErrors(source); |
| 684 verify([source]); | 697 verify([source]); |
| 685 } | 698 } |
| 686 | 699 |
| 687 test_forLoops_nonConflicting() async { | 700 test_forLoops_nonConflicting() async { |
| 688 Source source = addSource(r''' | 701 Source source = addSource(r''' |
| 689 f() { | 702 f() { |
| 690 for (int i = 0; i < 3; i++) { | 703 for (int i = 0; i < 3; i++) { |
| 691 } | 704 } |
| 692 for (int i = 0; i < 3; i++) { | 705 for (int i = 0; i < 3; i++) { |
| 693 } | 706 } |
| 694 }'''); | 707 }'''); |
| 695 await assertNoErrors(source); | 708 await computeAnalysisResult(source); |
| 709 assertNoErrors(source); |
| 696 verify([source]); | 710 verify([source]); |
| 697 } | 711 } |
| 698 | 712 |
| 699 test_functionTypeAlias() async { | 713 test_functionTypeAlias() async { |
| 700 Source source = addSource(r''' | 714 Source source = addSource(r''' |
| 701 typedef bool P(e); | 715 typedef bool P(e); |
| 702 class A { | 716 class A { |
| 703 P p; | 717 P p; |
| 704 m(e) { | 718 m(e) { |
| 705 if (p(e)) {} | 719 if (p(e)) {} |
| 706 } | 720 } |
| 707 }'''); | 721 }'''); |
| 708 await assertNoErrors(source); | 722 await computeAnalysisResult(source); |
| 723 assertNoErrors(source); |
| 709 verify([source]); | 724 verify([source]); |
| 710 } | 725 } |
| 711 | 726 |
| 712 test_getter_and_setter_fromMixins_bare_identifier() async { | 727 test_getter_and_setter_fromMixins_bare_identifier() async { |
| 713 Source source = addSource(''' | 728 Source source = addSource(''' |
| 714 class B {} | 729 class B {} |
| 715 class M1 { | 730 class M1 { |
| 716 get x => null; | 731 get x => null; |
| 717 set x(value) {} | 732 set x(value) {} |
| 718 } | 733 } |
| 719 class M2 { | 734 class M2 { |
| 720 get x => null; | 735 get x => null; |
| 721 set x(value) {} | 736 set x(value) {} |
| 722 } | 737 } |
| 723 class C extends B with M1, M2 { | 738 class C extends B with M1, M2 { |
| 724 void f() { | 739 void f() { |
| 725 x += 1; | 740 x += 1; |
| 726 } | 741 } |
| 727 } | 742 } |
| 728 '''); | 743 '''); |
| 729 LibraryElement library = resolve2(source); | 744 LibraryElement library = resolve2(source); |
| 730 await assertNoErrors(source); | 745 await computeAnalysisResult(source); |
| 746 assertNoErrors(source); |
| 731 verify([source]); | 747 verify([source]); |
| 732 // Verify that both the getter and setter for "x" in C.f() refer to the | 748 // Verify that both the getter and setter for "x" in C.f() refer to the |
| 733 // accessors defined in M2. | 749 // accessors defined in M2. |
| 734 ClassElement classC = library.definingCompilationUnit.types[3]; | 750 ClassElement classC = library.definingCompilationUnit.types[3]; |
| 735 MethodDeclaration f = classC.getMethod('f').computeNode(); | 751 MethodDeclaration f = classC.getMethod('f').computeNode(); |
| 736 BlockFunctionBody body = f.body; | 752 BlockFunctionBody body = f.body; |
| 737 ExpressionStatement stmt = body.block.statements[0]; | 753 ExpressionStatement stmt = body.block.statements[0]; |
| 738 AssignmentExpression assignment = stmt.expression; | 754 AssignmentExpression assignment = stmt.expression; |
| 739 SimpleIdentifier leftHandSide = assignment.leftHandSide; | 755 SimpleIdentifier leftHandSide = assignment.leftHandSide; |
| 740 expect( | 756 expect( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 761 class M2 { | 777 class M2 { |
| 762 get x => null; | 778 get x => null; |
| 763 set x(value) {} | 779 set x(value) {} |
| 764 } | 780 } |
| 765 class C extends B with M1, M2 {} | 781 class C extends B with M1, M2 {} |
| 766 void main() { | 782 void main() { |
| 767 new C().x += 1; | 783 new C().x += 1; |
| 768 } | 784 } |
| 769 '''); | 785 '''); |
| 770 LibraryElement library = resolve2(source); | 786 LibraryElement library = resolve2(source); |
| 771 await assertNoErrors(source); | 787 await computeAnalysisResult(source); |
| 788 assertNoErrors(source); |
| 772 verify([source]); | 789 verify([source]); |
| 773 // Verify that both the getter and setter for "x" in "new C().x" refer to | 790 // Verify that both the getter and setter for "x" in "new C().x" refer to |
| 774 // the accessors defined in M2. | 791 // the accessors defined in M2. |
| 775 FunctionDeclaration main = | 792 FunctionDeclaration main = |
| 776 library.definingCompilationUnit.functions[0].computeNode(); | 793 library.definingCompilationUnit.functions[0].computeNode(); |
| 777 BlockFunctionBody body = main.functionExpression.body; | 794 BlockFunctionBody body = main.functionExpression.body; |
| 778 ExpressionStatement stmt = body.block.statements[0]; | 795 ExpressionStatement stmt = body.block.statements[0]; |
| 779 AssignmentExpression assignment = stmt.expression; | 796 AssignmentExpression assignment = stmt.expression; |
| 780 PropertyAccess propertyAccess = assignment.leftHandSide; | 797 PropertyAccess propertyAccess = assignment.leftHandSide; |
| 781 expect( | 798 expect( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 799 class M2 { | 816 class M2 { |
| 800 get x => null; | 817 get x => null; |
| 801 } | 818 } |
| 802 class C extends B with M1, M2 { | 819 class C extends B with M1, M2 { |
| 803 f() { | 820 f() { |
| 804 return x; | 821 return x; |
| 805 } | 822 } |
| 806 } | 823 } |
| 807 '''); | 824 '''); |
| 808 LibraryElement library = resolve2(source); | 825 LibraryElement library = resolve2(source); |
| 809 await assertNoErrors(source); | 826 await computeAnalysisResult(source); |
| 827 assertNoErrors(source); |
| 810 verify([source]); | 828 verify([source]); |
| 811 // Verify that the getter for "x" in C.f() refers to the getter defined in | 829 // Verify that the getter for "x" in C.f() refers to the getter defined in |
| 812 // M2. | 830 // M2. |
| 813 ClassElement classC = library.definingCompilationUnit.types[3]; | 831 ClassElement classC = library.definingCompilationUnit.types[3]; |
| 814 MethodDeclaration f = classC.getMethod('f').computeNode(); | 832 MethodDeclaration f = classC.getMethod('f').computeNode(); |
| 815 BlockFunctionBody body = f.body; | 833 BlockFunctionBody body = f.body; |
| 816 ReturnStatement stmt = body.block.statements[0]; | 834 ReturnStatement stmt = body.block.statements[0]; |
| 817 SimpleIdentifier x = stmt.expression; | 835 SimpleIdentifier x = stmt.expression; |
| 818 expect(resolutionMap.staticElementForIdentifier(x).enclosingElement.name, | 836 expect(resolutionMap.staticElementForIdentifier(x).enclosingElement.name, |
| 819 'M2'); | 837 'M2'); |
| 820 } | 838 } |
| 821 | 839 |
| 822 test_getter_fromMixins_property_access() async { | 840 test_getter_fromMixins_property_access() async { |
| 823 Source source = addSource(''' | 841 Source source = addSource(''' |
| 824 class B {} | 842 class B {} |
| 825 class M1 { | 843 class M1 { |
| 826 get x => null; | 844 get x => null; |
| 827 } | 845 } |
| 828 class M2 { | 846 class M2 { |
| 829 get x => null; | 847 get x => null; |
| 830 } | 848 } |
| 831 class C extends B with M1, M2 {} | 849 class C extends B with M1, M2 {} |
| 832 void main() { | 850 void main() { |
| 833 var y = new C().x; | 851 var y = new C().x; |
| 834 } | 852 } |
| 835 '''); | 853 '''); |
| 836 LibraryElement library = resolve2(source); | 854 LibraryElement library = resolve2(source); |
| 837 await assertNoErrors(source); | 855 await computeAnalysisResult(source); |
| 856 assertNoErrors(source); |
| 838 verify([source]); | 857 verify([source]); |
| 839 // Verify that the getter for "x" in "new C().x" refers to the getter | 858 // Verify that the getter for "x" in "new C().x" refers to the getter |
| 840 // defined in M2. | 859 // defined in M2. |
| 841 FunctionDeclaration main = | 860 FunctionDeclaration main = |
| 842 library.definingCompilationUnit.functions[0].computeNode(); | 861 library.definingCompilationUnit.functions[0].computeNode(); |
| 843 BlockFunctionBody body = main.functionExpression.body; | 862 BlockFunctionBody body = main.functionExpression.body; |
| 844 VariableDeclarationStatement stmt = body.block.statements[0]; | 863 VariableDeclarationStatement stmt = body.block.statements[0]; |
| 845 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer; | 864 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer; |
| 846 expect( | 865 expect( |
| 847 resolutionMap | 866 resolutionMap |
| 848 .staticElementForIdentifier(propertyAccess.propertyName) | 867 .staticElementForIdentifier(propertyAccess.propertyName) |
| 849 .enclosingElement | 868 .enclosingElement |
| 850 .name, | 869 .name, |
| 851 'M2'); | 870 'M2'); |
| 852 } | 871 } |
| 853 | 872 |
| 854 test_getterAndSetterWithDifferentTypes() async { | 873 test_getterAndSetterWithDifferentTypes() async { |
| 855 Source source = addSource(r''' | 874 Source source = addSource(r''' |
| 856 class A { | 875 class A { |
| 857 int get f => 0; | 876 int get f => 0; |
| 858 void set f(String s) {} | 877 void set f(String s) {} |
| 859 } | 878 } |
| 860 g (A a) { | 879 g (A a) { |
| 861 a.f = a.f.toString(); | 880 a.f = a.f.toString(); |
| 862 }'''); | 881 }'''); |
| 863 await assertErrors( | 882 await computeAnalysisResult(source); |
| 883 assertErrors( |
| 864 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); | 884 source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]); |
| 865 verify([source]); | 885 verify([source]); |
| 866 } | 886 } |
| 867 | 887 |
| 868 test_hasReferenceToSuper() async { | 888 test_hasReferenceToSuper() async { |
| 869 Source source = addSource(r''' | 889 Source source = addSource(r''' |
| 870 class A {} | 890 class A {} |
| 871 class B {toString() => super.toString();}'''); | 891 class B {toString() => super.toString();}'''); |
| 872 LibraryElement library = resolve2(source); | 892 LibraryElement library = resolve2(source); |
| 873 expect(library, isNotNull); | 893 expect(library, isNotNull); |
| 874 CompilationUnitElement unit = library.definingCompilationUnit; | 894 CompilationUnitElement unit = library.definingCompilationUnit; |
| 875 expect(unit, isNotNull); | 895 expect(unit, isNotNull); |
| 876 List<ClassElement> classes = unit.types; | 896 List<ClassElement> classes = unit.types; |
| 877 expect(classes, hasLength(2)); | 897 expect(classes, hasLength(2)); |
| 878 expect(classes[0].hasReferenceToSuper, isFalse); | 898 expect(classes[0].hasReferenceToSuper, isFalse); |
| 879 expect(classes[1].hasReferenceToSuper, isTrue); | 899 expect(classes[1].hasReferenceToSuper, isTrue); |
| 880 await assertNoErrors(source); | 900 await computeAnalysisResult(source); |
| 901 assertNoErrors(source); |
| 881 verify([source]); | 902 verify([source]); |
| 882 } | 903 } |
| 883 | 904 |
| 884 test_import_hide() async { | 905 test_import_hide() async { |
| 885 addNamedSource( | 906 addNamedSource( |
| 886 "/lib1.dart", | 907 "/lib1.dart", |
| 887 r''' | 908 r''' |
| 888 library lib1; | 909 library lib1; |
| 889 set foo(value) {} | 910 set foo(value) {} |
| 890 class A {}'''); | 911 class A {}'''); |
| 891 addNamedSource( | 912 addNamedSource( |
| 892 "/lib2.dart", | 913 "/lib2.dart", |
| 893 r''' | 914 r''' |
| 894 library lib2; | 915 library lib2; |
| 895 set foo(value) {}'''); | 916 set foo(value) {}'''); |
| 896 Source source = addNamedSource( | 917 Source source = addNamedSource( |
| 897 "/lib3.dart", | 918 "/lib3.dart", |
| 898 r''' | 919 r''' |
| 899 import 'lib1.dart' hide foo; | 920 import 'lib1.dart' hide foo; |
| 900 import 'lib2.dart'; | 921 import 'lib2.dart'; |
| 901 | 922 |
| 902 main() { | 923 main() { |
| 903 foo = 0; | 924 foo = 0; |
| 904 } | 925 } |
| 905 A a;'''); | 926 A a;'''); |
| 906 await assertNoErrors(source); | 927 await computeAnalysisResult(source); |
| 928 assertNoErrors(source); |
| 907 verify([source]); | 929 verify([source]); |
| 908 } | 930 } |
| 909 | 931 |
| 910 test_import_prefix() async { | 932 test_import_prefix() async { |
| 911 addNamedSource( | 933 addNamedSource( |
| 912 "/two.dart", | 934 "/two.dart", |
| 913 r''' | 935 r''' |
| 914 library two; | 936 library two; |
| 915 f(int x) { | 937 f(int x) { |
| 916 return x * x; | 938 return x * x; |
| 917 }'''); | 939 }'''); |
| 918 Source source = addNamedSource( | 940 Source source = addNamedSource( |
| 919 "/one.dart", | 941 "/one.dart", |
| 920 r''' | 942 r''' |
| 921 library one; | 943 library one; |
| 922 import 'two.dart' as _two; | 944 import 'two.dart' as _two; |
| 923 main() { | 945 main() { |
| 924 _two.f(0); | 946 _two.f(0); |
| 925 }'''); | 947 }'''); |
| 926 await assertNoErrors(source); | 948 await computeAnalysisResult(source); |
| 949 assertNoErrors(source); |
| 927 verify([source]); | 950 verify([source]); |
| 928 } | 951 } |
| 929 | 952 |
| 930 test_import_prefix_doesNotExist() async { | 953 test_import_prefix_doesNotExist() async { |
| 931 // | 954 // |
| 932 // The primary purpose of this test is to ensure that we are only getting a | 955 // The primary purpose of this test is to ensure that we are only getting a |
| 933 // single error generated when the only problem is that an imported file | 956 // single error generated when the only problem is that an imported file |
| 934 // does not exist. | 957 // does not exist. |
| 935 // | 958 // |
| 936 Source source = addNamedSource( | 959 Source source = addNamedSource( |
| 937 "/a.dart", | 960 "/a.dart", |
| 938 r''' | 961 r''' |
| 939 import 'missing.dart' as p; | 962 import 'missing.dart' as p; |
| 940 int a = p.q + p.r.s; | 963 int a = p.q + p.r.s; |
| 941 String b = p.t(a) + p.u(v: 0); | 964 String b = p.t(a) + p.u(v: 0); |
| 942 p.T c = new p.T(); | 965 p.T c = new p.T(); |
| 943 class D<E> extends p.T { | 966 class D<E> extends p.T { |
| 944 D(int i) : super(i); | 967 D(int i) : super(i); |
| 945 p.U f = new p.V(); | 968 p.U f = new p.V(); |
| 946 } | 969 } |
| 947 class F implements p.T { | 970 class F implements p.T { |
| 948 p.T m(p.U u) => null; | 971 p.T m(p.U u) => null; |
| 949 } | 972 } |
| 950 class G extends Object with p.V {} | 973 class G extends Object with p.V {} |
| 951 class H extends D<p.W> { | 974 class H extends D<p.W> { |
| 952 H(int i) : super(i); | 975 H(int i) : super(i); |
| 953 } | 976 } |
| 954 '''); | 977 '''); |
| 955 await assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 978 await computeAnalysisResult(source); |
| 979 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 956 verify([source]); | 980 verify([source]); |
| 957 } | 981 } |
| 958 | 982 |
| 959 test_import_show_doesNotExist() async { | 983 test_import_show_doesNotExist() async { |
| 960 // | 984 // |
| 961 // The primary purpose of this test is to ensure that we are only getting a | 985 // The primary purpose of this test is to ensure that we are only getting a |
| 962 // single error generated when the only problem is that an imported file | 986 // single error generated when the only problem is that an imported file |
| 963 // does not exist. | 987 // does not exist. |
| 964 // | 988 // |
| 965 Source source = addNamedSource( | 989 Source source = addNamedSource( |
| 966 "/a.dart", | 990 "/a.dart", |
| 967 r''' | 991 r''' |
| 968 import 'missing.dart' show q, r, t, u, T, U, V, W; | 992 import 'missing.dart' show q, r, t, u, T, U, V, W; |
| 969 int a = q + r.s; | 993 int a = q + r.s; |
| 970 String b = t(a) + u(v: 0); | 994 String b = t(a) + u(v: 0); |
| 971 T c = new T(); | 995 T c = new T(); |
| 972 class D<E> extends T { | 996 class D<E> extends T { |
| 973 D(int i) : super(i); | 997 D(int i) : super(i); |
| 974 U f = new V(); | 998 U f = new V(); |
| 975 } | 999 } |
| 976 class F implements T { | 1000 class F implements T { |
| 977 T m(U u) => null; | 1001 T m(U u) => null; |
| 978 } | 1002 } |
| 979 class G extends Object with V {} | 1003 class G extends Object with V {} |
| 980 class H extends D<W> { | 1004 class H extends D<W> { |
| 981 H(int i) : super(i); | 1005 H(int i) : super(i); |
| 982 } | 1006 } |
| 983 '''); | 1007 '''); |
| 984 await assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 1008 await computeAnalysisResult(source); |
| 1009 assertErrors(source, [CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 985 verify([source]); | 1010 verify([source]); |
| 986 } | 1011 } |
| 987 | 1012 |
| 988 test_import_spaceInUri() async { | 1013 test_import_spaceInUri() async { |
| 989 addNamedSource( | 1014 addNamedSource( |
| 990 "/sub folder/lib.dart", | 1015 "/sub folder/lib.dart", |
| 991 r''' | 1016 r''' |
| 992 library lib; | 1017 library lib; |
| 993 foo() {}'''); | 1018 foo() {}'''); |
| 994 Source source = addNamedSource( | 1019 Source source = addNamedSource( |
| 995 "/app.dart", | 1020 "/app.dart", |
| 996 r''' | 1021 r''' |
| 997 import 'sub folder/lib.dart'; | 1022 import 'sub folder/lib.dart'; |
| 998 | 1023 |
| 999 main() { | 1024 main() { |
| 1000 foo(); | 1025 foo(); |
| 1001 }'''); | 1026 }'''); |
| 1002 await assertNoErrors(source); | 1027 await computeAnalysisResult(source); |
| 1028 assertNoErrors(source); |
| 1003 verify([source]); | 1029 verify([source]); |
| 1004 } | 1030 } |
| 1005 | 1031 |
| 1006 test_indexExpression_typeParameters() async { | 1032 test_indexExpression_typeParameters() async { |
| 1007 Source source = addSource(r''' | 1033 Source source = addSource(r''' |
| 1008 f() { | 1034 f() { |
| 1009 List<int> a; | 1035 List<int> a; |
| 1010 a[0]; | 1036 a[0]; |
| 1011 List<List<int>> b; | 1037 List<List<int>> b; |
| 1012 b[0][0]; | 1038 b[0][0]; |
| 1013 List<List<List<int>>> c; | 1039 List<List<List<int>>> c; |
| 1014 c[0][0][0]; | 1040 c[0][0][0]; |
| 1015 }'''); | 1041 }'''); |
| 1016 await assertNoErrors(source); | 1042 await computeAnalysisResult(source); |
| 1043 assertNoErrors(source); |
| 1017 verify([source]); | 1044 verify([source]); |
| 1018 } | 1045 } |
| 1019 | 1046 |
| 1020 test_indexExpression_typeParameters_invalidAssignmentWarning() async { | 1047 test_indexExpression_typeParameters_invalidAssignmentWarning() async { |
| 1021 Source source = addSource(r''' | 1048 Source source = addSource(r''' |
| 1022 f() { | 1049 f() { |
| 1023 List<List<int>> b; | 1050 List<List<int>> b; |
| 1024 b[0][0] = 'hi'; | 1051 b[0][0] = 'hi'; |
| 1025 }'''); | 1052 }'''); |
| 1026 await assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); | 1053 await computeAnalysisResult(source); |
| 1054 assertErrors(source, [StaticTypeWarningCode.INVALID_ASSIGNMENT]); |
| 1027 verify([source]); | 1055 verify([source]); |
| 1028 } | 1056 } |
| 1029 | 1057 |
| 1030 test_indirectOperatorThroughCall() async { | 1058 test_indirectOperatorThroughCall() async { |
| 1031 Source source = addSource(r''' | 1059 Source source = addSource(r''' |
| 1032 class A { | 1060 class A { |
| 1033 B call() { return new B(); } | 1061 B call() { return new B(); } |
| 1034 } | 1062 } |
| 1035 | 1063 |
| 1036 class B { | 1064 class B { |
| 1037 int operator [](int i) { return i; } | 1065 int operator [](int i) { return i; } |
| 1038 } | 1066 } |
| 1039 | 1067 |
| 1040 A f = new A(); | 1068 A f = new A(); |
| 1041 | 1069 |
| 1042 g(int x) {} | 1070 g(int x) {} |
| 1043 | 1071 |
| 1044 main() { | 1072 main() { |
| 1045 g(f()[0]); | 1073 g(f()[0]); |
| 1046 }'''); | 1074 }'''); |
| 1047 await assertNoErrors(source); | 1075 await computeAnalysisResult(source); |
| 1076 assertNoErrors(source); |
| 1048 verify([source]); | 1077 verify([source]); |
| 1049 } | 1078 } |
| 1050 | 1079 |
| 1051 test_invoke_dynamicThroughGetter() async { | 1080 test_invoke_dynamicThroughGetter() async { |
| 1052 Source source = addSource(r''' | 1081 Source source = addSource(r''' |
| 1053 class A { | 1082 class A { |
| 1054 List get X => [() => 0]; | 1083 List get X => [() => 0]; |
| 1055 m(A a) { | 1084 m(A a) { |
| 1056 X.last; | 1085 X.last; |
| 1057 } | 1086 } |
| 1058 }'''); | 1087 }'''); |
| 1059 await assertNoErrors(source); | 1088 await computeAnalysisResult(source); |
| 1089 assertNoErrors(source); |
| 1060 verify([source]); | 1090 verify([source]); |
| 1061 } | 1091 } |
| 1062 | 1092 |
| 1063 test_isValidMixin_badSuperclass() async { | 1093 test_isValidMixin_badSuperclass() async { |
| 1064 Source source = addSource(r''' | 1094 Source source = addSource(r''' |
| 1065 class A extends B {} | 1095 class A extends B {} |
| 1066 class B {} | 1096 class B {} |
| 1067 class C = Object with A;'''); | 1097 class C = Object with A;'''); |
| 1068 LibraryElement library = resolve2(source); | 1098 LibraryElement library = resolve2(source); |
| 1069 expect(library, isNotNull); | 1099 expect(library, isNotNull); |
| 1070 CompilationUnitElement unit = library.definingCompilationUnit; | 1100 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1071 expect(unit, isNotNull); | 1101 expect(unit, isNotNull); |
| 1072 ClassElement a = unit.getType('A'); | 1102 ClassElement a = unit.getType('A'); |
| 1073 expect(a.isValidMixin, isFalse); | 1103 expect(a.isValidMixin, isFalse); |
| 1074 await assertErrors( | 1104 await computeAnalysisResult(source); |
| 1075 source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); | 1105 assertErrors(source, [CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]); |
| 1076 verify([source]); | 1106 verify([source]); |
| 1077 } | 1107 } |
| 1078 | 1108 |
| 1079 test_isValidMixin_badSuperclass_withSuperMixins() async { | 1109 test_isValidMixin_badSuperclass_withSuperMixins() async { |
| 1080 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); | 1110 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); |
| 1081 Source source = addSource(r''' | 1111 Source source = addSource(r''' |
| 1082 class A extends B {} | 1112 class A extends B {} |
| 1083 class B {} | 1113 class B {} |
| 1084 class C = Object with A;'''); | 1114 class C = Object with A;'''); |
| 1085 LibraryElement library = resolve2(source); | 1115 LibraryElement library = resolve2(source); |
| 1086 expect(library, isNotNull); | 1116 expect(library, isNotNull); |
| 1087 CompilationUnitElement unit = library.definingCompilationUnit; | 1117 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1088 expect(unit, isNotNull); | 1118 expect(unit, isNotNull); |
| 1089 ClassElement a = unit.getType('A'); | 1119 ClassElement a = unit.getType('A'); |
| 1090 expect(a.isValidMixin, isTrue); | 1120 expect(a.isValidMixin, isTrue); |
| 1091 await assertNoErrors(source); | 1121 await computeAnalysisResult(source); |
| 1122 assertNoErrors(source); |
| 1092 verify([source]); | 1123 verify([source]); |
| 1093 } | 1124 } |
| 1094 | 1125 |
| 1095 test_isValidMixin_constructor() async { | 1126 test_isValidMixin_constructor() async { |
| 1096 Source source = addSource(r''' | 1127 Source source = addSource(r''' |
| 1097 class A { | 1128 class A { |
| 1098 A() {} | 1129 A() {} |
| 1099 } | 1130 } |
| 1100 class C = Object with A;'''); | 1131 class C = Object with A;'''); |
| 1101 LibraryElement library = resolve2(source); | 1132 LibraryElement library = resolve2(source); |
| 1102 expect(library, isNotNull); | 1133 expect(library, isNotNull); |
| 1103 CompilationUnitElement unit = library.definingCompilationUnit; | 1134 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1104 expect(unit, isNotNull); | 1135 expect(unit, isNotNull); |
| 1105 ClassElement a = unit.getType('A'); | 1136 ClassElement a = unit.getType('A'); |
| 1106 expect(a.isValidMixin, isFalse); | 1137 expect(a.isValidMixin, isFalse); |
| 1107 await assertErrors( | 1138 await computeAnalysisResult(source); |
| 1108 source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); | 1139 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
| 1109 verify([source]); | 1140 verify([source]); |
| 1110 } | 1141 } |
| 1111 | 1142 |
| 1112 test_isValidMixin_constructor_withSuperMixins() async { | 1143 test_isValidMixin_constructor_withSuperMixins() async { |
| 1113 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); | 1144 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); |
| 1114 Source source = addSource(r''' | 1145 Source source = addSource(r''' |
| 1115 class A { | 1146 class A { |
| 1116 A() {} | 1147 A() {} |
| 1117 } | 1148 } |
| 1118 class C = Object with A;'''); | 1149 class C = Object with A;'''); |
| 1119 LibraryElement library = resolve2(source); | 1150 LibraryElement library = resolve2(source); |
| 1120 expect(library, isNotNull); | 1151 expect(library, isNotNull); |
| 1121 CompilationUnitElement unit = library.definingCompilationUnit; | 1152 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1122 expect(unit, isNotNull); | 1153 expect(unit, isNotNull); |
| 1123 ClassElement a = unit.getType('A'); | 1154 ClassElement a = unit.getType('A'); |
| 1124 expect(a.isValidMixin, isFalse); | 1155 expect(a.isValidMixin, isFalse); |
| 1125 await assertErrors( | 1156 await computeAnalysisResult(source); |
| 1126 source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); | 1157 assertErrors(source, [CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]); |
| 1127 verify([source]); | 1158 verify([source]); |
| 1128 } | 1159 } |
| 1129 | 1160 |
| 1130 test_isValidMixin_factoryConstructor() async { | 1161 test_isValidMixin_factoryConstructor() async { |
| 1131 Source source = addSource(r''' | 1162 Source source = addSource(r''' |
| 1132 class A { | 1163 class A { |
| 1133 factory A() => null; | 1164 factory A() => null; |
| 1134 } | 1165 } |
| 1135 class C = Object with A;'''); | 1166 class C = Object with A;'''); |
| 1136 LibraryElement library = resolve2(source); | 1167 LibraryElement library = resolve2(source); |
| 1137 expect(library, isNotNull); | 1168 expect(library, isNotNull); |
| 1138 CompilationUnitElement unit = library.definingCompilationUnit; | 1169 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1139 expect(unit, isNotNull); | 1170 expect(unit, isNotNull); |
| 1140 ClassElement a = unit.getType('A'); | 1171 ClassElement a = unit.getType('A'); |
| 1141 expect(a.isValidMixin, isTrue); | 1172 expect(a.isValidMixin, isTrue); |
| 1142 await assertNoErrors(source); | 1173 await computeAnalysisResult(source); |
| 1174 assertNoErrors(source); |
| 1143 verify([source]); | 1175 verify([source]); |
| 1144 } | 1176 } |
| 1145 | 1177 |
| 1146 test_isValidMixin_factoryConstructor_withSuperMixins() async { | 1178 test_isValidMixin_factoryConstructor_withSuperMixins() async { |
| 1147 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); | 1179 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); |
| 1148 Source source = addSource(r''' | 1180 Source source = addSource(r''' |
| 1149 class A { | 1181 class A { |
| 1150 factory A() => null; | 1182 factory A() => null; |
| 1151 } | 1183 } |
| 1152 class C = Object with A;'''); | 1184 class C = Object with A;'''); |
| 1153 LibraryElement library = resolve2(source); | 1185 LibraryElement library = resolve2(source); |
| 1154 expect(library, isNotNull); | 1186 expect(library, isNotNull); |
| 1155 CompilationUnitElement unit = library.definingCompilationUnit; | 1187 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1156 expect(unit, isNotNull); | 1188 expect(unit, isNotNull); |
| 1157 ClassElement a = unit.getType('A'); | 1189 ClassElement a = unit.getType('A'); |
| 1158 expect(a.isValidMixin, isTrue); | 1190 expect(a.isValidMixin, isTrue); |
| 1159 await assertNoErrors(source); | 1191 await computeAnalysisResult(source); |
| 1192 assertNoErrors(source); |
| 1160 verify([source]); | 1193 verify([source]); |
| 1161 } | 1194 } |
| 1162 | 1195 |
| 1163 test_isValidMixin_super() async { | 1196 test_isValidMixin_super() async { |
| 1164 Source source = addSource(r''' | 1197 Source source = addSource(r''' |
| 1165 class A { | 1198 class A { |
| 1166 toString() { | 1199 toString() { |
| 1167 return super.toString(); | 1200 return super.toString(); |
| 1168 } | 1201 } |
| 1169 } | 1202 } |
| 1170 class C = Object with A;'''); | 1203 class C = Object with A;'''); |
| 1171 LibraryElement library = resolve2(source); | 1204 LibraryElement library = resolve2(source); |
| 1172 expect(library, isNotNull); | 1205 expect(library, isNotNull); |
| 1173 CompilationUnitElement unit = library.definingCompilationUnit; | 1206 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1174 expect(unit, isNotNull); | 1207 expect(unit, isNotNull); |
| 1175 ClassElement a = unit.getType('A'); | 1208 ClassElement a = unit.getType('A'); |
| 1176 expect(a.isValidMixin, isFalse); | 1209 expect(a.isValidMixin, isFalse); |
| 1177 await assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]); | 1210 await computeAnalysisResult(source); |
| 1211 assertErrors(source, [CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]); |
| 1178 verify([source]); | 1212 verify([source]); |
| 1179 } | 1213 } |
| 1180 | 1214 |
| 1181 test_isValidMixin_super_withSuperMixins() async { | 1215 test_isValidMixin_super_withSuperMixins() async { |
| 1182 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); | 1216 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); |
| 1183 Source source = addSource(r''' | 1217 Source source = addSource(r''' |
| 1184 class A { | 1218 class A { |
| 1185 toString() { | 1219 toString() { |
| 1186 return super.toString(); | 1220 return super.toString(); |
| 1187 } | 1221 } |
| 1188 } | 1222 } |
| 1189 class C = Object with A;'''); | 1223 class C = Object with A;'''); |
| 1190 LibraryElement library = resolve2(source); | 1224 LibraryElement library = resolve2(source); |
| 1191 expect(library, isNotNull); | 1225 expect(library, isNotNull); |
| 1192 CompilationUnitElement unit = library.definingCompilationUnit; | 1226 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1193 expect(unit, isNotNull); | 1227 expect(unit, isNotNull); |
| 1194 ClassElement a = unit.getType('A'); | 1228 ClassElement a = unit.getType('A'); |
| 1195 expect(a.isValidMixin, isTrue); | 1229 expect(a.isValidMixin, isTrue); |
| 1196 await assertNoErrors(source); | 1230 await computeAnalysisResult(source); |
| 1231 assertNoErrors(source); |
| 1197 verify([source]); | 1232 verify([source]); |
| 1198 } | 1233 } |
| 1199 | 1234 |
| 1200 test_isValidMixin_valid() async { | 1235 test_isValidMixin_valid() async { |
| 1201 Source source = addSource(''' | 1236 Source source = addSource(''' |
| 1202 class A {} | 1237 class A {} |
| 1203 class C = Object with A;'''); | 1238 class C = Object with A;'''); |
| 1204 LibraryElement library = resolve2(source); | 1239 LibraryElement library = resolve2(source); |
| 1205 expect(library, isNotNull); | 1240 expect(library, isNotNull); |
| 1206 CompilationUnitElement unit = library.definingCompilationUnit; | 1241 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1207 expect(unit, isNotNull); | 1242 expect(unit, isNotNull); |
| 1208 ClassElement a = unit.getType('A'); | 1243 ClassElement a = unit.getType('A'); |
| 1209 expect(a.isValidMixin, isTrue); | 1244 expect(a.isValidMixin, isTrue); |
| 1210 await assertNoErrors(source); | 1245 await computeAnalysisResult(source); |
| 1246 assertNoErrors(source); |
| 1211 verify([source]); | 1247 verify([source]); |
| 1212 } | 1248 } |
| 1213 | 1249 |
| 1214 test_isValidMixin_valid_withSuperMixins() async { | 1250 test_isValidMixin_valid_withSuperMixins() async { |
| 1215 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); | 1251 resetWithOptions(new AnalysisOptionsImpl()..enableSuperMixins = true); |
| 1216 Source source = addSource(''' | 1252 Source source = addSource(''' |
| 1217 class A {} | 1253 class A {} |
| 1218 class C = Object with A;'''); | 1254 class C = Object with A;'''); |
| 1219 LibraryElement library = resolve2(source); | 1255 LibraryElement library = resolve2(source); |
| 1220 expect(library, isNotNull); | 1256 expect(library, isNotNull); |
| 1221 CompilationUnitElement unit = library.definingCompilationUnit; | 1257 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1222 expect(unit, isNotNull); | 1258 expect(unit, isNotNull); |
| 1223 ClassElement a = unit.getType('A'); | 1259 ClassElement a = unit.getType('A'); |
| 1224 expect(a.isValidMixin, isTrue); | 1260 expect(a.isValidMixin, isTrue); |
| 1225 await assertNoErrors(source); | 1261 await computeAnalysisResult(source); |
| 1262 assertNoErrors(source); |
| 1226 verify([source]); | 1263 verify([source]); |
| 1227 } | 1264 } |
| 1228 | 1265 |
| 1229 test_labels_switch() async { | 1266 test_labels_switch() async { |
| 1230 Source source = addSource(r''' | 1267 Source source = addSource(r''' |
| 1231 void doSwitch(int target) { | 1268 void doSwitch(int target) { |
| 1232 switch (target) { | 1269 switch (target) { |
| 1233 l0: case 0: | 1270 l0: case 0: |
| 1234 continue l1; | 1271 continue l1; |
| 1235 l1: case 1: | 1272 l1: case 1: |
| 1236 continue l0; | 1273 continue l0; |
| 1237 default: | 1274 default: |
| 1238 continue l1; | 1275 continue l1; |
| 1239 } | 1276 } |
| 1240 }'''); | 1277 }'''); |
| 1241 LibraryElement library = resolve2(source); | 1278 LibraryElement library = resolve2(source); |
| 1242 expect(library, isNotNull); | 1279 expect(library, isNotNull); |
| 1243 await assertNoErrors(source); | 1280 await computeAnalysisResult(source); |
| 1281 assertNoErrors(source); |
| 1244 verify([source]); | 1282 verify([source]); |
| 1245 } | 1283 } |
| 1246 | 1284 |
| 1247 test_localVariable_types_invoked() async { | 1285 test_localVariable_types_invoked() async { |
| 1248 Source source = addSource(r''' | 1286 Source source = addSource(r''' |
| 1249 const A = null; | 1287 const A = null; |
| 1250 main() { | 1288 main() { |
| 1251 var myVar = (int p) => 'foo'; | 1289 var myVar = (int p) => 'foo'; |
| 1252 myVar(42); | 1290 myVar(42); |
| 1253 }'''); | 1291 }'''); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1272 const A = null; | 1310 const A = null; |
| 1273 @A class C<A> {}'''); | 1311 @A class C<A> {}'''); |
| 1274 LibraryElement library = resolve2(source); | 1312 LibraryElement library = resolve2(source); |
| 1275 expect(library, isNotNull); | 1313 expect(library, isNotNull); |
| 1276 CompilationUnitElement unitElement = library.definingCompilationUnit; | 1314 CompilationUnitElement unitElement = library.definingCompilationUnit; |
| 1277 expect(unitElement, isNotNull); | 1315 expect(unitElement, isNotNull); |
| 1278 List<ClassElement> classes = unitElement.types; | 1316 List<ClassElement> classes = unitElement.types; |
| 1279 expect(classes, hasLength(1)); | 1317 expect(classes, hasLength(1)); |
| 1280 List<ElementAnnotation> annotations = classes[0].metadata; | 1318 List<ElementAnnotation> annotations = classes[0].metadata; |
| 1281 expect(annotations, hasLength(1)); | 1319 expect(annotations, hasLength(1)); |
| 1282 await assertNoErrors(source); | 1320 await computeAnalysisResult(source); |
| 1321 assertNoErrors(source); |
| 1283 verify([source]); | 1322 verify([source]); |
| 1284 CompilationUnit unit = resolveCompilationUnit(source, library); | 1323 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 1285 NodeList<CompilationUnitMember> declarations = unit.declarations; | 1324 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 1286 expect(declarations, hasLength(2)); | 1325 expect(declarations, hasLength(2)); |
| 1287 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration) | 1326 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration) |
| 1288 .variables | 1327 .variables |
| 1289 .variables[0] | 1328 .variables[0] |
| 1290 .name | 1329 .name |
| 1291 .staticElement; | 1330 .staticElement; |
| 1292 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, | 1331 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1305 }'''); | 1344 }'''); |
| 1306 LibraryElement library = resolve2(source); | 1345 LibraryElement library = resolve2(source); |
| 1307 expect(library, isNotNull); | 1346 expect(library, isNotNull); |
| 1308 CompilationUnitElement unit = library.definingCompilationUnit; | 1347 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1309 expect(unit, isNotNull); | 1348 expect(unit, isNotNull); |
| 1310 List<ClassElement> classes = unit.types; | 1349 List<ClassElement> classes = unit.types; |
| 1311 expect(classes, hasLength(1)); | 1350 expect(classes, hasLength(1)); |
| 1312 FieldElement field = classes[0].fields[0]; | 1351 FieldElement field = classes[0].fields[0]; |
| 1313 List<ElementAnnotation> annotations = field.metadata; | 1352 List<ElementAnnotation> annotations = field.metadata; |
| 1314 expect(annotations, hasLength(1)); | 1353 expect(annotations, hasLength(1)); |
| 1315 await assertNoErrors(source); | 1354 await computeAnalysisResult(source); |
| 1355 assertNoErrors(source); |
| 1316 verify([source]); | 1356 verify([source]); |
| 1317 } | 1357 } |
| 1318 | 1358 |
| 1319 test_metadata_fieldFormalParameter() async { | 1359 test_metadata_fieldFormalParameter() async { |
| 1320 Source source = addSource(r''' | 1360 Source source = addSource(r''' |
| 1321 const A = null; | 1361 const A = null; |
| 1322 class C { | 1362 class C { |
| 1323 int f; | 1363 int f; |
| 1324 C(@A this.f); | 1364 C(@A this.f); |
| 1325 }'''); | 1365 }'''); |
| 1326 LibraryElement library = resolve2(source); | 1366 LibraryElement library = resolve2(source); |
| 1327 expect(library, isNotNull); | 1367 expect(library, isNotNull); |
| 1328 CompilationUnitElement unit = library.definingCompilationUnit; | 1368 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1329 expect(unit, isNotNull); | 1369 expect(unit, isNotNull); |
| 1330 List<ClassElement> classes = unit.types; | 1370 List<ClassElement> classes = unit.types; |
| 1331 expect(classes, hasLength(1)); | 1371 expect(classes, hasLength(1)); |
| 1332 List<ConstructorElement> constructors = classes[0].constructors; | 1372 List<ConstructorElement> constructors = classes[0].constructors; |
| 1333 expect(constructors, hasLength(1)); | 1373 expect(constructors, hasLength(1)); |
| 1334 List<ParameterElement> parameters = constructors[0].parameters; | 1374 List<ParameterElement> parameters = constructors[0].parameters; |
| 1335 expect(parameters, hasLength(1)); | 1375 expect(parameters, hasLength(1)); |
| 1336 List<ElementAnnotation> annotations = parameters[0].metadata; | 1376 List<ElementAnnotation> annotations = parameters[0].metadata; |
| 1337 expect(annotations, hasLength(1)); | 1377 expect(annotations, hasLength(1)); |
| 1338 await assertNoErrors(source); | 1378 await computeAnalysisResult(source); |
| 1379 assertNoErrors(source); |
| 1339 verify([source]); | 1380 verify([source]); |
| 1340 } | 1381 } |
| 1341 | 1382 |
| 1342 test_metadata_function() async { | 1383 test_metadata_function() async { |
| 1343 Source source = addSource(r''' | 1384 Source source = addSource(r''' |
| 1344 const A = null; | 1385 const A = null; |
| 1345 @A f() {}'''); | 1386 @A f() {}'''); |
| 1346 LibraryElement library = resolve2(source); | 1387 LibraryElement library = resolve2(source); |
| 1347 expect(library, isNotNull); | 1388 expect(library, isNotNull); |
| 1348 CompilationUnitElement unit = library.definingCompilationUnit; | 1389 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1349 expect(unit, isNotNull); | 1390 expect(unit, isNotNull); |
| 1350 List<FunctionElement> functions = unit.functions; | 1391 List<FunctionElement> functions = unit.functions; |
| 1351 expect(functions, hasLength(1)); | 1392 expect(functions, hasLength(1)); |
| 1352 List<ElementAnnotation> annotations = functions[0].metadata; | 1393 List<ElementAnnotation> annotations = functions[0].metadata; |
| 1353 expect(annotations, hasLength(1)); | 1394 expect(annotations, hasLength(1)); |
| 1354 await assertNoErrors(source); | 1395 await computeAnalysisResult(source); |
| 1396 assertNoErrors(source); |
| 1355 verify([source]); | 1397 verify([source]); |
| 1356 } | 1398 } |
| 1357 | 1399 |
| 1358 test_metadata_functionTypedParameter() async { | 1400 test_metadata_functionTypedParameter() async { |
| 1359 Source source = addSource(r''' | 1401 Source source = addSource(r''' |
| 1360 const A = null; | 1402 const A = null; |
| 1361 f(@A int p(int x)) {}'''); | 1403 f(@A int p(int x)) {}'''); |
| 1362 LibraryElement library = resolve2(source); | 1404 LibraryElement library = resolve2(source); |
| 1363 expect(library, isNotNull); | 1405 expect(library, isNotNull); |
| 1364 CompilationUnitElement unit = library.definingCompilationUnit; | 1406 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1365 expect(unit, isNotNull); | 1407 expect(unit, isNotNull); |
| 1366 List<FunctionElement> functions = unit.functions; | 1408 List<FunctionElement> functions = unit.functions; |
| 1367 expect(functions, hasLength(1)); | 1409 expect(functions, hasLength(1)); |
| 1368 List<ParameterElement> parameters = functions[0].parameters; | 1410 List<ParameterElement> parameters = functions[0].parameters; |
| 1369 expect(parameters, hasLength(1)); | 1411 expect(parameters, hasLength(1)); |
| 1370 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 1412 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 1371 expect(annotations1, hasLength(1)); | 1413 expect(annotations1, hasLength(1)); |
| 1372 await assertNoErrors(source); | 1414 await computeAnalysisResult(source); |
| 1415 assertNoErrors(source); |
| 1373 verify([source]); | 1416 verify([source]); |
| 1374 } | 1417 } |
| 1375 | 1418 |
| 1376 test_metadata_libraryDirective() async { | 1419 test_metadata_libraryDirective() async { |
| 1377 Source source = addSource(r''' | 1420 Source source = addSource(r''' |
| 1378 @A library lib; | 1421 @A library lib; |
| 1379 const A = null;'''); | 1422 const A = null;'''); |
| 1380 LibraryElement library = resolve2(source); | 1423 LibraryElement library = resolve2(source); |
| 1381 expect(library, isNotNull); | 1424 expect(library, isNotNull); |
| 1382 List<ElementAnnotation> annotations = library.metadata; | 1425 List<ElementAnnotation> annotations = library.metadata; |
| 1383 expect(annotations, hasLength(1)); | 1426 expect(annotations, hasLength(1)); |
| 1384 await assertNoErrors(source); | 1427 await computeAnalysisResult(source); |
| 1428 assertNoErrors(source); |
| 1385 verify([source]); | 1429 verify([source]); |
| 1386 } | 1430 } |
| 1387 | 1431 |
| 1388 test_metadata_method() async { | 1432 test_metadata_method() async { |
| 1389 Source source = addSource(r''' | 1433 Source source = addSource(r''' |
| 1390 const A = null; | 1434 const A = null; |
| 1391 class C { | 1435 class C { |
| 1392 @A void m() {} | 1436 @A void m() {} |
| 1393 }'''); | 1437 }'''); |
| 1394 LibraryElement library = resolve2(source); | 1438 LibraryElement library = resolve2(source); |
| 1395 expect(library, isNotNull); | 1439 expect(library, isNotNull); |
| 1396 CompilationUnitElement unit = library.definingCompilationUnit; | 1440 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1397 expect(unit, isNotNull); | 1441 expect(unit, isNotNull); |
| 1398 List<ClassElement> classes = unit.types; | 1442 List<ClassElement> classes = unit.types; |
| 1399 expect(classes, hasLength(1)); | 1443 expect(classes, hasLength(1)); |
| 1400 MethodElement method = classes[0].methods[0]; | 1444 MethodElement method = classes[0].methods[0]; |
| 1401 List<ElementAnnotation> annotations = method.metadata; | 1445 List<ElementAnnotation> annotations = method.metadata; |
| 1402 expect(annotations, hasLength(1)); | 1446 expect(annotations, hasLength(1)); |
| 1403 await assertNoErrors(source); | 1447 await computeAnalysisResult(source); |
| 1448 assertNoErrors(source); |
| 1404 verify([source]); | 1449 verify([source]); |
| 1405 } | 1450 } |
| 1406 | 1451 |
| 1407 test_metadata_namedParameter() async { | 1452 test_metadata_namedParameter() async { |
| 1408 Source source = addSource(r''' | 1453 Source source = addSource(r''' |
| 1409 const A = null; | 1454 const A = null; |
| 1410 f({@A int p : 0}) {}'''); | 1455 f({@A int p : 0}) {}'''); |
| 1411 LibraryElement library = resolve2(source); | 1456 LibraryElement library = resolve2(source); |
| 1412 expect(library, isNotNull); | 1457 expect(library, isNotNull); |
| 1413 CompilationUnitElement unit = library.definingCompilationUnit; | 1458 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1414 expect(unit, isNotNull); | 1459 expect(unit, isNotNull); |
| 1415 List<FunctionElement> functions = unit.functions; | 1460 List<FunctionElement> functions = unit.functions; |
| 1416 expect(functions, hasLength(1)); | 1461 expect(functions, hasLength(1)); |
| 1417 List<ParameterElement> parameters = functions[0].parameters; | 1462 List<ParameterElement> parameters = functions[0].parameters; |
| 1418 expect(parameters, hasLength(1)); | 1463 expect(parameters, hasLength(1)); |
| 1419 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 1464 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 1420 expect(annotations1, hasLength(1)); | 1465 expect(annotations1, hasLength(1)); |
| 1421 await assertNoErrors(source); | 1466 await computeAnalysisResult(source); |
| 1467 assertNoErrors(source); |
| 1422 verify([source]); | 1468 verify([source]); |
| 1423 } | 1469 } |
| 1424 | 1470 |
| 1425 test_metadata_positionalParameter() async { | 1471 test_metadata_positionalParameter() async { |
| 1426 Source source = addSource(r''' | 1472 Source source = addSource(r''' |
| 1427 const A = null; | 1473 const A = null; |
| 1428 f([@A int p = 0]) {}'''); | 1474 f([@A int p = 0]) {}'''); |
| 1429 LibraryElement library = resolve2(source); | 1475 LibraryElement library = resolve2(source); |
| 1430 expect(library, isNotNull); | 1476 expect(library, isNotNull); |
| 1431 CompilationUnitElement unit = library.definingCompilationUnit; | 1477 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1432 expect(unit, isNotNull); | 1478 expect(unit, isNotNull); |
| 1433 List<FunctionElement> functions = unit.functions; | 1479 List<FunctionElement> functions = unit.functions; |
| 1434 expect(functions, hasLength(1)); | 1480 expect(functions, hasLength(1)); |
| 1435 List<ParameterElement> parameters = functions[0].parameters; | 1481 List<ParameterElement> parameters = functions[0].parameters; |
| 1436 expect(parameters, hasLength(1)); | 1482 expect(parameters, hasLength(1)); |
| 1437 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 1483 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 1438 expect(annotations1, hasLength(1)); | 1484 expect(annotations1, hasLength(1)); |
| 1439 await assertNoErrors(source); | 1485 await computeAnalysisResult(source); |
| 1486 assertNoErrors(source); |
| 1440 verify([source]); | 1487 verify([source]); |
| 1441 } | 1488 } |
| 1442 | 1489 |
| 1443 test_metadata_simpleParameter() async { | 1490 test_metadata_simpleParameter() async { |
| 1444 Source source = addSource(r''' | 1491 Source source = addSource(r''' |
| 1445 const A = null; | 1492 const A = null; |
| 1446 f(@A p1, @A int p2) {}'''); | 1493 f(@A p1, @A int p2) {}'''); |
| 1447 LibraryElement library = resolve2(source); | 1494 LibraryElement library = resolve2(source); |
| 1448 expect(library, isNotNull); | 1495 expect(library, isNotNull); |
| 1449 CompilationUnitElement unit = library.definingCompilationUnit; | 1496 CompilationUnitElement unit = library.definingCompilationUnit; |
| 1450 expect(unit, isNotNull); | 1497 expect(unit, isNotNull); |
| 1451 List<FunctionElement> functions = unit.functions; | 1498 List<FunctionElement> functions = unit.functions; |
| 1452 expect(functions, hasLength(1)); | 1499 expect(functions, hasLength(1)); |
| 1453 List<ParameterElement> parameters = functions[0].parameters; | 1500 List<ParameterElement> parameters = functions[0].parameters; |
| 1454 expect(parameters, hasLength(2)); | 1501 expect(parameters, hasLength(2)); |
| 1455 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 1502 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 1456 expect(annotations1, hasLength(1)); | 1503 expect(annotations1, hasLength(1)); |
| 1457 List<ElementAnnotation> annotations2 = parameters[1].metadata; | 1504 List<ElementAnnotation> annotations2 = parameters[1].metadata; |
| 1458 expect(annotations2, hasLength(1)); | 1505 expect(annotations2, hasLength(1)); |
| 1459 await assertNoErrors(source); | 1506 await computeAnalysisResult(source); |
| 1507 assertNoErrors(source); |
| 1460 verify([source]); | 1508 verify([source]); |
| 1461 } | 1509 } |
| 1462 | 1510 |
| 1463 test_metadata_typedef() async { | 1511 test_metadata_typedef() async { |
| 1464 Source source = addSource(r''' | 1512 Source source = addSource(r''' |
| 1465 const A = null; | 1513 const A = null; |
| 1466 @A typedef F<A>();'''); | 1514 @A typedef F<A>();'''); |
| 1467 LibraryElement library = resolve2(source); | 1515 LibraryElement library = resolve2(source); |
| 1468 expect(library, isNotNull); | 1516 expect(library, isNotNull); |
| 1469 CompilationUnitElement unitElement = library.definingCompilationUnit; | 1517 CompilationUnitElement unitElement = library.definingCompilationUnit; |
| 1470 expect(unitElement, isNotNull); | 1518 expect(unitElement, isNotNull); |
| 1471 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; | 1519 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; |
| 1472 expect(aliases, hasLength(1)); | 1520 expect(aliases, hasLength(1)); |
| 1473 List<ElementAnnotation> annotations = aliases[0].metadata; | 1521 List<ElementAnnotation> annotations = aliases[0].metadata; |
| 1474 expect(annotations, hasLength(1)); | 1522 expect(annotations, hasLength(1)); |
| 1475 await assertNoErrors(source); | 1523 await computeAnalysisResult(source); |
| 1524 assertNoErrors(source); |
| 1476 verify([source]); | 1525 verify([source]); |
| 1477 CompilationUnit unit = resolveCompilationUnit(source, library); | 1526 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 1478 NodeList<CompilationUnitMember> declarations = unit.declarations; | 1527 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 1479 expect(declarations, hasLength(2)); | 1528 expect(declarations, hasLength(2)); |
| 1480 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration) | 1529 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration) |
| 1481 .variables | 1530 .variables |
| 1482 .variables[0] | 1531 .variables[0] |
| 1483 .name | 1532 .name |
| 1484 .staticElement; | 1533 .staticElement; |
| 1485 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, | 1534 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1496 bar() => 1; | 1545 bar() => 1; |
| 1497 } | 1546 } |
| 1498 class A { | 1547 class A { |
| 1499 foo() => 2; | 1548 foo() => 2; |
| 1500 } | 1549 } |
| 1501 | 1550 |
| 1502 class C extends B with A { | 1551 class C extends B with A { |
| 1503 bar() => super.bar(); | 1552 bar() => super.bar(); |
| 1504 foo() => super.foo(); | 1553 foo() => super.foo(); |
| 1505 }'''); | 1554 }'''); |
| 1506 await assertNoErrors(source); | 1555 await computeAnalysisResult(source); |
| 1556 assertNoErrors(source); |
| 1507 verify([source]); | 1557 verify([source]); |
| 1508 } | 1558 } |
| 1509 | 1559 |
| 1510 test_method_fromMixins() async { | 1560 test_method_fromMixins() async { |
| 1511 Source source = addSource(''' | 1561 Source source = addSource(''' |
| 1512 class B {} | 1562 class B {} |
| 1513 class M1 { | 1563 class M1 { |
| 1514 void f() {} | 1564 void f() {} |
| 1515 } | 1565 } |
| 1516 class M2 { | 1566 class M2 { |
| 1517 void f() {} | 1567 void f() {} |
| 1518 } | 1568 } |
| 1519 class C extends B with M1, M2 {} | 1569 class C extends B with M1, M2 {} |
| 1520 void main() { | 1570 void main() { |
| 1521 new C().f(); | 1571 new C().f(); |
| 1522 } | 1572 } |
| 1523 '''); | 1573 '''); |
| 1524 LibraryElement library = resolve2(source); | 1574 LibraryElement library = resolve2(source); |
| 1525 await assertNoErrors(source); | 1575 await computeAnalysisResult(source); |
| 1576 assertNoErrors(source); |
| 1526 verify([source]); | 1577 verify([source]); |
| 1527 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2. | 1578 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2. |
| 1528 FunctionDeclaration main = | 1579 FunctionDeclaration main = |
| 1529 library.definingCompilationUnit.functions[0].computeNode(); | 1580 library.definingCompilationUnit.functions[0].computeNode(); |
| 1530 BlockFunctionBody body = main.functionExpression.body; | 1581 BlockFunctionBody body = main.functionExpression.body; |
| 1531 ExpressionStatement stmt = body.block.statements[0]; | 1582 ExpressionStatement stmt = body.block.statements[0]; |
| 1532 MethodInvocation expr = stmt.expression; | 1583 MethodInvocation expr = stmt.expression; |
| 1533 expect( | 1584 expect( |
| 1534 resolutionMap | 1585 resolutionMap |
| 1535 .staticElementForIdentifier(expr.methodName) | 1586 .staticElementForIdentifier(expr.methodName) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1547 class M2 { | 1598 class M2 { |
| 1548 void f() {} | 1599 void f() {} |
| 1549 } | 1600 } |
| 1550 class C extends B with M1, M2 { | 1601 class C extends B with M1, M2 { |
| 1551 void g() { | 1602 void g() { |
| 1552 f(); | 1603 f(); |
| 1553 } | 1604 } |
| 1554 } | 1605 } |
| 1555 '''); | 1606 '''); |
| 1556 LibraryElement library = resolve2(source); | 1607 LibraryElement library = resolve2(source); |
| 1557 await assertNoErrors(source); | 1608 await computeAnalysisResult(source); |
| 1609 assertNoErrors(source); |
| 1558 verify([source]); | 1610 verify([source]); |
| 1559 // Verify that the call to f() in C.g() refers to the method defined in M2. | 1611 // Verify that the call to f() in C.g() refers to the method defined in M2. |
| 1560 ClassElement classC = library.definingCompilationUnit.types[3]; | 1612 ClassElement classC = library.definingCompilationUnit.types[3]; |
| 1561 MethodDeclaration g = classC.getMethod('g').computeNode(); | 1613 MethodDeclaration g = classC.getMethod('g').computeNode(); |
| 1562 BlockFunctionBody body = g.body; | 1614 BlockFunctionBody body = g.body; |
| 1563 ExpressionStatement stmt = body.block.statements[0]; | 1615 ExpressionStatement stmt = body.block.statements[0]; |
| 1564 MethodInvocation invocation = stmt.expression; | 1616 MethodInvocation invocation = stmt.expression; |
| 1565 SimpleIdentifier methodName = invocation.methodName; | 1617 SimpleIdentifier methodName = invocation.methodName; |
| 1566 expect( | 1618 expect( |
| 1567 resolutionMap | 1619 resolutionMap |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1579 } | 1631 } |
| 1580 class M2 { | 1632 class M2 { |
| 1581 void f() {} | 1633 void f() {} |
| 1582 } | 1634 } |
| 1583 class C extends B with M1, M2 {} | 1635 class C extends B with M1, M2 {} |
| 1584 void main() { | 1636 void main() { |
| 1585 new C().f(); | 1637 new C().f(); |
| 1586 } | 1638 } |
| 1587 '''); | 1639 '''); |
| 1588 LibraryElement library = resolve2(source); | 1640 LibraryElement library = resolve2(source); |
| 1589 await assertNoErrors(source); | 1641 await computeAnalysisResult(source); |
| 1642 assertNoErrors(source); |
| 1590 verify([source]); | 1643 verify([source]); |
| 1591 // Verify that the call to f() in "new C().f()" refers to the method | 1644 // Verify that the call to f() in "new C().f()" refers to the method |
| 1592 // defined in M2. | 1645 // defined in M2. |
| 1593 FunctionDeclaration main = | 1646 FunctionDeclaration main = |
| 1594 library.definingCompilationUnit.functions[0].computeNode(); | 1647 library.definingCompilationUnit.functions[0].computeNode(); |
| 1595 BlockFunctionBody body = main.functionExpression.body; | 1648 BlockFunctionBody body = main.functionExpression.body; |
| 1596 ExpressionStatement stmt = body.block.statements[0]; | 1649 ExpressionStatement stmt = body.block.statements[0]; |
| 1597 MethodInvocation invocation = stmt.expression; | 1650 MethodInvocation invocation = stmt.expression; |
| 1598 expect( | 1651 expect( |
| 1599 resolutionMap | 1652 resolutionMap |
| 1600 .staticElementForIdentifier(invocation.methodName) | 1653 .staticElementForIdentifier(invocation.methodName) |
| 1601 .enclosingElement | 1654 .enclosingElement |
| 1602 .name, | 1655 .name, |
| 1603 'M2'); | 1656 'M2'); |
| 1604 } | 1657 } |
| 1605 | 1658 |
| 1606 test_method_fromSuperclassMixin() async { | 1659 test_method_fromSuperclassMixin() async { |
| 1607 Source source = addSource(r''' | 1660 Source source = addSource(r''' |
| 1608 class A { | 1661 class A { |
| 1609 void m1() {} | 1662 void m1() {} |
| 1610 } | 1663 } |
| 1611 class B extends Object with A { | 1664 class B extends Object with A { |
| 1612 } | 1665 } |
| 1613 class C extends B { | 1666 class C extends B { |
| 1614 } | 1667 } |
| 1615 f(C c) { | 1668 f(C c) { |
| 1616 c.m1(); | 1669 c.m1(); |
| 1617 }'''); | 1670 }'''); |
| 1618 await assertNoErrors(source); | 1671 await computeAnalysisResult(source); |
| 1672 assertNoErrors(source); |
| 1619 verify([source]); | 1673 verify([source]); |
| 1620 } | 1674 } |
| 1621 | 1675 |
| 1622 test_methodCascades() async { | 1676 test_methodCascades() async { |
| 1623 Source source = addSource(r''' | 1677 Source source = addSource(r''' |
| 1624 class A { | 1678 class A { |
| 1625 void m1() {} | 1679 void m1() {} |
| 1626 void m2() {} | 1680 void m2() {} |
| 1627 void m() { | 1681 void m() { |
| 1628 A a = new A(); | 1682 A a = new A(); |
| 1629 a..m1() | 1683 a..m1() |
| 1630 ..m2(); | 1684 ..m2(); |
| 1631 } | 1685 } |
| 1632 }'''); | 1686 }'''); |
| 1633 await assertNoErrors(source); | 1687 await computeAnalysisResult(source); |
| 1688 assertNoErrors(source); |
| 1634 verify([source]); | 1689 verify([source]); |
| 1635 } | 1690 } |
| 1636 | 1691 |
| 1637 test_methodCascades_withSetter() async { | 1692 test_methodCascades_withSetter() async { |
| 1638 Source source = addSource(r''' | 1693 Source source = addSource(r''' |
| 1639 class A { | 1694 class A { |
| 1640 String name; | 1695 String name; |
| 1641 void m1() {} | 1696 void m1() {} |
| 1642 void m2() {} | 1697 void m2() {} |
| 1643 void m() { | 1698 void m() { |
| 1644 A a = new A(); | 1699 A a = new A(); |
| 1645 a..m1() | 1700 a..m1() |
| 1646 ..name = 'name' | 1701 ..name = 'name' |
| 1647 ..m2(); | 1702 ..m2(); |
| 1648 } | 1703 } |
| 1649 }'''); | 1704 }'''); |
| 1650 // failing with error code: INVOCATION_OF_NON_FUNCTION | 1705 // failing with error code: INVOCATION_OF_NON_FUNCTION |
| 1651 await assertNoErrors(source); | 1706 await computeAnalysisResult(source); |
| 1707 assertNoErrors(source); |
| 1652 verify([source]); | 1708 verify([source]); |
| 1653 } | 1709 } |
| 1654 | 1710 |
| 1655 test_resolveAgainstNull() async { | 1711 test_resolveAgainstNull() async { |
| 1656 Source source = addSource(r''' | 1712 Source source = addSource(r''' |
| 1657 f(var p) { | 1713 f(var p) { |
| 1658 return null == p; | 1714 return null == p; |
| 1659 }'''); | 1715 }'''); |
| 1660 await assertNoErrors(source); | 1716 await computeAnalysisResult(source); |
| 1717 assertNoErrors(source); |
| 1661 } | 1718 } |
| 1662 | 1719 |
| 1663 test_setter_fromMixins_bare_identifier() async { | 1720 test_setter_fromMixins_bare_identifier() async { |
| 1664 Source source = addSource(''' | 1721 Source source = addSource(''' |
| 1665 class B {} | 1722 class B {} |
| 1666 class M1 { | 1723 class M1 { |
| 1667 set x(value) {} | 1724 set x(value) {} |
| 1668 } | 1725 } |
| 1669 class M2 { | 1726 class M2 { |
| 1670 set x(value) {} | 1727 set x(value) {} |
| 1671 } | 1728 } |
| 1672 class C extends B with M1, M2 { | 1729 class C extends B with M1, M2 { |
| 1673 void f() { | 1730 void f() { |
| 1674 x = 1; | 1731 x = 1; |
| 1675 } | 1732 } |
| 1676 } | 1733 } |
| 1677 '''); | 1734 '''); |
| 1678 LibraryElement library = resolve2(source); | 1735 LibraryElement library = resolve2(source); |
| 1679 await assertNoErrors(source); | 1736 await computeAnalysisResult(source); |
| 1737 assertNoErrors(source); |
| 1680 verify([source]); | 1738 verify([source]); |
| 1681 // Verify that the setter for "x" in C.f() refers to the setter defined in | 1739 // Verify that the setter for "x" in C.f() refers to the setter defined in |
| 1682 // M2. | 1740 // M2. |
| 1683 ClassElement classC = library.definingCompilationUnit.types[3]; | 1741 ClassElement classC = library.definingCompilationUnit.types[3]; |
| 1684 MethodDeclaration f = classC.getMethod('f').computeNode(); | 1742 MethodDeclaration f = classC.getMethod('f').computeNode(); |
| 1685 BlockFunctionBody body = f.body; | 1743 BlockFunctionBody body = f.body; |
| 1686 ExpressionStatement stmt = body.block.statements[0]; | 1744 ExpressionStatement stmt = body.block.statements[0]; |
| 1687 AssignmentExpression assignment = stmt.expression; | 1745 AssignmentExpression assignment = stmt.expression; |
| 1688 SimpleIdentifier leftHandSide = assignment.leftHandSide; | 1746 SimpleIdentifier leftHandSide = assignment.leftHandSide; |
| 1689 expect( | 1747 expect( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1702 } | 1760 } |
| 1703 class M2 { | 1761 class M2 { |
| 1704 set x(value) {} | 1762 set x(value) {} |
| 1705 } | 1763 } |
| 1706 class C extends B with M1, M2 {} | 1764 class C extends B with M1, M2 {} |
| 1707 void main() { | 1765 void main() { |
| 1708 new C().x = 1; | 1766 new C().x = 1; |
| 1709 } | 1767 } |
| 1710 '''); | 1768 '''); |
| 1711 LibraryElement library = resolve2(source); | 1769 LibraryElement library = resolve2(source); |
| 1712 await assertNoErrors(source); | 1770 await computeAnalysisResult(source); |
| 1771 assertNoErrors(source); |
| 1713 verify([source]); | 1772 verify([source]); |
| 1714 // Verify that the setter for "x" in "new C().x" refers to the setter | 1773 // Verify that the setter for "x" in "new C().x" refers to the setter |
| 1715 // defined in M2. | 1774 // defined in M2. |
| 1716 FunctionDeclaration main = | 1775 FunctionDeclaration main = |
| 1717 library.definingCompilationUnit.functions[0].computeNode(); | 1776 library.definingCompilationUnit.functions[0].computeNode(); |
| 1718 BlockFunctionBody body = main.functionExpression.body; | 1777 BlockFunctionBody body = main.functionExpression.body; |
| 1719 ExpressionStatement stmt = body.block.statements[0]; | 1778 ExpressionStatement stmt = body.block.statements[0]; |
| 1720 AssignmentExpression assignment = stmt.expression; | 1779 AssignmentExpression assignment = stmt.expression; |
| 1721 PropertyAccess propertyAccess = assignment.leftHandSide; | 1780 PropertyAccess propertyAccess = assignment.leftHandSide; |
| 1722 expect( | 1781 expect( |
| 1723 resolutionMap | 1782 resolutionMap |
| 1724 .staticElementForIdentifier(propertyAccess.propertyName) | 1783 .staticElementForIdentifier(propertyAccess.propertyName) |
| 1725 .enclosingElement | 1784 .enclosingElement |
| 1726 .name, | 1785 .name, |
| 1727 'M2'); | 1786 'M2'); |
| 1728 } | 1787 } |
| 1729 | 1788 |
| 1730 test_setter_inherited() async { | 1789 test_setter_inherited() async { |
| 1731 Source source = addSource(r''' | 1790 Source source = addSource(r''' |
| 1732 class A { | 1791 class A { |
| 1733 int get x => 0; | 1792 int get x => 0; |
| 1734 set x(int p) {} | 1793 set x(int p) {} |
| 1735 } | 1794 } |
| 1736 class B extends A { | 1795 class B extends A { |
| 1737 int get x => super.x == null ? 0 : super.x; | 1796 int get x => super.x == null ? 0 : super.x; |
| 1738 int f() => x = 1; | 1797 int f() => x = 1; |
| 1739 }'''); | 1798 }'''); |
| 1740 await assertNoErrors(source); | 1799 await computeAnalysisResult(source); |
| 1800 assertNoErrors(source); |
| 1741 verify([source]); | 1801 verify([source]); |
| 1742 } | 1802 } |
| 1743 | 1803 |
| 1744 test_setter_static() async { | 1804 test_setter_static() async { |
| 1745 Source source = addSource(r''' | 1805 Source source = addSource(r''' |
| 1746 set s(x) { | 1806 set s(x) { |
| 1747 } | 1807 } |
| 1748 | 1808 |
| 1749 main() { | 1809 main() { |
| 1750 s = 123; | 1810 s = 123; |
| 1751 }'''); | 1811 }'''); |
| 1752 await assertNoErrors(source); | 1812 await computeAnalysisResult(source); |
| 1813 assertNoErrors(source); |
| 1753 verify([source]); | 1814 verify([source]); |
| 1754 } | 1815 } |
| 1755 | 1816 |
| 1756 @failingTest | 1817 @failingTest |
| 1757 test_staticInvocation() async { | 1818 test_staticInvocation() async { |
| 1758 Source source = addSource(r''' | 1819 Source source = addSource(r''' |
| 1759 class A { | 1820 class A { |
| 1760 static int get g => (a,b) => 0; | 1821 static int get g => (a,b) => 0; |
| 1761 } | 1822 } |
| 1762 class B { | 1823 class B { |
| 1763 f() { | 1824 f() { |
| 1764 A.g(1,0); | 1825 A.g(1,0); |
| 1765 } | 1826 } |
| 1766 }'''); | 1827 }'''); |
| 1767 await assertNoErrors(source); | 1828 await computeAnalysisResult(source); |
| 1829 assertNoErrors(source); |
| 1768 verify([source]); | 1830 verify([source]); |
| 1769 } | 1831 } |
| 1770 | 1832 |
| 1771 /** | 1833 /** |
| 1772 * Resolve the given source and verify that the arguments in a specific method
invocation were | 1834 * Resolve the given source and verify that the arguments in a specific method
invocation were |
| 1773 * correctly resolved. | 1835 * correctly resolved. |
| 1774 * | 1836 * |
| 1775 * The source is expected to be source for a compilation unit, the first decla
ration is expected | 1837 * The source is expected to be source for a compilation unit, the first decla
ration is expected |
| 1776 * to be a class, the first member of which is expected to be a method with a
block body, and the | 1838 * to be a class, the first member of which is expected to be a method with a
block body, and the |
| 1777 * first statement in the body is expected to be an expression statement whose
expression is a | 1839 * first statement in the body is expected to be an expression statement whose
expression is a |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 // check propagated type | 1904 // check propagated type |
| 1843 FunctionType propagatedType = node.propagatedType as FunctionType; | 1905 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 1844 expect(propagatedType.returnType, test.typeProvider.stringType); | 1906 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 1845 } on AnalysisException catch (e, stackTrace) { | 1907 } on AnalysisException catch (e, stackTrace) { |
| 1846 thrownException[0] = new CaughtException(e, stackTrace); | 1908 thrownException[0] = new CaughtException(e, stackTrace); |
| 1847 } | 1909 } |
| 1848 } | 1910 } |
| 1849 return null; | 1911 return null; |
| 1850 } | 1912 } |
| 1851 } | 1913 } |
| OLD | NEW |