Skip to content

Commit

Permalink
staticcheck: don't panic if we can't find an IR function for an AST node
Browse files Browse the repository at this point in the history
Closes gh-1268

(cherry picked from commit bda615d)
  • Loading branch information
dominikh committed May 16, 2022
1 parent 7ef9e7d commit b345e26
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions staticcheck/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4939,6 +4939,10 @@ func CheckTypeAssertionShadowingElse(pass *analysis.Pass) (interface{}, error) {
return
}
irfn := ir.EnclosingFunction(irpkg, path)
if irfn == nil {
// For example for functions named "_", because we don't generate IR for them.
return
}

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

0 comments on commit b345e26

Please sign in to comment.