OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:async_helper/async_helper.dart'; | 5 import 'package:async_helper/async_helper.dart'; |
6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
7 import 'package:compiler/src/js_backend/backend_helpers.dart'; | 7 import 'package:compiler/src/js_backend/backend_helpers.dart'; |
8 import 'package:compiler/src/js_backend/js_backend.dart'; | 8 import 'package:compiler/src/js_backend/js_backend.dart'; |
9 import 'package:compiler/src/types/types.dart'; | 9 import 'package:compiler/src/types/types.dart'; |
10 import 'package:compiler/src/world.dart'; | 10 import 'package:compiler/src/world.dart'; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 typesSeen..add(type1)..add(type2); | 69 typesSeen..add(type1)..add(type2); |
70 var pair1 = new Pair(type1, type2); | 70 var pair1 = new Pair(type1, type2); |
71 var pair2 = new Pair(type2, type1); | 71 var pair2 = new Pair(type2, type1); |
72 if (pairsSeen.contains(pair1)) { | 72 if (pairsSeen.contains(pair1)) { |
73 Expect.isFalse(true, 'Redundant rule ($type1, $type2, ...)'); | 73 Expect.isFalse(true, 'Redundant rule ($type1, $type2, ...)'); |
74 } | 74 } |
75 pairsSeen..add(pair1)..add(pair2); | 75 pairsSeen..add(pair1)..add(pair2); |
76 | 76 |
77 var r1 = operate(type1, type2); | 77 var r1 = operate(type1, type2); |
78 var r2 = operate(type2, type1); | 78 var r2 = operate(type2, type1); |
79 Expect.equals(result, r1); | 79 Expect.equals(result, r1, |
80 Expect.equals(r1, r2, 'symmetry violation'); | 80 "Unexpected result of $name($type1,$type2)"); |
| 81 Expect.equals(r1, r2, 'Symmetry violation of $name($type1,$type2)'); |
81 } | 82 } |
82 | 83 |
83 void check(type1, type2, predicate) { | 84 void check(type1, type2, predicate) { |
84 typesSeen..add(type1)..add(type2); | 85 typesSeen..add(type1)..add(type2); |
85 var pair = new Pair(type1, type2); | 86 var pair = new Pair(type1, type2); |
86 pairsSeen..add(pair); | 87 pairsSeen..add(pair); |
87 var result = operate(type1, type2); | 88 var result = operate(type1, type2); |
88 Expect.isTrue(predicate(result)); | 89 Expect.isTrue(predicate(result)); |
89 } | 90 } |
90 | 91 |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 | 725 |
725 void testRegressions(MockCompiler compiler) { | 726 void testRegressions(MockCompiler compiler) { |
726 TypeMask nonNullPotentialString = new TypeMask.nonNullSubtype( | 727 TypeMask nonNullPotentialString = new TypeMask.nonNullSubtype( |
727 patternClass, compiler.world); | 728 patternClass, compiler.world); |
728 Expect.equals( | 729 Expect.equals( |
729 potentialString, jsStringOrNull.union( | 730 potentialString, jsStringOrNull.union( |
730 nonNullPotentialString, compiler.world)); | 731 nonNullPotentialString, compiler.world)); |
731 } | 732 } |
732 | 733 |
733 void main() { | 734 void main() { |
734 asyncTest(() => MockCompiler.create((MockCompiler compiler) { | 735 asyncTest(() async { |
| 736 MockCompiler compiler = new MockCompiler.internal(); |
| 737 await compiler.init(""" |
| 738 class PatternImpl implements Pattern {} |
| 739 """); |
735 JavaScriptBackend backend = compiler.backend; | 740 JavaScriptBackend backend = compiler.backend; |
736 BackendHelpers helpers = backend.helpers; | 741 BackendHelpers helpers = backend.helpers; |
737 World world = compiler.world; | 742 World world = compiler.world; |
738 helpers.interceptorsLibrary.forEachLocalMember((element) { | 743 helpers.interceptorsLibrary.forEachLocalMember((element) { |
739 if (element.isClass) { | 744 if (element.isClass) { |
740 element.ensureResolved(compiler.resolution); | 745 element.ensureResolved(compiler.resolution); |
741 backend.registerInstantiatedType( | 746 backend.registerInstantiatedType( |
742 element.rawType, | 747 element.rawType, |
743 compiler.enqueuer.resolution, | 748 compiler.enqueuer.resolution, |
744 compiler.globalDependencies); | 749 compiler.globalDependencies); |
745 } | 750 } |
746 }); | 751 }); |
| 752 ClassElement patternImplClass = compiler.mainApp.find('PatternImpl'); |
| 753 patternImplClass.ensureResolved(compiler.resolution); |
| 754 |
747 backend.registerInstantiatedType( | 755 backend.registerInstantiatedType( |
748 compiler.coreTypes.mapType(), | 756 compiler.coreTypes.mapType(), |
749 compiler.enqueuer.resolution, | 757 compiler.enqueuer.resolution, |
750 compiler.globalDependencies); | 758 compiler.globalDependencies); |
751 backend.registerInstantiatedType( | 759 backend.registerInstantiatedType( |
752 compiler.coreTypes.functionType, | 760 compiler.coreTypes.functionType, |
753 compiler.enqueuer.resolution, | 761 compiler.enqueuer.resolution, |
754 compiler.globalDependencies); | 762 compiler.globalDependencies); |
| 763 backend.registerInstantiatedType( |
| 764 patternImplClass.rawType, |
| 765 compiler.enqueuer.resolution, |
| 766 compiler.globalDependencies); |
755 compiler.world.populate(); | 767 compiler.world.populate(); |
756 | 768 |
757 // Grab hold of a supertype for String so we can produce potential | 769 // Grab hold of a supertype for String so we can produce potential |
758 // string types. | 770 // string types. |
759 patternClass = compiler.coreLibrary.find('Pattern'); | 771 patternClass = compiler.coreLibrary.find('Pattern'); |
760 | 772 |
761 nonPrimitive1 = new TypeMask.nonNullSubtype( | 773 nonPrimitive1 = new TypeMask.nonNullSubtype( |
762 compiler.coreClasses.mapClass, world); | 774 compiler.coreClasses.mapClass, world); |
763 nonPrimitive2 = new TypeMask.nonNullSubtype( | 775 nonPrimitive2 = new TypeMask.nonNullSubtype( |
764 compiler.coreClasses.functionClass, world); | 776 compiler.coreClasses.functionClass, world); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 jsNumberOrNull = new TypeMask.subclass(helpers.jsNumberClass, world); | 810 jsNumberOrNull = new TypeMask.subclass(helpers.jsNumberClass, world); |
799 jsIntegerOrNull = new TypeMask.exact(helpers.jsIntClass, world); | 811 jsIntegerOrNull = new TypeMask.exact(helpers.jsIntClass, world); |
800 jsDoubleOrNull = new TypeMask.exact(helpers.jsDoubleClass, world); | 812 jsDoubleOrNull = new TypeMask.exact(helpers.jsDoubleClass, world); |
801 nullType = const TypeMask.empty(); | 813 nullType = const TypeMask.empty(); |
802 objectType = new TypeMask.nonNullSubclass( | 814 objectType = new TypeMask.nonNullSubclass( |
803 compiler.coreClasses.objectClass, world); | 815 compiler.coreClasses.objectClass, world); |
804 emptyType = const TypeMask.nonNullEmpty(); | 816 emptyType = const TypeMask.nonNullEmpty(); |
805 dynamicType = new TypeMask.subclass( | 817 dynamicType = new TypeMask.subclass( |
806 compiler.coreClasses.objectClass, world); | 818 compiler.coreClasses.objectClass, world); |
807 | 819 |
| 820 Expect.notEquals(emptyType, nonPrimitive1, |
| 821 "nonPrimitive1 expected to be non-empty."); |
| 822 Expect.notEquals(jsStringOrNull, potentialString, |
| 823 "potentialString expected not to be exact JSString"); |
| 824 Expect.notEquals(jsArrayOrNull, potentialArray, |
| 825 "potentialArray expected not to be JSArray subclass"); |
| 826 |
808 testUnion(compiler); | 827 testUnion(compiler); |
809 testIntersection(compiler); | 828 testIntersection(compiler); |
810 testRegressions(compiler); | 829 testRegressions(compiler); |
811 })); | 830 }); |
812 } | 831 } |
OLD | NEW |