[analyzer] Issue 53793: Resolve enum arguments even if the constant is non-serializable.

The analyzer used to crash when there's a non-serializable constant enum.
The issue was that we would not resolve any of its arguments if we find that it's non-serializable.

This change resolves the enum arguments, regardless.

Fixes https://github.com/dart-lang/sdk/issues/53793

Bug: https://github.com/dart-lang/sdk/issues/53793
Change-Id: I67508a9d76cce385533c963dabf7a20d9559d9ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331747
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Kallen Tu 2023-10-27 19:18:58 +00:00 committed by Commit Queue
parent 0a2141b134
commit 7a248040c8
4 changed files with 29 additions and 13 deletions

View file

@ -202,7 +202,6 @@ enum E {
''', matchFixMessage: "Create constructor 'E'");
}
@FailingTest(reason: 'parameter types should be inferred')
Future<void> test_undefined_enum_constructor_unnamed_parameters() async {
await resolveTestCode('''
enum E {

View file

@ -2424,16 +2424,6 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
parameters: constructorElement.parameters,
errorReporter: errorReporter,
);
for (var argument in argumentList.arguments) {
analyzeExpression(argument, argument.staticParameterElement?.type);
popRewrite();
}
arguments.typeArguments?.accept(this);
var whyNotPromotedList =
<Map<DartType, NonPromotionReason> Function()>[];
checkForArgumentTypesNotAssignableInList(
argumentList, whyNotPromotedList);
} else if (definingLibrary.featureSet
.isEnabled(Feature.enhanced_enums)) {
var requiredParameterCount = constructorElement.parameters
@ -2451,6 +2441,20 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
}
}
var arguments = node.arguments;
if (arguments != null) {
var argumentList = arguments.argumentList;
for (var argument in argumentList.arguments) {
analyzeExpression(argument, argument.staticParameterElement?.type);
popRewrite();
}
arguments.typeArguments?.accept(this);
var whyNotPromotedList = <Map<DartType, NonPromotionReason> Function()>[];
checkForArgumentTypesNotAssignableInList(
argumentList, whyNotPromotedList);
}
elementResolver.visitEnumConstantDeclaration(node);
}

View file

@ -39,6 +39,19 @@ const int x = 'foo';
]);
}
test_enum_argument_methodInvocation() async {
await assertErrorsInCode('''
enum E {
enumValue(["text"].map((x) => x));
const E(this.strings);
final Iterable<String> strings;
}
''', [
error(CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION, 21, 22),
]);
}
/// Enum constants can reference other constants.
test_enum_enhanced_constants() async {
await assertNoErrorsInCode('''

View file

@ -282,7 +282,7 @@ EnumConstantDeclaration
IntegerLiteral
literal: 42
parameter: <null>
staticType: null
staticType: int
rightParenthesis: )
constructorElement: <null>
declaredElement: self::@enum::E::@field::v
@ -310,7 +310,7 @@ EnumConstantDeclaration
IntegerLiteral
literal: 42
parameter: <null>
staticType: null
staticType: int
rightParenthesis: )
constructorElement: <null>
declaredElement: self::@enum::E::@field::v