Skip to content

Commit b345e26

Browse files
committed
staticcheck: don't panic if we can't find an IR function for an AST node
Closes gh-1268 (cherry picked from commit bda615d)
1 parent 7ef9e7d commit b345e26

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

staticcheck/lint.go

+8
Original file line numberDiff line numberDiff line change
@@ -4939,6 +4939,10 @@ func CheckTypeAssertionShadowingElse(pass *analysis.Pass) (interface{}, error) {
49394939
return
49404940
}
49414941
irfn := ir.EnclosingFunction(irpkg, path)
4942+
if irfn == nil {
4943+
// For example for functions named "_", because we don't generate IR for them.
4944+
return
4945+
}
49424946

49434947
shadoweeIR, isAddr := irfn.ValueForExpr(m.State["obj"].(*ast.Ident))
49444948
if shadoweeIR == nil || isAddr {
@@ -5088,6 +5092,10 @@ func CheckAllocationNilCheck(pass *analysis.Pass) (interface{}, error) {
50885092
path = append(path, stack[i])
50895093
}
50905094
irfn := ir.EnclosingFunction(irpkg, path)
5095+
if irfn == nil {
5096+
// For example for functions named "_", because we don't generate IR for them.
5097+
return
5098+
}
50915099
v, isAddr := irfn.ValueForExpr(lhs)
50925100
if isAddr {
50935101
return

0 commit comments

Comments
 (0)