Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 1dc427a

Browse files
committed
Cleanup: use TypeSwitchStmt.getAssign, not a raw child accessor
1 parent d8374ad commit 1dc427a

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

ql/src/semmle/go/Stmt.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,9 @@ class TypeSwitchStmt extends @typeswitchstmt, SwitchStmt {
882882
/** Gets the assign statement of this type-switch statement. */
883883
SimpleAssignStmt getAssign() { result = getChildStmt(1) }
884884

885+
/** Gets the test statement of this type-switch statement. This is a `SimpleAssignStmt` or `ExprStmt`. */
886+
Stmt getTest() { result = getChildStmt(1) }
887+
885888
/** Gets the expression whose type is examined by this `switch` statement. */
886889
Expr getExpr() { result = getAssign().getRhs() or result = getChildStmt(1).(ExprStmt).getExpr() }
887890

ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ module CFG {
17611761
or
17621762
first = MkImplicitTrue(this)
17631763
or
1764-
firstNode(this.(TypeSwitchStmt).getChildStmt(1), first)
1764+
firstNode(this.(TypeSwitchStmt).getTest(), first)
17651765
)
17661766
}
17671767

@@ -1775,7 +1775,7 @@ module CFG {
17751775
last = MkImplicitTrue(this) and
17761776
cmpl = Bool(true)
17771777
or
1778-
lastNode(this.(TypeSwitchStmt).getChildStmt(1), last, cmpl)
1778+
lastNode(this.(TypeSwitchStmt).getTest(), last, cmpl)
17791779
) and
17801780
(
17811781
not cmpl.isNormal()
@@ -1811,13 +1811,13 @@ module CFG {
18111811
(
18121812
firstNode(this.(ExpressionSwitchStmt).getExpr(), succ) or
18131813
succ = MkImplicitTrue(this) or
1814-
firstNode(this.(TypeSwitchStmt).getChildStmt(1), succ)
1814+
firstNode(this.(TypeSwitchStmt).getTest(), succ)
18151815
)
18161816
or
18171817
(
18181818
lastNode(this.(ExpressionSwitchStmt).getExpr(), pred, normalCompletion()) or
18191819
pred = MkImplicitTrue(this) or
1820-
lastNode(this.(TypeSwitchStmt).getChildStmt(1), pred, normalCompletion())
1820+
lastNode(this.(TypeSwitchStmt).getTest(), pred, normalCompletion())
18211821
) and
18221822
(
18231823
firstNode(getNonDefaultCase(0), succ)

0 commit comments

Comments
 (0)