| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 compiler.closeResolution(); | 214 compiler.closeResolution(); |
| 215 var closedWorld = compiler.closedWorld; | |
| 216 asyncTest(() => compiler.run(uri).then((_) { | 215 asyncTest(() => compiler.run(uri).then((_) { |
| 217 var keyType, valueType; | 216 var keyType, valueType; |
| 218 var commonMasks = compiler.closedWorld.commonMasks; | |
| 219 var typesInferrer = compiler.globalInference.typesInferrerInternal; | 217 var typesInferrer = compiler.globalInference.typesInferrerInternal; |
| 218 var closedWorld = typesInferrer.closedWorld; |
| 219 var commonMasks = closedWorld.commonMasks; |
| 220 var emptyType = new TypeMask.nonNullEmpty(); | 220 var emptyType = new TypeMask.nonNullEmpty(); |
| 221 var aKeyType = | 221 var aKeyType = |
| 222 typesInferrer.getTypeOfElement(findElement(compiler, 'aKey')); | 222 typesInferrer.getTypeOfElement(findElement(compiler, 'aKey')); |
| 223 if (keyElement != null) { | 223 if (keyElement != null) { |
| 224 keyType = | 224 keyType = |
| 225 typesInferrer.getTypeOfElement(findElement(compiler, keyElement)); | 225 typesInferrer.getTypeOfElement(findElement(compiler, keyElement)); |
| 226 } | 226 } |
| 227 if (valueElement != null) { | 227 if (valueElement != null) { |
| 228 valueType = typesInferrer | 228 valueType = typesInferrer |
| 229 .getTypeOfElement(findElement(compiler, valueElement)); | 229 .getTypeOfElement(findElement(compiler, valueElement)); |
| 230 } | 230 } |
| 231 if (keyType == null) keyType = emptyType; | 231 if (keyType == null) keyType = emptyType; |
| 232 if (valueType == null) valueType = emptyType; | 232 if (valueType == null) valueType = emptyType; |
| 233 | 233 |
| 234 checkType(String name, keyType, valueType) { | 234 checkType(String name, keyType, valueType) { |
| 235 var element = findElement(compiler, name); | 235 var element = findElement(compiler, name); |
| 236 MapTypeMask mask = typesInferrer.getTypeOfElement(element); | 236 MapTypeMask mask = typesInferrer.getTypeOfElement(element); |
| 237 Expect.equals(keyType, simplify(mask.keyType, compiler), name); | 237 Expect.equals(keyType, simplify(mask.keyType, closedWorld), name); |
| 238 Expect.equals(valueType, simplify(mask.valueType, compiler), name); | 238 Expect.equals(valueType, simplify(mask.valueType, closedWorld), name); |
| 239 } | 239 } |
| 240 | 240 |
| 241 K(TypeMask other) => | 241 K(TypeMask other) => |
| 242 simplify(keyType.union(other, closedWorld), compiler); | 242 simplify(keyType.union(other, closedWorld), closedWorld); |
| 243 V(TypeMask other) => | 243 V(TypeMask other) => |
| 244 simplify(valueType.union(other, closedWorld), compiler).nullable(); | 244 simplify(valueType.union(other, closedWorld), closedWorld) |
| 245 .nullable(); |
| 245 | 246 |
| 246 checkType('mapInField', K(aKeyType), V(commonMasks.numType)); | 247 checkType('mapInField', K(aKeyType), V(commonMasks.numType)); |
| 247 checkType('mapPassedToMethod', K(aKeyType), V(commonMasks.numType)); | 248 checkType('mapPassedToMethod', K(aKeyType), V(commonMasks.numType)); |
| 248 checkType('mapReturnedFromMethod', K(aKeyType), V(commonMasks.numType)); | 249 checkType('mapReturnedFromMethod', K(aKeyType), V(commonMasks.numType)); |
| 249 checkType('mapUsedWithCascade', K(aKeyType), V(commonMasks.numType)); | 250 checkType('mapUsedWithCascade', K(aKeyType), V(commonMasks.numType)); |
| 250 checkType('mapUsedInClosure', K(aKeyType), V(commonMasks.numType)); | 251 checkType('mapUsedInClosure', K(aKeyType), V(commonMasks.numType)); |
| 251 checkType('mapPassedToSelector', K(aKeyType), V(commonMasks.numType)); | 252 checkType('mapPassedToSelector', K(aKeyType), V(commonMasks.numType)); |
| 252 checkType( | 253 checkType( |
| 253 'mapReturnedFromSelector', K(aKeyType), V(commonMasks.numType)); | 254 'mapReturnedFromSelector', K(aKeyType), V(commonMasks.numType)); |
| 254 checkType( | 255 checkType( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 278 checkType('mapStoredInListButEscapes', K(commonMasks.dynamicType), | 279 checkType('mapStoredInListButEscapes', K(commonMasks.dynamicType), |
| 279 V(commonMasks.dynamicType)); | 280 V(commonMasks.dynamicType)); |
| 280 checkType('mapStoredInMap', K(aKeyType), V(commonMasks.uint31Type)); | 281 checkType('mapStoredInMap', K(aKeyType), V(commonMasks.uint31Type)); |
| 281 checkType('mapStoredInMapButEscapes', K(commonMasks.dynamicType), | 282 checkType('mapStoredInMapButEscapes', K(commonMasks.dynamicType), |
| 282 V(commonMasks.dynamicType)); | 283 V(commonMasks.dynamicType)); |
| 283 | 284 |
| 284 checkType('mapUnset', K(emptyType), V(emptyType)); | 285 checkType('mapUnset', K(emptyType), V(emptyType)); |
| 285 checkType('mapOnlySetWithConstraint', K(aKeyType), V(emptyType)); | 286 checkType('mapOnlySetWithConstraint', K(aKeyType), V(emptyType)); |
| 286 })); | 287 })); |
| 287 } | 288 } |
| OLD | NEW |