| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
| 7 import 'package:compiler/src/types/types.dart' show TypeMask; | 7 import 'package:compiler/src/types/types.dart' show TypeMask; |
| 8 import 'type_mask_test_helper.dart'; | 8 import 'type_mask_test_helper.dart'; |
| 9 | 9 |
| 10 import 'compiler_helper.dart'; | 10 import 'compiler_helper.dart'; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 returnInt2() => new A().myField += 4; | 575 returnInt2() => new A().myField += 4; |
| 576 returnInt3() => ++new A()[0]; | 576 returnInt3() => ++new A()[0]; |
| 577 returnInt4() => new A()[0] += 42; | 577 returnInt4() => new A()[0] += 42; |
| 578 returnInt5() => ++super.myField; | 578 returnInt5() => ++super.myField; |
| 579 returnInt6() => super.myField += 4; | 579 returnInt6() => super.myField += 4; |
| 580 returnInt7() => ++super[0]; | 580 returnInt7() => ++super[0]; |
| 581 returnInt8() => super[0] += 54; | 581 returnInt8() => super[0] += 54; |
| 582 returnInt9() => super.myField; | 582 returnInt9() => super.myField; |
| 583 } | 583 } |
| 584 | 584 |
| 585 class C { |
| 586 var myField = 42; |
| 587 C(); |
| 588 |
| 589 returnInt1() => ++myField; |
| 590 returnInt2() => ++this.myField; |
| 591 returnInt3() => this.myField += 42; |
| 592 returnInt4() => myField += 42; |
| 593 operator[](index) => myField; |
| 594 operator[]= (index, value) {} |
| 595 returnInt5() => ++this[0]; |
| 596 returnInt6() => this[0] += 1; |
| 597 } |
| 598 |
| 585 testCascade1() { | 599 testCascade1() { |
| 586 return [1, 2, 3]..add(4)..add(5); | 600 return [1, 2, 3]..add(4)..add(5); |
| 587 } | 601 } |
| 588 | 602 |
| 589 testCascade2() { | 603 testCascade2() { |
| 590 return new CascadeHelper() | 604 return new CascadeHelper() |
| 591 ..a = "hello" | 605 ..a = "hello" |
| 592 ..b = 42 | 606 ..b = 42 |
| 593 ..i += 1; | 607 ..i += 1; |
| 594 } | 608 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 | 691 |
| 678 new B()..returnInt1() | 692 new B()..returnInt1() |
| 679 ..returnInt2() | 693 ..returnInt2() |
| 680 ..returnInt3() | 694 ..returnInt3() |
| 681 ..returnInt4() | 695 ..returnInt4() |
| 682 ..returnInt5() | 696 ..returnInt5() |
| 683 ..returnInt6() | 697 ..returnInt6() |
| 684 ..returnInt7() | 698 ..returnInt7() |
| 685 ..returnInt8() | 699 ..returnInt8() |
| 686 ..returnInt9(); | 700 ..returnInt9(); |
| 701 |
| 702 new C()..returnInt1() |
| 703 ..returnInt2() |
| 704 ..returnInt3() |
| 705 ..returnInt4() |
| 706 ..returnInt5() |
| 707 ..returnInt6(); |
| 687 testReturnElementOfConstList1(); | 708 testReturnElementOfConstList1(); |
| 688 testReturnElementOfConstList2(); | 709 testReturnElementOfConstList2(); |
| 689 testReturnItselfOrInt(topLevelGetter()); | 710 testReturnItselfOrInt(topLevelGetter()); |
| 690 testReturnInvokeDynamicGetter(); | 711 testReturnInvokeDynamicGetter(); |
| 691 testCascade1(); | 712 testCascade1(); |
| 692 testCascade2(); | 713 testCascade2(); |
| 693 testSpecialization1(); | 714 testSpecialization1(); |
| 694 testSpecialization2(); | 715 testSpecialization2(); |
| 695 testSpecialization3(); | 716 testSpecialization3(); |
| 696 testReturnNull1(topLevelGetter()); | 717 testReturnNull1(topLevelGetter()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 720 } | 741 } |
| 721 var interceptorType = | 742 var interceptorType = |
| 722 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); | 743 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
| 723 | 744 |
| 724 checkReturn('returnNum1', typesTask.numType); | 745 checkReturn('returnNum1', typesTask.numType); |
| 725 checkReturn('returnNum2', typesTask.numType); | 746 checkReturn('returnNum2', typesTask.numType); |
| 726 checkReturn('returnInt1', typesTask.uint31Type); | 747 checkReturn('returnInt1', typesTask.uint31Type); |
| 727 checkReturn('returnInt2', typesTask.uint31Type); | 748 checkReturn('returnInt2', typesTask.uint31Type); |
| 728 checkReturn('returnDouble', typesTask.doubleType); | 749 checkReturn('returnDouble', typesTask.doubleType); |
| 729 checkReturn('returnGiveUp', interceptorType); | 750 checkReturn('returnGiveUp', interceptorType); |
| 730 checkReturn('returnInt5', typesTask.positiveIntType); | 751 checkReturn('returnInt5', typesTask.uint32Type); // uint31+uint31->uint32 |
| 731 checkReturn('returnInt6', typesTask.positiveIntType); | 752 checkReturn('returnInt6', typesTask.uint32Type); // uint31+uint31->uint32 |
| 732 checkReturn('returnIntOrNull', typesTask.uint31Type.nullable()); | 753 checkReturn('returnIntOrNull', typesTask.uint31Type.nullable()); |
| 733 checkReturn('returnInt3', typesTask.uint31Type); | 754 checkReturn('returnInt3', typesTask.uint31Type); |
| 734 checkReturn('returnDynamic', typesTask.dynamicType); | 755 checkReturn('returnDynamic', typesTask.dynamicType); |
| 735 checkReturn('returnInt4', typesTask.uint31Type); | 756 checkReturn('returnInt4', typesTask.uint31Type); |
| 736 checkReturn('returnInt7', typesTask.positiveIntType); | 757 checkReturn('returnInt7', typesTask.positiveIntType); |
| 737 checkReturn('returnInt8', typesTask.positiveIntType); | 758 checkReturn('returnInt8', typesTask.positiveIntType); |
| 738 checkReturn('returnEmpty1', const TypeMask.nonNullEmpty()); | 759 checkReturn('returnEmpty1', const TypeMask.nonNullEmpty()); |
| 739 checkReturn('returnEmpty2', const TypeMask.nonNullEmpty()); | 760 checkReturn('returnEmpty2', const TypeMask.nonNullEmpty()); |
| 740 TypeMask intType = new TypeMask.nonNullSubtype(compiler.intClass, | 761 TypeMask intType = new TypeMask.nonNullSubtype(compiler.intClass, |
| 741 compiler.world); | 762 compiler.world); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 .union(typesTask.doubleType, compiler.world) | 803 .union(typesTask.doubleType, compiler.world) |
| 783 .nullable(), | 804 .nullable(), |
| 784 compiler)); | 805 compiler)); |
| 785 checkReturn('testSwitch2', typesTask.uint31Type); | 806 checkReturn('testSwitch2', typesTask.uint31Type); |
| 786 checkReturn('testSwitch3', interceptorType.nullable()); | 807 checkReturn('testSwitch3', interceptorType.nullable()); |
| 787 checkReturn('testSwitch4', typesTask.uint31Type); | 808 checkReturn('testSwitch4', typesTask.uint31Type); |
| 788 checkReturn('testSwitch5', typesTask.uint31Type); | 809 checkReturn('testSwitch5', typesTask.uint31Type); |
| 789 checkReturn('testContinue1', interceptorType.nullable()); | 810 checkReturn('testContinue1', interceptorType.nullable()); |
| 790 checkReturn('testBreak1', interceptorType.nullable()); | 811 checkReturn('testBreak1', interceptorType.nullable()); |
| 791 checkReturn('testContinue2', interceptorType.nullable()); | 812 checkReturn('testContinue2', interceptorType.nullable()); |
| 792 checkReturn('testBreak2', typesTask.positiveIntType.nullable()); | 813 checkReturn('testBreak2', typesTask.uint32Type.nullable()); |
| 793 checkReturn('testReturnElementOfConstList1', typesTask.uint31Type); | 814 checkReturn('testReturnElementOfConstList1', typesTask.uint31Type); |
| 794 checkReturn('testReturnElementOfConstList2', typesTask.uint31Type); | 815 checkReturn('testReturnElementOfConstList2', typesTask.uint31Type); |
| 795 checkReturn('testReturnItselfOrInt', typesTask.uint31Type); | 816 checkReturn('testReturnItselfOrInt', typesTask.uint31Type); |
| 796 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType); | 817 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType); |
| 797 | 818 |
| 798 checkReturn('testDoWhile1', typesTask.stringType); | 819 checkReturn('testDoWhile1', typesTask.stringType); |
| 799 checkReturn('testDoWhile2', typesTask.nullType); | 820 checkReturn('testDoWhile2', typesTask.nullType); |
| 800 checkReturn('testDoWhile3', typesTask.uint31Type); | 821 checkReturn('testDoWhile3', typesTask.uint31Type); |
| 801 checkReturn('testDoWhile4', typesTask.numType); | 822 checkReturn('testDoWhile4', typesTask.numType); |
| 802 | 823 |
| 803 checkReturnInClass(String className, String methodName, type) { | 824 checkReturnInClass(String className, String methodName, type) { |
| 804 var cls = findElement(compiler, className); | 825 var cls = findElement(compiler, className); |
| 805 var element = cls.lookupLocalMember(methodName); | 826 var element = cls.lookupLocalMember(methodName); |
| 806 Expect.equals(type, | 827 Expect.equals(type, |
| 807 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), | 828 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), |
| 808 '$className:$methodName'); | 829 '$className:$methodName'); |
| 809 } | 830 } |
| 810 | 831 |
| 811 checkReturnInClass('A', 'returnInt1', typesTask.positiveIntType); | 832 checkReturnInClass('A', 'returnInt1', typesTask.uint32Type); |
| 812 checkReturnInClass('A', 'returnInt2', typesTask.positiveIntType); | 833 checkReturnInClass('A', 'returnInt2', typesTask.uint32Type); |
| 813 checkReturnInClass('A', 'returnInt3', typesTask.positiveIntType); | 834 checkReturnInClass('A', 'returnInt3', typesTask.uint32Type); |
| 814 checkReturnInClass('A', 'returnInt4', typesTask.positiveIntType); | 835 checkReturnInClass('A', 'returnInt4', typesTask.uint32Type); |
| 815 checkReturnInClass('A', 'returnInt5', typesTask.positiveIntType); | 836 checkReturnInClass('A', 'returnInt5', typesTask.uint32Type); |
| 816 checkReturnInClass('A', 'returnInt6', typesTask.positiveIntType); | 837 checkReturnInClass('A', 'returnInt6', typesTask.uint32Type); |
| 817 checkReturnInClass('A', '==', interceptorType); | 838 checkReturnInClass('A', '==', interceptorType); |
| 818 | 839 |
| 819 checkReturnInClass('B', 'returnInt1', typesTask.positiveIntType); | 840 checkReturnInClass('B', 'returnInt1', typesTask.uint32Type); |
| 820 checkReturnInClass('B', 'returnInt2', typesTask.positiveIntType); | 841 checkReturnInClass('B', 'returnInt2', typesTask.uint32Type); |
| 821 checkReturnInClass('B', 'returnInt3', typesTask.positiveIntType); | 842 checkReturnInClass('B', 'returnInt3', typesTask.uint32Type); |
| 822 checkReturnInClass('B', 'returnInt4', typesTask.positiveIntType); | 843 checkReturnInClass('B', 'returnInt4', typesTask.uint32Type); |
| 823 checkReturnInClass('B', 'returnInt5', typesTask.positiveIntType); | 844 checkReturnInClass('B', 'returnInt5', typesTask.uint32Type); |
| 824 checkReturnInClass('B', 'returnInt6', typesTask.positiveIntType); | 845 checkReturnInClass('B', 'returnInt6', typesTask.uint32Type); |
| 825 checkReturnInClass('B', 'returnInt7', typesTask.positiveIntType); | 846 checkReturnInClass('B', 'returnInt7', typesTask.uint32Type); |
| 826 checkReturnInClass('B', 'returnInt8', typesTask.positiveIntType); | 847 checkReturnInClass('B', 'returnInt8', typesTask.uint32Type); |
| 827 checkReturnInClass('B', 'returnInt9', typesTask.uint31Type); | 848 checkReturnInClass('B', 'returnInt9', typesTask.uint31Type); |
| 828 | 849 |
| 850 checkReturnInClass('C', 'returnInt1', typesTask.positiveIntType); |
| 851 checkReturnInClass('C', 'returnInt2', typesTask.positiveIntType); |
| 852 checkReturnInClass('C', 'returnInt3', typesTask.positiveIntType); |
| 853 checkReturnInClass('C', 'returnInt4', typesTask.positiveIntType); |
| 854 checkReturnInClass('C', 'returnInt5', typesTask.positiveIntType); |
| 855 checkReturnInClass('C', 'returnInt6', typesTask.positiveIntType); |
| 856 |
| 829 checkFactoryConstructor(String className, String factoryName) { | 857 checkFactoryConstructor(String className, String factoryName) { |
| 830 var cls = findElement(compiler, className); | 858 var cls = findElement(compiler, className); |
| 831 var element = cls.localLookup(factoryName); | 859 var element = cls.localLookup(factoryName); |
| 832 Expect.equals(new TypeMask.nonNullExact(cls, world), | 860 Expect.equals(new TypeMask.nonNullExact(cls, world), |
| 833 typesInferrer.getReturnTypeOfElement(element)); | 861 typesInferrer.getReturnTypeOfElement(element)); |
| 834 } | 862 } |
| 835 checkFactoryConstructor('A', ''); | 863 checkFactoryConstructor('A', ''); |
| 836 | 864 |
| 837 checkReturn('testCascade1', typesTask.growableListType); | 865 checkReturn('testCascade1', typesTask.growableListType); |
| 838 checkReturn('testCascade2', new TypeMask.nonNullExact( | 866 checkReturn('testCascade2', new TypeMask.nonNullExact( |
| 839 findElement(compiler, 'CascadeHelper'), world)); | 867 findElement(compiler, 'CascadeHelper'), world)); |
| 840 checkReturn('testSpecialization1', typesTask.numType); | 868 checkReturn('testSpecialization1', typesTask.numType); |
| 841 checkReturn('testSpecialization2', typesTask.dynamicType); | 869 checkReturn('testSpecialization2', typesTask.dynamicType); |
| 842 checkReturn('testSpecialization3', typesTask.uint31Type.nullable()); | 870 checkReturn('testSpecialization3', typesTask.uint31Type.nullable()); |
| 843 checkReturn('testReturnNull1', typesTask.nullType); | 871 checkReturn('testReturnNull1', typesTask.nullType); |
| 844 checkReturn('testReturnNull2', typesTask.nullType); | 872 checkReturn('testReturnNull2', typesTask.nullType); |
| 845 checkReturn('testReturnNull3', typesTask.dynamicType); | 873 checkReturn('testReturnNull3', typesTask.dynamicType); |
| 846 checkReturn('testReturnNull4', typesTask.nullType); | 874 checkReturn('testReturnNull4', typesTask.nullType); |
| 847 checkReturn('testReturnNull5', typesTask.nullType); | 875 checkReturn('testReturnNull5', typesTask.nullType); |
| 848 checkReturn('testReturnNull6', typesTask.dynamicType); | 876 checkReturn('testReturnNull6', typesTask.dynamicType); |
| 849 checkReturn('testReturnNotEquals', typesTask.boolType); | 877 checkReturn('testReturnNotEquals', typesTask.boolType); |
| 850 })); | 878 })); |
| 851 } | 879 } |
| OLD | NEW |