| 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 | 7 import |
| 8 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' | 8 '../../../sdk/lib/_internal/compiler/implementation/types/types.dart' |
| 9 show MapTypeMask, TypeMask; | 9 show MapTypeMask, TypeMask; |
| 10 | 10 |
| 11 import 'compiler_helper.dart'; | 11 import 'compiler_helper.dart'; |
| 12 import 'parser_helper.dart'; | 12 import 'parser_helper.dart'; |
| 13 import 'type_mask_test_helper.dart'; |
| 13 | 14 |
| 14 | 15 |
| 15 String generateTest(String mapAllocation) { | 16 String generateTest(String mapAllocation) { |
| 16 return """ | 17 return """ |
| 17 int anInt = 42; | 18 int anInt = 42; |
| 18 double aDouble = 42.5; | 19 double aDouble = 42.5; |
| 19 String aKey = 'aKey'; | 20 String aKey = 'aKey'; |
| 20 String anotherKey = 'anotherKey'; | 21 String anotherKey = 'anotherKey'; |
| 21 String presetKey = 'presetKey'; | 22 String presetKey = 'presetKey'; |
| 22 | 23 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 if (valueElement != null) { | 230 if (valueElement != null) { |
| 230 valueType | 231 valueType |
| 231 = typesInferrer.getTypeOfElement(findElement(compiler, valueElement)); | 232 = typesInferrer.getTypeOfElement(findElement(compiler, valueElement)); |
| 232 } | 233 } |
| 233 if (keyType == null) keyType = emptyType; | 234 if (keyType == null) keyType = emptyType; |
| 234 if (valueType == null) valueType = emptyType; | 235 if (valueType == null) valueType = emptyType; |
| 235 | 236 |
| 236 checkType(String name, keyType, valueType) { | 237 checkType(String name, keyType, valueType) { |
| 237 var element = findElement(compiler, name); | 238 var element = findElement(compiler, name); |
| 238 MapTypeMask mask = typesInferrer.getTypeOfElement(element); | 239 MapTypeMask mask = typesInferrer.getTypeOfElement(element); |
| 239 Expect.equals(keyType, mask.keyType.simplify(compiler), name); | 240 Expect.equals(keyType, simplify(mask.keyType, compiler), name); |
| 240 Expect.equals(valueType, mask.valueType.simplify(compiler), name); | 241 Expect.equals(valueType, simplify(mask.valueType, compiler), name); |
| 241 } | 242 } |
| 242 | 243 |
| 243 K(TypeMask other) => keyType.union(other, compiler).simplify(compiler); | 244 K(TypeMask other) => simplify(keyType.union(other, compiler), compiler); |
| 244 V(TypeMask other) => valueType.union(other, compiler).simplify(compiler); | 245 V(TypeMask other) => simplify(valueType.union(other, compiler), compiler); |
| 245 | 246 |
| 246 checkType('mapInField', K(aKeyType), V(typesTask.numType)); | 247 checkType('mapInField', K(aKeyType), V(typesTask.numType)); |
| 247 checkType('mapPassedToMethod', K(aKeyType), V(typesTask.numType)); | 248 checkType('mapPassedToMethod', K(aKeyType), V(typesTask.numType)); |
| 248 checkType('mapReturnedFromMethod', K(aKeyType), V(typesTask.numType)); | 249 checkType('mapReturnedFromMethod', K(aKeyType), V(typesTask.numType)); |
| 249 checkType('mapUsedWithCascade', K(aKeyType), V(typesTask.numType)); | 250 checkType('mapUsedWithCascade', K(aKeyType), V(typesTask.numType)); |
| 250 checkType('mapUsedInClosure', K(aKeyType), V(typesTask.numType)); | 251 checkType('mapUsedInClosure', K(aKeyType), V(typesTask.numType)); |
| 251 checkType('mapPassedToSelector', K(aKeyType), V(typesTask.numType)); | 252 checkType('mapPassedToSelector', K(aKeyType), V(typesTask.numType)); |
| 252 checkType('mapReturnedFromSelector', K(aKeyType), V(typesTask.numType)); | 253 checkType('mapReturnedFromSelector', K(aKeyType), V(typesTask.numType)); |
| 253 checkType('mapUsedWithConstraint', K(aKeyType), V(typesTask.uint31Type)); | 254 checkType('mapUsedWithConstraint', K(aKeyType), V(typesTask.uint31Type)); |
| 254 checkType('mapEscapingFromSetter', K(aKeyType), V(typesTask.numType)); | 255 checkType('mapEscapingFromSetter', K(aKeyType), V(typesTask.numType)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 274 checkType('mapStoredInListButEscapes', K(typesTask.dynamicType), | 275 checkType('mapStoredInListButEscapes', K(typesTask.dynamicType), |
| 275 V(typesTask.dynamicType)); | 276 V(typesTask.dynamicType)); |
| 276 checkType('mapStoredInMap', K(aKeyType), V(typesTask.uint31Type)); | 277 checkType('mapStoredInMap', K(aKeyType), V(typesTask.uint31Type)); |
| 277 checkType('mapStoredInMapButEscapes', K(typesTask.dynamicType), | 278 checkType('mapStoredInMapButEscapes', K(typesTask.dynamicType), |
| 278 V(typesTask.dynamicType)); | 279 V(typesTask.dynamicType)); |
| 279 | 280 |
| 280 checkType('mapUnset', K(emptyType), V(emptyType)); | 281 checkType('mapUnset', K(emptyType), V(emptyType)); |
| 281 checkType('mapOnlySetWithConstraint', K(aKeyType), V(emptyType)); | 282 checkType('mapOnlySetWithConstraint', K(aKeyType), V(emptyType)); |
| 282 })); | 283 })); |
| 283 } | 284 } |
| OLD | NEW |