| 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 | 7 import |
| 8 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' | 8 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' |
| 9 show TypeMask; | 9 show TypeMask; |
| 10 import 'type_mask_test_helper.dart'; |
| 10 | 11 |
| 11 import 'compiler_helper.dart'; | 12 import 'compiler_helper.dart'; |
| 12 import 'parser_helper.dart'; | 13 import 'parser_helper.dart'; |
| 14 import 'type_mask_test_helper.dart'; |
| 13 | 15 |
| 14 const String TEST = """ | 16 const String TEST = """ |
| 15 returnNum1(a) { | 17 returnNum1(a) { |
| 16 if (a) return 1; | 18 if (a) return 1; |
| 17 else return 2.5; | 19 else return 2.5; |
| 18 } | 20 } |
| 19 | 21 |
| 20 returnNum2(a) { | 22 returnNum2(a) { |
| 21 if (a) return 1.4; | 23 if (a) return 1.4; |
| 22 else return 2; | 24 else return 2; |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 Uri uri = new Uri(scheme: 'source'); | 709 Uri uri = new Uri(scheme: 'source'); |
| 708 var compiler = compilerFor(TEST, uri); | 710 var compiler = compilerFor(TEST, uri); |
| 709 asyncTest(() => compiler.runCompiler(uri).then((_) { | 711 asyncTest(() => compiler.runCompiler(uri).then((_) { |
| 710 var typesTask = compiler.typesTask; | 712 var typesTask = compiler.typesTask; |
| 711 var typesInferrer = typesTask.typesInferrer; | 713 var typesInferrer = typesTask.typesInferrer; |
| 712 | 714 |
| 713 checkReturn(String name, type) { | 715 checkReturn(String name, type) { |
| 714 var element = findElement(compiler, name); | 716 var element = findElement(compiler, name); |
| 715 Expect.equals( | 717 Expect.equals( |
| 716 type, | 718 type, |
| 717 typesInferrer.getReturnTypeOfElement(element).simplify(compiler), | 719 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), |
| 718 name); | 720 name); |
| 719 } | 721 } |
| 720 var interceptorType = | 722 var interceptorType = |
| 721 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); | 723 findTypeMask(compiler, 'Interceptor', 'nonNullSubclass'); |
| 722 | 724 |
| 723 checkReturn('returnNum1', typesTask.numType); | 725 checkReturn('returnNum1', typesTask.numType); |
| 724 checkReturn('returnNum2', typesTask.numType); | 726 checkReturn('returnNum2', typesTask.numType); |
| 725 checkReturn('returnInt1', typesTask.uint31Type); | 727 checkReturn('returnInt1', typesTask.uint31Type); |
| 726 checkReturn('returnInt2', typesTask.uint31Type); | 728 checkReturn('returnInt2', typesTask.uint31Type); |
| 727 checkReturn('returnDouble', typesTask.doubleType); | 729 checkReturn('returnDouble', typesTask.doubleType); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 checkReturn('testIsCheck29', typesTask.dynamicType); | 770 checkReturn('testIsCheck29', typesTask.dynamicType); |
| 769 checkReturn('testIf1', typesTask.uint31Type.nullable()); | 771 checkReturn('testIf1', typesTask.uint31Type.nullable()); |
| 770 checkReturn('testIf2', typesTask.uint31Type.nullable()); | 772 checkReturn('testIf2', typesTask.uint31Type.nullable()); |
| 771 checkReturn('returnAsString', | 773 checkReturn('returnAsString', |
| 772 new TypeMask.subtype(compiler.stringClass)); | 774 new TypeMask.subtype(compiler.stringClass)); |
| 773 checkReturn('returnIntAsNum', typesTask.uint31Type); | 775 checkReturn('returnIntAsNum', typesTask.uint31Type); |
| 774 checkReturn('returnAsTypedef', typesTask.functionType.nullable()); | 776 checkReturn('returnAsTypedef', typesTask.functionType.nullable()); |
| 775 checkReturn('returnTopLevelGetter', typesTask.uint31Type); | 777 checkReturn('returnTopLevelGetter', typesTask.uint31Type); |
| 776 checkReturn('testDeadCode', typesTask.uint31Type); | 778 checkReturn('testDeadCode', typesTask.uint31Type); |
| 777 checkReturn('testLabeledIf', typesTask.uint31Type.nullable()); | 779 checkReturn('testLabeledIf', typesTask.uint31Type.nullable()); |
| 778 checkReturn('testSwitch1', typesTask.intType | 780 checkReturn('testSwitch1', simplify( |
| 779 .union(typesTask.doubleType, compiler) | 781 typesTask.intType |
| 780 .nullable().simplify(compiler)); | 782 .union(typesTask.doubleType, compiler) |
| 783 .nullable(), |
| 784 compiler)); |
| 781 checkReturn('testSwitch2', typesTask.uint31Type); | 785 checkReturn('testSwitch2', typesTask.uint31Type); |
| 782 checkReturn('testSwitch3', interceptorType.nullable()); | 786 checkReturn('testSwitch3', interceptorType.nullable()); |
| 783 checkReturn('testSwitch4', typesTask.uint31Type); | 787 checkReturn('testSwitch4', typesTask.uint31Type); |
| 784 checkReturn('testSwitch5', typesTask.uint31Type); | 788 checkReturn('testSwitch5', typesTask.uint31Type); |
| 785 checkReturn('testContinue1', interceptorType.nullable()); | 789 checkReturn('testContinue1', interceptorType.nullable()); |
| 786 checkReturn('testBreak1', interceptorType.nullable()); | 790 checkReturn('testBreak1', interceptorType.nullable()); |
| 787 checkReturn('testContinue2', interceptorType.nullable()); | 791 checkReturn('testContinue2', interceptorType.nullable()); |
| 788 checkReturn('testBreak2', typesTask.positiveIntType.nullable()); | 792 checkReturn('testBreak2', typesTask.positiveIntType.nullable()); |
| 789 checkReturn('testReturnElementOfConstList1', typesTask.uint31Type); | 793 checkReturn('testReturnElementOfConstList1', typesTask.uint31Type); |
| 790 checkReturn('testReturnElementOfConstList2', typesTask.uint31Type); | 794 checkReturn('testReturnElementOfConstList2', typesTask.uint31Type); |
| 791 checkReturn('testReturnItselfOrInt', typesTask.uint31Type); | 795 checkReturn('testReturnItselfOrInt', typesTask.uint31Type); |
| 792 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType); | 796 checkReturn('testReturnInvokeDynamicGetter', typesTask.dynamicType); |
| 793 | 797 |
| 794 checkReturn('testDoWhile1', typesTask.stringType); | 798 checkReturn('testDoWhile1', typesTask.stringType); |
| 795 checkReturn('testDoWhile2', typesTask.nullType); | 799 checkReturn('testDoWhile2', typesTask.nullType); |
| 796 checkReturn('testDoWhile3', typesTask.uint31Type); | 800 checkReturn('testDoWhile3', typesTask.uint31Type); |
| 797 checkReturn('testDoWhile4', typesTask.numType); | 801 checkReturn('testDoWhile4', typesTask.numType); |
| 798 | 802 |
| 799 checkReturnInClass(String className, String methodName, type) { | 803 checkReturnInClass(String className, String methodName, type) { |
| 800 var cls = findElement(compiler, className); | 804 var cls = findElement(compiler, className); |
| 801 var element = cls.lookupLocalMember(methodName); | 805 var element = cls.lookupLocalMember(methodName); |
| 802 Expect.equals(type, | 806 Expect.equals(type, |
| 803 typesInferrer.getReturnTypeOfElement(element).simplify(compiler), | 807 simplify(typesInferrer.getReturnTypeOfElement(element), compiler), |
| 804 '$className:$methodName'); | 808 '$className:$methodName'); |
| 805 } | 809 } |
| 806 | 810 |
| 807 checkReturnInClass('A', 'returnInt1', typesTask.positiveIntType); | 811 checkReturnInClass('A', 'returnInt1', typesTask.positiveIntType); |
| 808 checkReturnInClass('A', 'returnInt2', typesTask.positiveIntType); | 812 checkReturnInClass('A', 'returnInt2', typesTask.positiveIntType); |
| 809 checkReturnInClass('A', 'returnInt3', typesTask.positiveIntType); | 813 checkReturnInClass('A', 'returnInt3', typesTask.positiveIntType); |
| 810 checkReturnInClass('A', 'returnInt4', typesTask.positiveIntType); | 814 checkReturnInClass('A', 'returnInt4', typesTask.positiveIntType); |
| 811 checkReturnInClass('A', 'returnInt5', typesTask.positiveIntType); | 815 checkReturnInClass('A', 'returnInt5', typesTask.positiveIntType); |
| 812 checkReturnInClass('A', 'returnInt6', typesTask.positiveIntType); | 816 checkReturnInClass('A', 'returnInt6', typesTask.positiveIntType); |
| 813 checkReturnInClass('A', '==', interceptorType); | 817 checkReturnInClass('A', '==', interceptorType); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 838 checkReturn('testSpecialization3', typesTask.uint31Type.nullable()); | 842 checkReturn('testSpecialization3', typesTask.uint31Type.nullable()); |
| 839 checkReturn('testReturnNull1', typesTask.nullType); | 843 checkReturn('testReturnNull1', typesTask.nullType); |
| 840 checkReturn('testReturnNull2', typesTask.nullType); | 844 checkReturn('testReturnNull2', typesTask.nullType); |
| 841 checkReturn('testReturnNull3', typesTask.dynamicType); | 845 checkReturn('testReturnNull3', typesTask.dynamicType); |
| 842 checkReturn('testReturnNull4', typesTask.nullType); | 846 checkReturn('testReturnNull4', typesTask.nullType); |
| 843 checkReturn('testReturnNull5', typesTask.nullType); | 847 checkReturn('testReturnNull5', typesTask.nullType); |
| 844 checkReturn('testReturnNull6', typesTask.dynamicType); | 848 checkReturn('testReturnNull6', typesTask.dynamicType); |
| 845 checkReturn('testReturnNotEquals', typesTask.boolType); | 849 checkReturn('testReturnNotEquals', typesTask.boolType); |
| 846 })); | 850 })); |
| 847 } | 851 } |
| OLD | NEW |