Skip to content

Commit

Permalink
[dart2js] Handle null as a switch statement case value.
Browse files Browse the repository at this point in the history
Bug: 51527
Change-Id: I6203c9aa668689bb44800082864174b9fb215289
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310500
Reviewed-by: Nicholas Shahan <[email protected]>
Commit-Queue: Stephen Adams <[email protected]>
  • Loading branch information
rakudrama authored and Commit Queue committed Jun 22, 2023
1 parent a282120 commit 5a59512
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/compiler/lib/src/ssa/codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -817,9 +817,18 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
// omit the code for it.
if (successor.isLive) {
do {
visit(inputs[inputIndex]);
final input = inputs[inputIndex];
visit(input);
currentContainer = js.Block.empty();
cases.add(js.Case(pop(), currentContainer));
if (input is HConstant && input.constant is NullConstantValue) {
// JavaScript case expressions match on `===`, which means that the
// just emitted `case null:` will not catch `undefined`.
// Add `case void 0:` to catch `undefined`.
currentContainer = js.Block.empty();
cases.add(
js.Case(js.Prefix('void', js.number(0)), currentContainer));
}
inputIndex++;
} while ((successors[inputIndex - 1] == successor) &&
(inputIndex < inputs.length));
Expand Down

0 comments on commit 5a59512

Please sign in to comment.