Skip to content

Commit 0eb6ca4

Browse files
committed
Add location for implicitly declared variables
1 parent 86af912 commit 0eb6ca4

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

go/ql/lib/semmle/go/Scopes.qll

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,22 @@ class Entity extends @object {
148148
string filepath, int startline, int startcolumn, int endline, int endcolumn
149149
) {
150150
// take the location of the declaration if there is one
151-
this.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
152-
or
153-
// otherwise fall back on dummy location
154-
not exists(this.getDeclaration()) and
155-
filepath = "" and
156-
startline = 0 and
157-
startcolumn = 0 and
158-
endline = 0 and
159-
endcolumn = 0
151+
if exists(this.getDeclaration())
152+
then this.getDeclaration().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
153+
else
154+
// take the location of the implicit declaration if there is one
155+
if this = any(CaseClause cc).getImplicitlyDeclaredVariable()
156+
then
157+
any(CaseClause cc | this = cc.getImplicitlyDeclaredVariable())
158+
.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
159+
else (
160+
// otherwise fall back on dummy location
161+
filepath = "" and
162+
startline = 0 and
163+
startcolumn = 0 and
164+
endline = 0 and
165+
endcolumn = 0
166+
)
160167
}
161168
}
162169

0 commit comments

Comments
 (0)