From 1dc427a2c5b14cc8b59d50003af97d49ba7b117c Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 22 Jun 2020 14:33:38 +0100 Subject: [PATCH] Cleanup: use TypeSwitchStmt.getAssign, not a raw child accessor --- ql/src/semmle/go/Stmt.qll | 3 +++ ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ql/src/semmle/go/Stmt.qll b/ql/src/semmle/go/Stmt.qll index e47b0fedf1c..0bfbbea1eef 100644 --- a/ql/src/semmle/go/Stmt.qll +++ b/ql/src/semmle/go/Stmt.qll @@ -882,6 +882,9 @@ class TypeSwitchStmt extends @typeswitchstmt, SwitchStmt { /** Gets the assign statement of this type-switch statement. */ SimpleAssignStmt getAssign() { result = getChildStmt(1) } + /** Gets the test statement of this type-switch statement. This is a `SimpleAssignStmt` or `ExprStmt`. */ + Stmt getTest() { result = getChildStmt(1) } + /** Gets the expression whose type is examined by this `switch` statement. */ Expr getExpr() { result = getAssign().getRhs() or result = getChildStmt(1).(ExprStmt).getExpr() } diff --git a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll index 2013967c940..82d62210a1d 100644 --- a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll +++ b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll @@ -1761,7 +1761,7 @@ module CFG { or first = MkImplicitTrue(this) or - firstNode(this.(TypeSwitchStmt).getChildStmt(1), first) + firstNode(this.(TypeSwitchStmt).getTest(), first) ) } @@ -1775,7 +1775,7 @@ module CFG { last = MkImplicitTrue(this) and cmpl = Bool(true) or - lastNode(this.(TypeSwitchStmt).getChildStmt(1), last, cmpl) + lastNode(this.(TypeSwitchStmt).getTest(), last, cmpl) ) and ( not cmpl.isNormal() @@ -1811,13 +1811,13 @@ module CFG { ( firstNode(this.(ExpressionSwitchStmt).getExpr(), succ) or succ = MkImplicitTrue(this) or - firstNode(this.(TypeSwitchStmt).getChildStmt(1), succ) + firstNode(this.(TypeSwitchStmt).getTest(), succ) ) or ( lastNode(this.(ExpressionSwitchStmt).getExpr(), pred, normalCompletion()) or pred = MkImplicitTrue(this) or - lastNode(this.(TypeSwitchStmt).getChildStmt(1), pred, normalCompletion()) + lastNode(this.(TypeSwitchStmt).getTest(), pred, normalCompletion()) ) and ( firstNode(getNonDefaultCase(0), succ)