Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bc2b788

Browse files
askeksacommit-bot@chromium.org
authored andcommitted
[CFE] handle set literals in constant evaluator.
Change-Id: I9dc5f7a3d2e7bc0f53e0370042bc59d688a8c4b3 Reviewed-on: https://dart-review.googlesource.com/c/95021 Commit-Queue: Aske Simon Christensen <[email protected]> Reviewed-by: Kevin Millikin <[email protected]>
1 parent 2b2e717 commit bc2b788

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pkg/kernel/lib/transformations/constants.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,29 @@ class ConstantEvaluator extends RecursiveVisitor {
562562
return canonicalize(new ListConstant(typeArgument, entries));
563563
}
564564

565+
visitSetLiteral(SetLiteral node) {
566+
if (!node.isConst) {
567+
throw new _AbortCurrentEvaluation(
568+
errorReporter.nonConstLiteral(contextChain, node, 'Set'));
569+
}
570+
final List<Constant> entries = new List<Constant>(node.expressions.length);
571+
for (int i = 0; i < node.expressions.length; ++i) {
572+
entries[i] = _evaluateSubexpression(node.expressions[i]);
573+
}
574+
if (hasUnevaluatedChild(node)) {
575+
final expressions = new List<Expression>(node.expressions.length);
576+
for (int i = 0; i < node.expressions.length; ++i) {
577+
expressions[i] = unique(entries[i].asExpression());
578+
}
579+
return unevaluated(
580+
node,
581+
new SetLiteral(expressions,
582+
typeArgument: node.typeArgument, isConst: true));
583+
}
584+
final DartType typeArgument = evaluateDartType(node, node.typeArgument);
585+
return canonicalize(new SetConstant(typeArgument, entries));
586+
}
587+
565588
visitMapLiteral(MapLiteral node) {
566589
if (!node.isConst) {
567590
throw new _AbortCurrentEvaluation(

0 commit comments

Comments
 (0)