OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 MapTypeMask, TypeMask; | 7 import 'package:compiler/src/types/types.dart' show MapTypeMask, TypeMask; |
8 | 8 |
9 import 'compiler_helper.dart'; | 9 import 'compiler_helper.dart'; |
10 import 'type_mask_test_helper.dart'; | 10 import 'type_mask_test_helper.dart'; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 // Test preset map of <String,uint32> | 204 // Test preset map of <String,uint32> |
205 doTest('{presetKey : anInt}', "presetKey", "anInt"); | 205 doTest('{presetKey : anInt}', "presetKey", "anInt"); |
206 // Test preset map of <Double,uint32> | 206 // Test preset map of <Double,uint32> |
207 doTest('{aDouble : anInt}', "aDouble", "anInt"); | 207 doTest('{aDouble : anInt}', "aDouble", "anInt"); |
208 } | 208 } |
209 | 209 |
210 void doTest(String allocation, [String keyElement, String valueElement]) { | 210 void doTest(String allocation, [String keyElement, String valueElement]) { |
211 Uri uri = new Uri(scheme: 'source'); | 211 Uri uri = new Uri(scheme: 'source'); |
212 var compiler = compilerFor(generateTest(allocation), uri, | 212 var compiler = compilerFor(generateTest(allocation), uri, |
213 expectedErrors: 0, expectedWarnings: 1); | 213 expectedErrors: 0, expectedWarnings: 1); |
214 var classWorld = compiler.openWorld.closeWorld(); | 214 var closedWorld = compiler.openWorld.closeWorld(); |
215 asyncTest(() => compiler.run(uri).then((_) { | 215 asyncTest(() => compiler.run(uri).then((_) { |
216 var keyType, valueType; | 216 var keyType, valueType; |
217 var commonMasks = compiler.commonMasks; | 217 var commonMasks = compiler.commonMasks; |
218 var typesInferrer = compiler.globalInference.typesInferrer; | 218 var typesInferrer = compiler.globalInference.typesInferrer; |
219 var emptyType = new TypeMask.nonNullEmpty(); | 219 var emptyType = new TypeMask.nonNullEmpty(); |
220 var aKeyType = | 220 var aKeyType = |
221 typesInferrer.getTypeOfElement(findElement(compiler, 'aKey')); | 221 typesInferrer.getTypeOfElement(findElement(compiler, 'aKey')); |
222 if (keyElement != null) { | 222 if (keyElement != null) { |
223 keyType = | 223 keyType = |
224 typesInferrer.getTypeOfElement(findElement(compiler, keyElement)); | 224 typesInferrer.getTypeOfElement(findElement(compiler, keyElement)); |
225 } | 225 } |
226 if (valueElement != null) { | 226 if (valueElement != null) { |
227 valueType = typesInferrer | 227 valueType = typesInferrer |
228 .getTypeOfElement(findElement(compiler, valueElement)); | 228 .getTypeOfElement(findElement(compiler, valueElement)); |
229 } | 229 } |
230 if (keyType == null) keyType = emptyType; | 230 if (keyType == null) keyType = emptyType; |
231 if (valueType == null) valueType = emptyType; | 231 if (valueType == null) valueType = emptyType; |
232 | 232 |
233 checkType(String name, keyType, valueType) { | 233 checkType(String name, keyType, valueType) { |
234 var element = findElement(compiler, name); | 234 var element = findElement(compiler, name); |
235 MapTypeMask mask = typesInferrer.getTypeOfElement(element); | 235 MapTypeMask mask = typesInferrer.getTypeOfElement(element); |
236 Expect.equals(keyType, simplify(mask.keyType, compiler), name); | 236 Expect.equals(keyType, simplify(mask.keyType, compiler), name); |
237 Expect.equals(valueType, simplify(mask.valueType, compiler), name); | 237 Expect.equals(valueType, simplify(mask.valueType, compiler), name); |
238 } | 238 } |
239 | 239 |
240 K(TypeMask other) => | 240 K(TypeMask other) => |
241 simplify(keyType.union(other, classWorld), compiler); | 241 simplify(keyType.union(other, closedWorld), compiler); |
242 V(TypeMask other) => | 242 V(TypeMask other) => |
243 simplify(valueType.union(other, classWorld), compiler).nullable(); | 243 simplify(valueType.union(other, closedWorld), compiler).nullable(); |
244 | 244 |
245 checkType('mapInField', K(aKeyType), V(commonMasks.numType)); | 245 checkType('mapInField', K(aKeyType), V(commonMasks.numType)); |
246 checkType('mapPassedToMethod', K(aKeyType), V(commonMasks.numType)); | 246 checkType('mapPassedToMethod', K(aKeyType), V(commonMasks.numType)); |
247 checkType('mapReturnedFromMethod', K(aKeyType), V(commonMasks.numType)); | 247 checkType('mapReturnedFromMethod', K(aKeyType), V(commonMasks.numType)); |
248 checkType('mapUsedWithCascade', K(aKeyType), V(commonMasks.numType)); | 248 checkType('mapUsedWithCascade', K(aKeyType), V(commonMasks.numType)); |
249 checkType('mapUsedInClosure', K(aKeyType), V(commonMasks.numType)); | 249 checkType('mapUsedInClosure', K(aKeyType), V(commonMasks.numType)); |
250 checkType('mapPassedToSelector', K(aKeyType), V(commonMasks.numType)); | 250 checkType('mapPassedToSelector', K(aKeyType), V(commonMasks.numType)); |
251 checkType( | 251 checkType( |
252 'mapReturnedFromSelector', K(aKeyType), V(commonMasks.numType)); | 252 'mapReturnedFromSelector', K(aKeyType), V(commonMasks.numType)); |
253 checkType( | 253 checkType( |
(...skipping 23 matching lines...) Expand all Loading... |
277 checkType('mapStoredInListButEscapes', K(commonMasks.dynamicType), | 277 checkType('mapStoredInListButEscapes', K(commonMasks.dynamicType), |
278 V(commonMasks.dynamicType)); | 278 V(commonMasks.dynamicType)); |
279 checkType('mapStoredInMap', K(aKeyType), V(commonMasks.uint31Type)); | 279 checkType('mapStoredInMap', K(aKeyType), V(commonMasks.uint31Type)); |
280 checkType('mapStoredInMapButEscapes', K(commonMasks.dynamicType), | 280 checkType('mapStoredInMapButEscapes', K(commonMasks.dynamicType), |
281 V(commonMasks.dynamicType)); | 281 V(commonMasks.dynamicType)); |
282 | 282 |
283 checkType('mapUnset', K(emptyType), V(emptyType)); | 283 checkType('mapUnset', K(emptyType), V(emptyType)); |
284 checkType('mapOnlySetWithConstraint', K(aKeyType), V(emptyType)); | 284 checkType('mapOnlySetWithConstraint', K(aKeyType), V(emptyType)); |
285 })); | 285 })); |
286 } | 286 } |
OLD | NEW |