Skip to content

Commit cc5b77a

Browse files
nshahanCommit Queue
authored andcommitted
[ddc] Handle undefined as null in switch
Add a case for `undefined` whenever a case expression is a null constant. Issue: #51527 Change-Id: I6e9946b588e293bcf0b953d568495c8be95f3749 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310775 Commit-Queue: Nicholas Shahan <[email protected]> Reviewed-by: Stephen Adams <[email protected]>
1 parent f5131f9 commit cc5b77a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4853,6 +4853,10 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
48534853
expressions.isNotEmpty && !node.isDefault ? expressions.last : null;
48544854
for (var e in expressions) {
48554855
var jsExpr = _visitExpression(e);
4856+
if (e is ConstantExpression && e.constant is NullConstant) {
4857+
// Coerce null and undefined by adding an extra case.
4858+
cases.add(js_ast.Case(js_ast.Prefix('void', js.number(0)), emptyBlock));
4859+
}
48564860
cases.add(js_ast.Case(jsExpr, e == lastExpr ? body : emptyBlock));
48574861
}
48584862
if (node.isDefault) {

0 commit comments

Comments
 (0)