@@ -306,6 +306,19 @@ newtype TControlFlowNode =
306306 * the `i`th expression of a case clause `cc`.
307307 */
308308 MkCaseCheckNode ( CaseClause cc , int i ) { exists ( cc .getExpr ( i ) ) } or
309+ /**
310+ * A control-flow node that represents the implicit declaration of the
311+ * variable `lv` in case clause `cc` and its assignment of the value
312+ * `switchExpr` from the guard. This only occurs in case clauses in a type
313+ * switch statement which declares a variable in its guard.
314+ */
315+ MkTypeSwitchImplicitVariable ( CaseClause cc , LocalVariable lv , Expr switchExpr ) {
316+ exists ( TypeSwitchStmt ts , DefineStmt ds | ds = ts .getAssign ( ) |
317+ cc = ts .getACase ( ) and
318+ lv = cc .getImplicitlyDeclaredVariable ( ) and
319+ switchExpr = ds .getRhs ( ) .( TypeAssertExpr ) .getExpr ( )
320+ )
321+ } or
309322 /**
310323 * A control-flow node that represents the implicit lower bound of a slice expression.
311324 */
@@ -1099,6 +1112,10 @@ module CFG {
10991112 first = this .getExprStart ( 0 )
11001113 or
11011114 not exists ( this .getAnExpr ( ) ) and
1115+ first = MkTypeSwitchImplicitVariable ( this , _, _)
1116+ or
1117+ not exists ( this .getAnExpr ( ) ) and
1118+ not exists ( MkTypeSwitchImplicitVariable ( this , _, _) ) and
11021119 first = this .getBodyStart ( )
11031120 }
11041121
@@ -1119,6 +1136,9 @@ module CFG {
11191136 override predicate succ0 ( ControlFlow:: Node pred , ControlFlow:: Node succ ) {
11201137 ControlFlowTree .super .succ0 ( pred , succ )
11211138 or
1139+ pred = MkTypeSwitchImplicitVariable ( this , _, _) and
1140+ succ = this .getBodyStart ( )
1141+ or
11221142 exists ( int i |
11231143 lastNode ( this .getExpr ( i ) , pred , normalCompletion ( ) ) and
11241144 succ = MkCaseCheckNode ( this , i )
@@ -1137,8 +1157,13 @@ module CFG {
11371157
11381158 predicate isPassingEdge ( int i , ControlFlow:: Node pred , ControlFlow:: Node succ , Expr testExpr ) {
11391159 pred = this .getExprEnd ( i , true ) and
1140- succ = this .getBodyStart ( ) and
1141- testExpr = this .getExpr ( i )
1160+ testExpr = this .getExpr ( i ) and
1161+ (
1162+ succ = MkTypeSwitchImplicitVariable ( this , _, _)
1163+ or
1164+ not exists ( MkTypeSwitchImplicitVariable ( this , _, _) ) and
1165+ succ = this .getBodyStart ( )
1166+ )
11421167 }
11431168
11441169 override ControlFlowTree getChildTree ( int i ) { result = this .getStmt ( i ) }
0 commit comments