OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 'compiler_helper.dart'; | 7 import 'compiler_helper.dart'; |
8 import 'type_mask_test_helper.dart'; | 8 import 'type_mask_test_helper.dart'; |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 var commonMasks = compiler.commonMasks; | 26 var commonMasks = compiler.commonMasks; |
27 var typesInferrer = compiler.globalInference.typesInferrer; | 27 var typesInferrer = compiler.globalInference.typesInferrer; |
28 var foo = findElement(compiler, "foo"); | 28 var foo = findElement(compiler, "foo"); |
29 // Return type is null|bool. | 29 // Return type is null|bool. |
30 var mask = typesInferrer.getReturnTypeOfElement(foo); | 30 var mask = typesInferrer.getReturnTypeOfElement(foo); |
31 Expect.isTrue(mask.isNullable); | 31 Expect.isTrue(mask.isNullable); |
32 Expect.equals(commonMasks.boolType, simplify(mask.nonNullable(), compiler)); | 32 Expect.equals(commonMasks.boolType, simplify(mask.nonNullable(), compiler)); |
33 // First parameter is uint31|String|bool. | 33 // First parameter is uint31|String|bool. |
34 var mask1 = typesInferrer.getTypeOfElement(foo.parameters[0]); | 34 var mask1 = typesInferrer.getTypeOfElement(foo.parameters[0]); |
35 Expect.isTrue(mask1.isUnion); | 35 Expect.isTrue(mask1.isUnion); |
36 var expectedTypes = new Set.from([commonMasks.uint31Type, | 36 var expectedTypes = new Set.from( |
37 commonMasks.stringType, | 37 [commonMasks.uint31Type, commonMasks.stringType, commonMasks.boolType]); |
38 commonMasks.boolType]); | |
39 for (var typeMask in mask1.disjointMasks) { | 38 for (var typeMask in mask1.disjointMasks) { |
40 Expect.isFalse(typeMask.isNullable); | 39 Expect.isFalse(typeMask.isNullable); |
41 var simpleType = simplify(typeMask, compiler); | 40 var simpleType = simplify(typeMask, compiler); |
42 Expect.isTrue(expectedTypes.remove(simpleType), "$simpleType"); | 41 Expect.isTrue(expectedTypes.remove(simpleType), "$simpleType"); |
43 } | 42 } |
44 Expect.isTrue(expectedTypes.isEmpty); | 43 Expect.isTrue(expectedTypes.isEmpty); |
45 // Second parameter is bool or null. | 44 // Second parameter is bool or null. |
46 var mask2 = typesInferrer.getTypeOfElement(foo.parameters[1]); | 45 var mask2 = typesInferrer.getTypeOfElement(foo.parameters[1]); |
47 Expect.isTrue(mask2.isNullable); | 46 Expect.isTrue(mask2.isNullable); |
48 Expect.equals( | 47 Expect.equals( |
(...skipping 22 matching lines...) Expand all Loading... |
71 } | 70 } |
72 } | 71 } |
73 | 72 |
74 main() { | 73 main() { |
75 asyncStart(); | 74 asyncStart(); |
76 runTest().then((_) { | 75 runTest().then((_) { |
77 // Make sure that the type is still correct when we do a second compilation. | 76 // Make sure that the type is still correct when we do a second compilation. |
78 return runTest(); | 77 return runTest(); |
79 }).whenComplete(asyncEnd); | 78 }).whenComplete(asyncEnd); |
80 } | 79 } |
OLD | NEW |