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 709 matching lines...) Loading... |
720 testReturnNull6(); | 720 testReturnNull6(); |
721 testReturnNotEquals(); | 721 testReturnNotEquals(); |
722 } | 722 } |
723 """; | 723 """; |
724 | 724 |
725 void main() { | 725 void main() { |
726 Uri uri = new Uri(scheme: 'source'); | 726 Uri uri = new Uri(scheme: 'source'); |
727 var compiler = compilerFor(TEST, uri); | 727 var compiler = compilerFor(TEST, uri); |
728 compiler.diagnosticHandler = createHandler(compiler, TEST); | 728 compiler.diagnosticHandler = createHandler(compiler, TEST); |
729 asyncTest(() => compiler.run(uri).then((_) { | 729 asyncTest(() => compiler.run(uri).then((_) { |
730 var commonMasks = compiler.commonMasks; | 730 var commonMasks = compiler.commonMasks; |
731 var typesInferrer = compiler.globalInference.typesInferrer; | 731 var typesInferrer = compiler.globalInference.typesInferrer; |
732 var world = compiler.world; | 732 var world = compiler.world; |
733 | 733 |
734 checkReturn(String name, type) { | 734 checkReturn(String name, type) { |
735 var element = findElement(compiler, name); | 735 var element = findElement(compiler, name); |
736 Expect.equals( | 736 Expect.equals( |
737 type, | 737 type, |
738 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), | 738 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), |
739 name); | 739 name); |
740 } | 740 } |
741 var interceptorType = | 741 var interceptorType = |
742 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); | 742 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
743 | 743 |
744 checkReturn('returnNum1', commonMasks.numType); | 744 checkReturn('returnNum1', commonMasks.numType); |
745 checkReturn('returnNum2', commonMasks.numType); | 745 checkReturn('returnNum2', commonMasks.numType); |
746 checkReturn('returnInt1', commonMasks.uint31Type); | 746 checkReturn('returnInt1', commonMasks.uint31Type); |
747 checkReturn('returnInt2', commonMasks.uint31Type); | 747 checkReturn('returnInt2', commonMasks.uint31Type); |
748 checkReturn('returnDouble', commonMasks.doubleType); | 748 checkReturn('returnDouble', commonMasks.doubleType); |
749 checkReturn('returnGiveUp', interceptorType); | 749 checkReturn('returnGiveUp', interceptorType); |
750 checkReturn('returnInt5', commonMasks.uint32Type); // uint31+uint31->uint32 | 750 checkReturn( |
751 checkReturn('returnInt6', commonMasks.uint32Type); // uint31+uint31->uint32 | 751 'returnInt5', commonMasks.uint32Type); // uint31+uint31->uint32 |
752 checkReturn('returnIntOrNull', commonMasks.uint31Type.nullable()); | 752 checkReturn( |
753 checkReturn('returnInt3', commonMasks.uint31Type); | 753 'returnInt6', commonMasks.uint32Type); // uint31+uint31->uint32 |
754 checkReturn('returnDynamic', commonMasks.dynamicType); | 754 checkReturn('returnIntOrNull', commonMasks.uint31Type.nullable()); |
755 checkReturn('returnInt4', commonMasks.uint31Type); | 755 checkReturn('returnInt3', commonMasks.uint31Type); |
756 checkReturn('returnInt7', commonMasks.positiveIntType); | 756 checkReturn('returnDynamic', commonMasks.dynamicType); |
757 checkReturn('returnInt8', commonMasks.positiveIntType); | 757 checkReturn('returnInt4', commonMasks.uint31Type); |
758 checkReturn('returnEmpty1', const TypeMask.nonNullEmpty()); | 758 checkReturn('returnInt7', commonMasks.positiveIntType); |
759 checkReturn('returnEmpty2', const TypeMask.nonNullEmpty()); | 759 checkReturn('returnInt8', commonMasks.positiveIntType); |
760 TypeMask intType = new TypeMask.nonNullSubtype( | 760 checkReturn('returnEmpty1', const TypeMask.nonNullEmpty()); |
761 compiler.coreClasses.intClass, compiler.world); | 761 checkReturn('returnEmpty2', const TypeMask.nonNullEmpty()); |
762 checkReturn('testIsCheck1', intType); | 762 TypeMask intType = new TypeMask.nonNullSubtype( |
763 checkReturn('testIsCheck2', intType); | 763 compiler.coreClasses.intClass, compiler.world); |
764 checkReturn('testIsCheck3', intType.nullable()); | 764 checkReturn('testIsCheck1', intType); |
765 checkReturn('testIsCheck4', intType); | 765 checkReturn('testIsCheck2', intType); |
766 checkReturn('testIsCheck5', intType); | 766 checkReturn('testIsCheck3', intType.nullable()); |
767 checkReturn('testIsCheck6', commonMasks.dynamicType); | 767 checkReturn('testIsCheck4', intType); |
768 checkReturn('testIsCheck7', intType); | 768 checkReturn('testIsCheck5', intType); |
769 checkReturn('testIsCheck8', commonMasks.dynamicType); | 769 checkReturn('testIsCheck6', commonMasks.dynamicType); |
770 checkReturn('testIsCheck9', intType); | 770 checkReturn('testIsCheck7', intType); |
771 checkReturn('testIsCheck10', commonMasks.dynamicType); | 771 checkReturn('testIsCheck8', commonMasks.dynamicType); |
772 checkReturn('testIsCheck11', intType); | 772 checkReturn('testIsCheck9', intType); |
773 checkReturn('testIsCheck12', commonMasks.dynamicType); | 773 checkReturn('testIsCheck10', commonMasks.dynamicType); |
774 checkReturn('testIsCheck13', intType); | 774 checkReturn('testIsCheck11', intType); |
775 checkReturn('testIsCheck14', commonMasks.dynamicType); | 775 checkReturn('testIsCheck12', commonMasks.dynamicType); |
776 checkReturn('testIsCheck15', intType); | 776 checkReturn('testIsCheck13', intType); |
777 checkReturn('testIsCheck16', commonMasks.dynamicType); | 777 checkReturn('testIsCheck14', commonMasks.dynamicType); |
778 checkReturn('testIsCheck17', intType); | 778 checkReturn('testIsCheck15', intType); |
779 checkReturn('testIsCheck18', commonMasks.dynamicType); | 779 checkReturn('testIsCheck16', commonMasks.dynamicType); |
780 checkReturn('testIsCheck19', commonMasks.dynamicType); | 780 checkReturn('testIsCheck17', intType); |
781 checkReturn('testIsCheck20', interceptorType); | 781 checkReturn('testIsCheck18', commonMasks.dynamicType); |
782 checkReturn('testIsCheck21', commonMasks.dynamicType); | 782 checkReturn('testIsCheck19', commonMasks.dynamicType); |
783 checkReturn('testIsCheck22', commonMasks.dynamicType); | 783 checkReturn('testIsCheck20', interceptorType); |
784 checkReturn('testIsCheck23', intType); | 784 checkReturn('testIsCheck21', commonMasks.dynamicType); |
785 checkReturn('testIsCheck24', intType); | 785 checkReturn('testIsCheck22', commonMasks.dynamicType); |
786 checkReturn('testIsCheck25', commonMasks.dynamicType); | 786 checkReturn('testIsCheck23', intType); |
787 checkReturn('testIsCheck26', intType); | 787 checkReturn('testIsCheck24', intType); |
788 checkReturn('testIsCheck27', intType); | 788 checkReturn('testIsCheck25', commonMasks.dynamicType); |
789 checkReturn('testIsCheck28', commonMasks.dynamicType); | 789 checkReturn('testIsCheck26', intType); |
790 checkReturn('testIsCheck29', commonMasks.dynamicType); | 790 checkReturn('testIsCheck27', intType); |
791 checkReturn('testIf1', commonMasks.uint31Type.nullable()); | 791 checkReturn('testIsCheck28', commonMasks.dynamicType); |
792 checkReturn('testIf2', commonMasks.uint31Type.nullable()); | 792 checkReturn('testIsCheck29', commonMasks.dynamicType); |
793 checkReturn('returnAsString', new TypeMask.subtype( | 793 checkReturn('testIf1', commonMasks.uint31Type.nullable()); |
794 compiler.coreClasses.stringClass, compiler.world)); | 794 checkReturn('testIf2', commonMasks.uint31Type.nullable()); |
795 checkReturn('returnIntAsNum', commonMasks.uint31Type); | 795 checkReturn( |
796 checkReturn('returnAsTypedef', commonMasks.functionType.nullable()); | 796 'returnAsString', |
797 checkReturn('returnTopLevelGetter', commonMasks.uint31Type); | 797 new TypeMask.subtype( |
798 checkReturn('testDeadCode', commonMasks.uint31Type); | 798 compiler.coreClasses.stringClass, compiler.world)); |
799 checkReturn('testLabeledIf', commonMasks.uint31Type.nullable()); | 799 checkReturn('returnIntAsNum', commonMasks.uint31Type); |
800 checkReturn('testSwitch1', simplify( | 800 checkReturn('returnAsTypedef', commonMasks.functionType.nullable()); |
801 commonMasks.intType | 801 checkReturn('returnTopLevelGetter', commonMasks.uint31Type); |
802 .union(commonMasks.doubleType, compiler.world) | 802 checkReturn('testDeadCode', commonMasks.uint31Type); |
803 .nullable(), | 803 checkReturn('testLabeledIf', commonMasks.uint31Type.nullable()); |
804 compiler)); | 804 checkReturn( |
805 checkReturn('testSwitch2', commonMasks.uint31Type); | 805 'testSwitch1', |
806 checkReturn('testSwitch3', interceptorType.nullable()); | 806 simplify( |
807 checkReturn('testSwitch4', commonMasks.uint31Type); | 807 commonMasks.intType |
808 checkReturn('testSwitch5', commonMasks.uint31Type); | 808 .union(commonMasks.doubleType, compiler.world) |
809 checkReturn('testContinue1', interceptorType.nullable()); | 809 .nullable(), |
810 checkReturn('testBreak1', interceptorType.nullable()); | 810 compiler)); |
811 checkReturn('testContinue2', interceptorType.nullable()); | 811 checkReturn('testSwitch2', commonMasks.uint31Type); |
812 checkReturn('testBreak2', commonMasks.uint32Type.nullable()); | 812 checkReturn('testSwitch3', interceptorType.nullable()); |
813 checkReturn('testReturnElementOfConstList1', commonMasks.uint31Type); | 813 checkReturn('testSwitch4', commonMasks.uint31Type); |
814 checkReturn('testReturnElementOfConstList2', commonMasks.uint31Type); | 814 checkReturn('testSwitch5', commonMasks.uint31Type); |
815 checkReturn('testReturnItselfOrInt', commonMasks.uint31Type); | 815 checkReturn('testContinue1', interceptorType.nullable()); |
816 checkReturn('testReturnInvokeDynamicGetter', commonMasks.dynamicType); | 816 checkReturn('testBreak1', interceptorType.nullable()); |
| 817 checkReturn('testContinue2', interceptorType.nullable()); |
| 818 checkReturn('testBreak2', commonMasks.uint32Type.nullable()); |
| 819 checkReturn('testReturnElementOfConstList1', commonMasks.uint31Type); |
| 820 checkReturn('testReturnElementOfConstList2', commonMasks.uint31Type); |
| 821 checkReturn('testReturnItselfOrInt', commonMasks.uint31Type); |
| 822 checkReturn('testReturnInvokeDynamicGetter', commonMasks.dynamicType); |
817 | 823 |
818 checkReturn('testDoWhile1', commonMasks.stringType); | 824 checkReturn('testDoWhile1', commonMasks.stringType); |
819 checkReturn('testDoWhile2', commonMasks.nullType); | 825 checkReturn('testDoWhile2', commonMasks.nullType); |
820 checkReturn('testDoWhile3', commonMasks.uint31Type); | 826 checkReturn('testDoWhile3', commonMasks.uint31Type); |
821 checkReturn('testDoWhile4', commonMasks.numType); | 827 checkReturn('testDoWhile4', commonMasks.numType); |
822 | 828 |
823 checkReturnInClass(String className, String methodName, type) { | 829 checkReturnInClass(String className, String methodName, type) { |
824 var cls = findElement(compiler, className); | 830 var cls = findElement(compiler, className); |
825 var element = cls.lookupLocalMember(methodName); | 831 var element = cls.lookupLocalMember(methodName); |
826 Expect.equals(type, | 832 Expect.equals( |
827 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), | 833 type, |
828 '$className:$methodName'); | 834 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), |
829 } | 835 '$className:$methodName'); |
| 836 } |
830 | 837 |
831 checkReturnInClass('A', 'returnInt1', commonMasks.uint32Type); | 838 checkReturnInClass('A', 'returnInt1', commonMasks.uint32Type); |
832 checkReturnInClass('A', 'returnInt2', commonMasks.uint32Type); | 839 checkReturnInClass('A', 'returnInt2', commonMasks.uint32Type); |
833 checkReturnInClass('A', 'returnInt3', commonMasks.uint32Type); | 840 checkReturnInClass('A', 'returnInt3', commonMasks.uint32Type); |
834 checkReturnInClass('A', 'returnInt4', commonMasks.uint32Type); | 841 checkReturnInClass('A', 'returnInt4', commonMasks.uint32Type); |
835 checkReturnInClass('A', 'returnInt5', commonMasks.uint32Type); | 842 checkReturnInClass('A', 'returnInt5', commonMasks.uint32Type); |
836 checkReturnInClass('A', 'returnInt6', commonMasks.uint32Type); | 843 checkReturnInClass('A', 'returnInt6', commonMasks.uint32Type); |
837 checkReturnInClass('A', '==', interceptorType); | 844 checkReturnInClass('A', '==', interceptorType); |
838 | 845 |
839 checkReturnInClass('B', 'returnInt1', commonMasks.uint32Type); | 846 checkReturnInClass('B', 'returnInt1', commonMasks.uint32Type); |
840 checkReturnInClass('B', 'returnInt2', commonMasks.uint32Type); | 847 checkReturnInClass('B', 'returnInt2', commonMasks.uint32Type); |
841 checkReturnInClass('B', 'returnInt3', commonMasks.uint32Type); | 848 checkReturnInClass('B', 'returnInt3', commonMasks.uint32Type); |
842 checkReturnInClass('B', 'returnInt4', commonMasks.uint32Type); | 849 checkReturnInClass('B', 'returnInt4', commonMasks.uint32Type); |
843 checkReturnInClass('B', 'returnInt5', commonMasks.uint32Type); | 850 checkReturnInClass('B', 'returnInt5', commonMasks.uint32Type); |
844 checkReturnInClass('B', 'returnInt6', commonMasks.uint32Type); | 851 checkReturnInClass('B', 'returnInt6', commonMasks.uint32Type); |
845 checkReturnInClass('B', 'returnInt7', commonMasks.uint32Type); | 852 checkReturnInClass('B', 'returnInt7', commonMasks.uint32Type); |
846 checkReturnInClass('B', 'returnInt8', commonMasks.uint32Type); | 853 checkReturnInClass('B', 'returnInt8', commonMasks.uint32Type); |
847 checkReturnInClass('B', 'returnInt9', commonMasks.uint31Type); | 854 checkReturnInClass('B', 'returnInt9', commonMasks.uint31Type); |
848 | 855 |
849 checkReturnInClass('C', 'returnInt1', commonMasks.positiveIntType); | 856 checkReturnInClass('C', 'returnInt1', commonMasks.positiveIntType); |
850 checkReturnInClass('C', 'returnInt2', commonMasks.positiveIntType); | 857 checkReturnInClass('C', 'returnInt2', commonMasks.positiveIntType); |
851 checkReturnInClass('C', 'returnInt3', commonMasks.positiveIntType); | 858 checkReturnInClass('C', 'returnInt3', commonMasks.positiveIntType); |
852 checkReturnInClass('C', 'returnInt4', commonMasks.positiveIntType); | 859 checkReturnInClass('C', 'returnInt4', commonMasks.positiveIntType); |
853 checkReturnInClass('C', 'returnInt5', commonMasks.positiveIntType); | 860 checkReturnInClass('C', 'returnInt5', commonMasks.positiveIntType); |
854 checkReturnInClass('C', 'returnInt6', commonMasks.positiveIntType); | 861 checkReturnInClass('C', 'returnInt6', commonMasks.positiveIntType); |
855 | 862 |
856 checkFactoryConstructor(String className, String factoryName) { | 863 checkFactoryConstructor(String className, String factoryName) { |
857 var cls = findElement(compiler, className); | 864 var cls = findElement(compiler, className); |
858 var element = cls.localLookup(factoryName); | 865 var element = cls.localLookup(factoryName); |
859 Expect.equals(new TypeMask.nonNullExact(cls, world), | 866 Expect.equals(new TypeMask.nonNullExact(cls, world), |
860 typesInferrer.getReturnTypeOfElement(element)); | 867 typesInferrer.getReturnTypeOfElement(element)); |
861 } | 868 } |
862 checkFactoryConstructor('A', ''); | 869 checkFactoryConstructor('A', ''); |
863 | 870 |
864 checkReturn('testCascade1', commonMasks.growableListType); | 871 checkReturn('testCascade1', commonMasks.growableListType); |
865 checkReturn('testCascade2', new TypeMask.nonNullExact( | 872 checkReturn( |
866 findElement(compiler, 'CascadeHelper'), world)); | 873 'testCascade2', |
867 checkReturn('testSpecialization1', commonMasks.numType); | 874 new TypeMask.nonNullExact( |
868 checkReturn('testSpecialization2', commonMasks.dynamicType); | 875 findElement(compiler, 'CascadeHelper'), world)); |
869 checkReturn('testSpecialization3', commonMasks.uint31Type.nullable()); | 876 checkReturn('testSpecialization1', commonMasks.numType); |
870 checkReturn('testReturnNull1', commonMasks.nullType); | 877 checkReturn('testSpecialization2', commonMasks.dynamicType); |
871 checkReturn('testReturnNull2', commonMasks.nullType); | 878 checkReturn('testSpecialization3', commonMasks.uint31Type.nullable()); |
872 checkReturn('testReturnNull3', commonMasks.dynamicType); | 879 checkReturn('testReturnNull1', commonMasks.nullType); |
873 checkReturn('testReturnNull4', commonMasks.nullType); | 880 checkReturn('testReturnNull2', commonMasks.nullType); |
874 checkReturn('testReturnNull5', commonMasks.nullType); | 881 checkReturn('testReturnNull3', commonMasks.dynamicType); |
875 checkReturn('testReturnNull6', commonMasks.dynamicType); | 882 checkReturn('testReturnNull4', commonMasks.nullType); |
876 checkReturn('testReturnNotEquals', commonMasks.boolType); | 883 checkReturn('testReturnNull5', commonMasks.nullType); |
877 })); | 884 checkReturn('testReturnNull6', commonMasks.dynamicType); |
| 885 checkReturn('testReturnNotEquals', commonMasks.boolType); |
| 886 })); |
878 } | 887 } |
OLD | NEW |