| 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import 'package:compiler/src/types/types.dart'; | 8 import 'package:compiler/src/types/types.dart'; |
| 9 import 'package:compiler/src/inferrer/concrete_types_inferrer.dart'; | 9 import 'package:compiler/src/inferrer/concrete_types_inferrer.dart'; |
| 10 | 10 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 * Checks that [: className#fieldName :]'s inferred type is the unknown | 137 * Checks that [: className#fieldName :]'s inferred type is the unknown |
| 138 * concrete type. | 138 * concrete type. |
| 139 */ | 139 */ |
| 140 void checkFieldHasUknownType(String className, String fieldName) { | 140 void checkFieldHasUknownType(String className, String fieldName) { |
| 141 Expect.isTrue( | 141 Expect.isTrue( |
| 142 inferrer.inferredFieldTypes[findField(className, fieldName)] | 142 inferrer.inferredFieldTypes[findField(className, fieldName)] |
| 143 .isUnknown()); | 143 .isUnknown()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 /** Checks that the inferred type for [selector] is [mask]. */ | 146 /** Checks that the inferred type for [selector] is [mask]. */ |
| 147 void checkSelectorHasType(Selector selector, | 147 void checkSelectorHasType(Selector selector, TypeMask mask) { |
| 148 TypeMask mask, | 148 Expect.equals(mask, inferrer.getTypeOfSelector(selector)); |
| 149 TypeMask expectedMask) { | |
| 150 Expect.equals(expectedMask, inferrer.getTypeOfSelector(selector, mask)); | |
| 151 } | 149 } |
| 152 } | 150 } |
| 153 | 151 |
| 154 const String DYNAMIC = '"__dynamic_for_test"'; | 152 const String DYNAMIC = '"__dynamic_for_test"'; |
| 155 | 153 |
| 156 Future<AnalysisResult> analyze(String code, {int maxConcreteTypeSize: 1000}) { | 154 Future<AnalysisResult> analyze(String code, {int maxConcreteTypeSize: 1000}) { |
| 157 Uri uri = new Uri(scheme: 'dart', path: 'test'); | 155 Uri uri = new Uri(scheme: 'dart', path: 'test'); |
| 158 MockCompiler compiler = new MockCompiler.internal( | 156 MockCompiler compiler = new MockCompiler.internal( |
| 159 enableConcreteTypeInference: true, | 157 enableConcreteTypeInference: true, |
| 160 maxConcreteTypeSize: maxConcreteTypeSize); | 158 maxConcreteTypeSize: maxConcreteTypeSize); |
| (...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 ClassElement c = findElement(result.compiler, 'C'); | 1641 ClassElement c = findElement(result.compiler, 'C'); |
| 1644 ClassElement xy = findElement(result.compiler, 'XY'); | 1642 ClassElement xy = findElement(result.compiler, 'XY'); |
| 1645 ClassElement x = findElement(result.compiler, 'X'); | 1643 ClassElement x = findElement(result.compiler, 'X'); |
| 1646 ClassElement y = findElement(result.compiler, 'Y'); | 1644 ClassElement y = findElement(result.compiler, 'Y'); |
| 1647 ClassElement z = findElement(result.compiler, 'Z'); | 1645 ClassElement z = findElement(result.compiler, 'Z'); |
| 1648 | 1646 |
| 1649 Selector foo = new Selector.call("foo", null, 0); | 1647 Selector foo = new Selector.call("foo", null, 0); |
| 1650 | 1648 |
| 1651 result.checkSelectorHasType( | 1649 result.checkSelectorHasType( |
| 1652 foo, | 1650 foo, |
| 1653 null, | |
| 1654 new TypeMask.unionOf([a, b, c] | 1651 new TypeMask.unionOf([a, b, c] |
| 1655 .map((cls) => new TypeMask.nonNullExact(cls, world)), | 1652 .map((cls) => new TypeMask.nonNullExact(cls, world)), |
| 1656 result.compiler.world)); | 1653 result.compiler.world)); |
| 1657 result.checkSelectorHasType( | 1654 result.checkSelectorHasType( |
| 1658 foo, | 1655 new TypedSelector.subclass(x, foo, world), |
| 1659 new TypeMask.subclass(x, world), | |
| 1660 new TypeMask.nonNullExact(b, world)); | 1656 new TypeMask.nonNullExact(b, world)); |
| 1661 result.checkSelectorHasType( | 1657 result.checkSelectorHasType( |
| 1662 foo, | 1658 new TypedSelector.subclass(y, foo, world), |
| 1663 new TypeMask.subclass(y, world), | |
| 1664 new TypeMask.nonNullExact(c, world)); | 1659 new TypeMask.nonNullExact(c, world)); |
| 1665 result.checkSelectorHasType( | 1660 result.checkSelectorHasType( |
| 1666 foo, | 1661 new TypedSelector.subclass(z, foo, world), |
| 1667 new TypeMask.subclass(z, world), | |
| 1668 new TypeMask.nonNullExact(a, world)); | 1662 new TypeMask.nonNullExact(a, world)); |
| 1669 result.checkSelectorHasType( | 1663 result.checkSelectorHasType( |
| 1670 foo, | 1664 new TypedSelector.subclass(xy, foo, world), |
| 1671 new TypeMask.subclass(xy, world), | |
| 1672 new TypeMask.unionOf([b, c].map((cls) => | 1665 new TypeMask.unionOf([b, c].map((cls) => |
| 1673 new TypeMask.nonNullExact(cls, world)), world)); | 1666 new TypeMask.nonNullExact(cls, world)), world)); |
| 1674 | 1667 |
| 1675 result.checkSelectorHasType(new Selector.call("bar", null, 0), null, null); | 1668 result.checkSelectorHasType(new Selector.call("bar", null, 0), null); |
| 1676 }); | 1669 }); |
| 1677 } | 1670 } |
| 1678 | 1671 |
| 1679 testEqualsNullSelector() { | 1672 testEqualsNullSelector() { |
| 1680 final String source = r""" | 1673 final String source = r""" |
| 1681 main() { | 1674 main() { |
| 1682 1 == null; | 1675 1 == null; |
| 1683 } | 1676 } |
| 1684 """; | 1677 """; |
| 1685 return analyze(source).then((result) { | 1678 return analyze(source).then((result) { |
| 1686 ClassElement bool = result.compiler.backend.boolImplementation; | 1679 ClassElement bool = result.compiler.backend.boolImplementation; |
| 1687 result.checkSelectorHasType(new Selector.binaryOperator('=='), | 1680 result.checkSelectorHasType(new Selector.binaryOperator('=='), |
| 1688 null, | |
| 1689 new TypeMask.nonNullExact(bool, | 1681 new TypeMask.nonNullExact(bool, |
| 1690 result.compiler.world)); | 1682 result.compiler.world)); |
| 1691 }); | 1683 }); |
| 1692 } | 1684 } |
| 1693 | 1685 |
| 1694 testMixins() { | 1686 testMixins() { |
| 1695 final String source = r""" | 1687 final String source = r""" |
| 1696 class A { | 1688 class A { |
| 1697 foo() => "abc"; | 1689 foo() => "abc"; |
| 1698 get x => 42; | 1690 get x => 42; |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2143 testClosures10, | 2135 testClosures10, |
| 2144 testClosures11, | 2136 testClosures11, |
| 2145 testClosures12, | 2137 testClosures12, |
| 2146 testRefinement, | 2138 testRefinement, |
| 2147 testDefaultArguments, | 2139 testDefaultArguments, |
| 2148 testSuperConstructorCall, | 2140 testSuperConstructorCall, |
| 2149 testSuperConstructorCall2, | 2141 testSuperConstructorCall2, |
| 2150 testSuperConstructorCall3, | 2142 testSuperConstructorCall3, |
| 2151 ], (f) => f())); | 2143 ], (f) => f())); |
| 2152 } | 2144 } |
| OLD | NEW |