Remove fall-through CFG edge for exhaustive switch statements

This commit is contained in:
Chris Smowton
2023-11-22 20:21:39 +00:00
parent 1047a89613
commit aa5f7352e2
4 changed files with 85 additions and 1 deletions

View File

@@ -936,7 +936,12 @@ private module ControlFlowGraphImpl {
completion = NormalCompletion()
or
// if no default case exists, then normal completion of the expression may terminate the switch
// Note this can't happen if there are pattern cases or a null literal, as
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-14.11.2 requires that such
// an enhanced switch block is exhaustive.
not exists(switch.getDefaultCase()) and
not exists(switch.getAPatternCase()) and
not switch.hasNullCase() and
last(switch.getExpr(), last, completion) and
completion = NormalCompletion()
)