@@ -152,13 +152,16 @@ class Guard extends ExprParent {
152152 bb2 = cb .getTestSuccessor ( branch )
153153 )
154154 or
155- exists ( SwitchCase sc , ControlFlowNode pred |
155+ exists ( SwitchCase sc |
156156 sc = this and
157+ // Pattern cases are handled as ConditionBlocks above.
158+ not sc instanceof PatternCase and
157159 branch = true and
158160 bb2 .getFirstNode ( ) = sc .getControlFlowNode ( ) and
159- pred = sc .getControlFlowNode ( ) .getAPredecessor ( ) and
160- pred .( Expr ) .getParent * ( ) = sc .getSelectorExpr ( ) and
161- bb1 = pred .getBasicBlock ( )
161+ bb1 = sc .getControlFlowNode ( ) .getAPredecessor ( ) .getBasicBlock ( ) and
162+ // This is either the top of the switch block, or a preceding pattern case
163+ // if one exists.
164+ this .getBasicBlock ( ) = bb1
162165 )
163166 or
164167 preconditionBranchEdge ( this , bb1 , bb2 , branch )
@@ -245,20 +248,20 @@ class TypeTestGuard extends Guard {
245248}
246249
247250private predicate switchCaseControls ( SwitchCase sc , BasicBlock bb ) {
248- exists ( BasicBlock caseblock , Expr selector |
249- selector = sc .getSelectorExpr ( ) and
250- (
251- if sc instanceof PatternCase
252- then caseblock . getANode ( ) = sc .( PatternCase ) . getPattern ( ) . getControlFlowNode ( )
253- else (
254- caseblock . getFirstNode ( ) = sc .getControlFlowNode ( ) and
255- // Check there is no fall-through edge from a previous case:
256- forall ( ControlFlowNode pred | pred = sc . getControlFlowNode ( ) . getAPredecessor ( ) |
257- pred . ( Expr ) . getParent * ( ) = selector
258- )
259- )
260- ) and
261- caseblock . bbDominates ( bb )
251+ exists ( BasicBlock caseblock |
252+ caseblock . getFirstNode ( ) = sc .getControlFlowNode ( ) and
253+ caseblock . bbDominates ( bb ) and
254+ // Check we can't fall through from a previous block:
255+ forall ( ControlFlowNode pred | pred = sc .getControlFlowNode ( ) . getAPredecessor ( ) |
256+ // Branch straight from the switch selector:
257+ pred . ( Expr ) . getParent * ( ) = sc .getSelectorExpr ( )
258+ or
259+ // Branch from a predecessor pattern case (note pattern cases cannot ever fall through)
260+ pred = sc . getSiblingCase ( _ ) . ( PatternCase )
261+ or
262+ // Branch from a predecessor pattern case's guard test, which also can't be a fallthrough edge
263+ pred . ( Expr ) . getParent * ( ) = sc . getSiblingCase ( _ ) . ( PatternCase ) . getGuard ( )
264+ )
262265 )
263266}
264267
0 commit comments