mirror of
https://github.com/dart-lang/sdk
synced 2024-07-20 18:05:01 +00:00
Issue 52197. Remove null assert from getEnumElementValue()
I see a crash like this from external users. Bug: https://github.com/dart-lang/sdk/issues/52197 Change-Id: I5b18552ae1db50c7a103ee6b04f36d0ade8c6f5d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299180 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
parent
d838d1a08a
commit
0f4275a443
|
@ -17,7 +17,7 @@ abstract class EnumOperations<Type extends Object, EnumClass extends Object,
|
|||
/// Returns the value defined by the [enumElement]. The encoding is specific
|
||||
/// the implementation of this interface but must ensure constant value
|
||||
/// identity.
|
||||
EnumElementValue getEnumElementValue(EnumElement enumElement);
|
||||
EnumElementValue? getEnumElementValue(EnumElement enumElement);
|
||||
|
||||
/// Returns the declared name of the [enumElement].
|
||||
String getEnumElementName(EnumElement enumElement);
|
||||
|
@ -57,14 +57,16 @@ class EnumInfo<Type extends Object, EnumClass extends Object,
|
|||
Map<EnumElementValue, EnumElementStaticType<Type, EnumElement>> elements =
|
||||
{};
|
||||
for (EnumElement element in _enumOperations.getEnumElements(_enumClass)) {
|
||||
EnumElementValue value = _enumOperations.getEnumElementValue(element);
|
||||
elements[value] = new EnumElementStaticType<Type, EnumElement>(
|
||||
_typeOperations,
|
||||
_fieldLookup,
|
||||
_enumOperations.getEnumElementType(element),
|
||||
new IdentityRestriction<EnumElement>(element),
|
||||
_enumOperations.getEnumElementName(element),
|
||||
element);
|
||||
EnumElementValue? value = _enumOperations.getEnumElementValue(element);
|
||||
if (value != null) {
|
||||
elements[value] = new EnumElementStaticType<Type, EnumElement>(
|
||||
_typeOperations,
|
||||
_fieldLookup,
|
||||
_enumOperations.getEnumElementType(element),
|
||||
new IdentityRestriction<EnumElement>(element),
|
||||
_enumOperations.getEnumElementName(element),
|
||||
element);
|
||||
}
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
|
|
@ -56,8 +56,8 @@ class AnalyzerEnumOperations
|
|||
}
|
||||
|
||||
@override
|
||||
DartObject getEnumElementValue(FieldElement enumField) {
|
||||
return enumField.computeConstantValue()!;
|
||||
DartObject? getEnumElementValue(FieldElement enumField) {
|
||||
return enumField.computeConstantValue();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -239,6 +239,26 @@ void f(E x) {
|
|||
);
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_enum_cannotCompute() async {
|
||||
await assertErrorsInCode(r'''
|
||||
enum E {
|
||||
v1(v2), v2(v1);
|
||||
const E(Object f);
|
||||
}
|
||||
|
||||
void f(E x) {
|
||||
switch (x) {
|
||||
case E.v1:
|
||||
case E.v2:
|
||||
break;
|
||||
}
|
||||
}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, 11, 2),
|
||||
error(CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, 19, 2),
|
||||
]);
|
||||
}
|
||||
|
||||
test_alwaysExhaustive_Null_hasError() async {
|
||||
await assertErrorsInCode(r'''
|
||||
void f(Null x) {
|
||||
|
|
Loading…
Reference in a new issue