Allow case null, default to be the first switch case

This is consistent with existing treatment of `case null: default:`
This commit is contained in:
Chris Smowton
2023-11-17 09:22:08 +00:00
parent 0b08507033
commit 6b3080ae92
2 changed files with 4 additions and 0 deletions

View File

@@ -471,6 +471,7 @@ private module ControlFlowGraphImpl {
private SwitchCase getASuccessorSwitchCase(PatternCase pred) {
result.getParent() = pred.getParent() and
result.getIndex() > pred.getIndex() and
// Note we do include `case null, default` (as well as plain old `default`) here.
not result.(ConstCase).getValue(_) instanceof NullLiteral and
(
result.getIndex() <= getNextPatternCase(pred).getIndex()
@@ -492,6 +493,8 @@ private module ControlFlowGraphImpl {
(
result.(ConstCase).getValue(_) instanceof NullLiteral
or
result instanceof NullDefaultCase
or
not exists(getPatternCase(switch, _))
or
result.getIndex() <= getPatternCase(switch, 0).getIndex()