Index: tests/compiler/dart2js/map_tracer_test.dart |
diff --git a/tests/compiler/dart2js/map_tracer_test.dart b/tests/compiler/dart2js/map_tracer_test.dart |
index 1f313dada2985ffcd12082a17d5c582fee93f834..1f8e806c1bc591cc19e1614e9a72a666c03d8ce8 100644 |
--- a/tests/compiler/dart2js/map_tracer_test.dart |
+++ b/tests/compiler/dart2js/map_tracer_test.dart |
@@ -4,13 +4,11 @@ |
import 'package:expect/expect.dart'; |
import "package:async_helper/async_helper.dart"; |
-import 'package:compiler/src/types/types.dart' |
- show MapTypeMask, TypeMask; |
+import 'package:compiler/src/types/types.dart' show MapTypeMask, TypeMask; |
import 'compiler_helper.dart'; |
import 'type_mask_test_helper.dart'; |
- |
String generateTest(String mapAllocation) { |
return """ |
int anInt = 42; |
@@ -209,77 +207,80 @@ void main() { |
doTest('{aDouble : anInt}', "aDouble", "anInt"); |
} |
-void doTest(String allocation, [String keyElement, |
- String valueElement]) { |
+void doTest(String allocation, [String keyElement, String valueElement]) { |
Uri uri = new Uri(scheme: 'source'); |
var compiler = compilerFor(generateTest(allocation), uri, |
expectedErrors: 0, expectedWarnings: 1); |
var classWorld = compiler.world; |
asyncTest(() => compiler.run(uri).then((_) { |
- var keyType, valueType; |
- var commonMasks = compiler.commonMasks; |
- var typesInferrer = compiler.globalInference.typesInferrer; |
- var emptyType = new TypeMask.nonNullEmpty(); |
- var aKeyType = |
- typesInferrer.getTypeOfElement(findElement(compiler, 'aKey')); |
- if (keyElement != null) { |
- keyType = |
- typesInferrer.getTypeOfElement(findElement(compiler, keyElement)); |
- } |
- if (valueElement != null) { |
- valueType = |
- typesInferrer.getTypeOfElement(findElement(compiler, valueElement)); |
- } |
- if (keyType == null) keyType = emptyType; |
- if (valueType == null) valueType = emptyType; |
- |
- checkType(String name, keyType, valueType) { |
- var element = findElement(compiler, name); |
- MapTypeMask mask = typesInferrer.getTypeOfElement(element); |
- Expect.equals(keyType, simplify(mask.keyType, compiler), name); |
- Expect.equals(valueType, simplify(mask.valueType, compiler), name); |
- } |
- |
- K(TypeMask other) => simplify(keyType.union(other, classWorld), compiler); |
- V(TypeMask other) => |
- simplify(valueType.union(other, classWorld), compiler).nullable(); |
- |
- checkType('mapInField', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapPassedToMethod', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapReturnedFromMethod', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapUsedWithCascade', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapUsedInClosure', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapPassedToSelector', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapReturnedFromSelector', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapUsedWithConstraint', K(aKeyType), V(commonMasks.uint31Type)); |
- checkType('mapEscapingFromSetter', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapUsedInLocal', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapEscapingInSetterValue', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapEscapingInIndex', K(aKeyType), V(commonMasks.numType)); |
- checkType('mapEscapingInIndexSet', K(aKeyType), V(commonMasks.uint31Type)); |
- checkType('mapEscapingTwiceInIndexSet', |
- K(aKeyType), V(commonMasks.numType)); |
- checkType('mapSetInNonFinalField', K(aKeyType), V(commonMasks.numType)); |
- |
- checkType('mapPassedToClosure', K(commonMasks.dynamicType), |
- V(commonMasks.dynamicType)); |
- checkType('mapReturnedFromClosure', K(commonMasks.dynamicType), |
- V(commonMasks.dynamicType)); |
- checkType('mapUsedWithNonOkSelector', K(commonMasks.dynamicType), |
- V(commonMasks.dynamicType)); |
- checkType('mapPassedAsOptionalParameter', K(aKeyType), |
- V(commonMasks.numType)); |
- checkType('mapPassedAsNamedParameter', K(aKeyType), |
- V(commonMasks.numType)); |
- checkType('mapStoredInList', K(aKeyType), |
- V(commonMasks.uint31Type)); |
- checkType('mapStoredInListButEscapes', K(commonMasks.dynamicType), |
- V(commonMasks.dynamicType)); |
- checkType('mapStoredInMap', K(aKeyType), V(commonMasks.uint31Type)); |
- checkType('mapStoredInMapButEscapes', K(commonMasks.dynamicType), |
- V(commonMasks.dynamicType)); |
- |
- checkType('mapUnset', K(emptyType), V(emptyType)); |
- checkType('mapOnlySetWithConstraint', K(aKeyType), V(emptyType)); |
- })); |
+ var keyType, valueType; |
+ var commonMasks = compiler.commonMasks; |
+ var typesInferrer = compiler.globalInference.typesInferrer; |
+ var emptyType = new TypeMask.nonNullEmpty(); |
+ var aKeyType = |
+ typesInferrer.getTypeOfElement(findElement(compiler, 'aKey')); |
+ if (keyElement != null) { |
+ keyType = |
+ typesInferrer.getTypeOfElement(findElement(compiler, keyElement)); |
+ } |
+ if (valueElement != null) { |
+ valueType = typesInferrer |
+ .getTypeOfElement(findElement(compiler, valueElement)); |
+ } |
+ if (keyType == null) keyType = emptyType; |
+ if (valueType == null) valueType = emptyType; |
+ |
+ checkType(String name, keyType, valueType) { |
+ var element = findElement(compiler, name); |
+ MapTypeMask mask = typesInferrer.getTypeOfElement(element); |
+ Expect.equals(keyType, simplify(mask.keyType, compiler), name); |
+ Expect.equals(valueType, simplify(mask.valueType, compiler), name); |
+ } |
+ |
+ K(TypeMask other) => |
+ simplify(keyType.union(other, classWorld), compiler); |
+ V(TypeMask other) => |
+ simplify(valueType.union(other, classWorld), compiler).nullable(); |
+ |
+ checkType('mapInField', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapPassedToMethod', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapReturnedFromMethod', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapUsedWithCascade', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapUsedInClosure', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapPassedToSelector', K(aKeyType), V(commonMasks.numType)); |
+ checkType( |
+ 'mapReturnedFromSelector', K(aKeyType), V(commonMasks.numType)); |
+ checkType( |
+ 'mapUsedWithConstraint', K(aKeyType), V(commonMasks.uint31Type)); |
+ checkType('mapEscapingFromSetter', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapUsedInLocal', K(aKeyType), V(commonMasks.numType)); |
+ checkType( |
+ 'mapEscapingInSetterValue', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapEscapingInIndex', K(aKeyType), V(commonMasks.numType)); |
+ checkType( |
+ 'mapEscapingInIndexSet', K(aKeyType), V(commonMasks.uint31Type)); |
+ checkType( |
+ 'mapEscapingTwiceInIndexSet', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapSetInNonFinalField', K(aKeyType), V(commonMasks.numType)); |
+ |
+ checkType('mapPassedToClosure', K(commonMasks.dynamicType), |
+ V(commonMasks.dynamicType)); |
+ checkType('mapReturnedFromClosure', K(commonMasks.dynamicType), |
+ V(commonMasks.dynamicType)); |
+ checkType('mapUsedWithNonOkSelector', K(commonMasks.dynamicType), |
+ V(commonMasks.dynamicType)); |
+ checkType('mapPassedAsOptionalParameter', K(aKeyType), |
+ V(commonMasks.numType)); |
+ checkType( |
+ 'mapPassedAsNamedParameter', K(aKeyType), V(commonMasks.numType)); |
+ checkType('mapStoredInList', K(aKeyType), V(commonMasks.uint31Type)); |
+ checkType('mapStoredInListButEscapes', K(commonMasks.dynamicType), |
+ V(commonMasks.dynamicType)); |
+ checkType('mapStoredInMap', K(aKeyType), V(commonMasks.uint31Type)); |
+ checkType('mapStoredInMapButEscapes', K(commonMasks.dynamicType), |
+ V(commonMasks.dynamicType)); |
+ |
+ checkType('mapUnset', K(emptyType), V(emptyType)); |
+ checkType('mapOnlySetWithConstraint', K(aKeyType), V(emptyType)); |
+ })); |
} |