mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
[dart2js] Avoid treatAsRawType for constant collections
dart2js incorrectly canonicalized `const <dynamic>[]` and `const <Object?>[]` to the same const object. The incorrect canonicalization showed up in tests for the Patterns feature. This is not a complete fix for problems with `treatAsRawType`. See http://dartbug.com/51534 for more details. Bug: 49754 Bug: 51534 Change-Id: Ib4bb8529320ed240ab16ae35d4161834dd32b28a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285540 Commit-Queue: Stephen Adams <sra@google.com> Reviewed-by: Mayank Patke <fishythefish@google.com>
This commit is contained in:
parent
89e9f1ea9b
commit
3af33c1ffb
2 changed files with 13 additions and 20 deletions
|
@ -368,27 +368,24 @@ abstract class CommonElements {
|
|||
return _env.createInterfaceType(cls, typeArguments);
|
||||
}
|
||||
|
||||
InterfaceType getConstantListTypeFor(InterfaceType sourceType) =>
|
||||
dartTypes.treatAsRawType(sourceType)
|
||||
? _env.getRawType(jsArrayClass)
|
||||
: _env.createInterfaceType(jsArrayClass, sourceType.typeArguments);
|
||||
InterfaceType getConstantListTypeFor(InterfaceType sourceType) {
|
||||
// TODO(51534): Use CONST_CANONICAL_TYPE(T_i) for arguments.
|
||||
return _env.createInterfaceType(jsArrayClass, sourceType.typeArguments);
|
||||
}
|
||||
|
||||
InterfaceType getConstantMapTypeFor(InterfaceType sourceType,
|
||||
{bool onlyStringKeys = false}) {
|
||||
// TODO(51534): Use CONST_CANONICAL_TYPE(T_i) for arguments.
|
||||
ClassEntity classElement =
|
||||
onlyStringKeys ? constantStringMapClass : generalConstantMapClass;
|
||||
if (dartTypes.treatAsRawType(sourceType)) {
|
||||
return _env.getRawType(classElement);
|
||||
} else {
|
||||
return _env.createInterfaceType(classElement, sourceType.typeArguments);
|
||||
}
|
||||
return _env.createInterfaceType(classElement, sourceType.typeArguments);
|
||||
}
|
||||
|
||||
InterfaceType getConstantSetTypeFor(InterfaceType sourceType) =>
|
||||
dartTypes.treatAsRawType(sourceType)
|
||||
? _env.getRawType(constSetLiteralClass)
|
||||
: _env.createInterfaceType(
|
||||
constSetLiteralClass, sourceType.typeArguments);
|
||||
InterfaceType getConstantSetTypeFor(InterfaceType sourceType) {
|
||||
// TODO(51534): Use CONST_CANONICAL_TYPE(T_i) for arguments.
|
||||
return _env.createInterfaceType(
|
||||
constSetLiteralClass, sourceType.typeArguments);
|
||||
}
|
||||
|
||||
/// Returns the field that holds the internal name in the implementation class
|
||||
/// for `Symbol`.
|
||||
|
|
|
@ -162,12 +162,8 @@ MapConstantValue createMap(
|
|||
key is StringConstantValue &&
|
||||
key.stringValue != JavaScriptMapConstant.PROTO_PROPERTY);
|
||||
|
||||
InterfaceType keysType;
|
||||
if (commonElements.dartTypes.treatAsRawType(sourceType)) {
|
||||
keysType = commonElements.listType();
|
||||
} else {
|
||||
keysType = commonElements.listType(sourceType.typeArguments.first);
|
||||
}
|
||||
InterfaceType keysType =
|
||||
commonElements.listType(sourceType.typeArguments.first);
|
||||
ListConstantValue keysList = createList(commonElements, keysType, keys);
|
||||
InterfaceType type = commonElements.getConstantMapTypeFor(sourceType,
|
||||
onlyStringKeys: onlyStringKeys);
|
||||
|
|
Loading…
Reference in a new issue