Skip to content

Commit 329c593

Browse files
committed
staticcheck: replace an unnecessary use of PathEnclosingInterval
(cherry picked from commit cc39862)
1 parent 26cf12e commit 329c593

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

staticcheck/lint.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5066,7 +5066,9 @@ var allocationNilCheckQ = pattern.MustParse(`(IfStmt _ cond@(BinaryExpr lhs op@(
50665066

50675067
func CheckAllocationNilCheck(pass *analysis.Pass) (interface{}, error) {
50685068
irpkg := pass.ResultOf[buildir.Analyzer].(*buildir.IR).Pkg
5069-
fn := func(node ast.Node) {
5069+
5070+
var path []ast.Node
5071+
fn := func(node ast.Node, stack []ast.Node) {
50705072
m, ok := code.Match(pass, allocationNilCheckQ, node)
50715073
if !ok {
50725074
return
@@ -5077,10 +5079,9 @@ func CheckAllocationNilCheck(pass *analysis.Pass) (interface{}, error) {
50775079
return
50785080
}
50795081
lhs := m.State["lhs"].(ast.Expr)
5080-
path, exact := astutil.PathEnclosingInterval(code.File(pass, lhs), lhs.Pos(), lhs.Pos())
5081-
if !exact {
5082-
// TODO(dh): when can this happen?
5083-
return
5082+
path = path[:0]
5083+
for i := len(stack) - 1; i >= 0; i-- {
5084+
path = append(path, stack[i])
50845085
}
50855086
irfn := ir.EnclosingFunction(irpkg, path)
50865087
v, isAddr := irfn.ValueForExpr(lhs)
@@ -5178,8 +5179,7 @@ func CheckAllocationNilCheck(pass *analysis.Pass) (interface{}, error) {
51785179
report.Report(pass, cond, fallback)
51795180
}
51805181
}
5181-
51825182
}
5183-
code.Preorder(pass, fn, (*ast.IfStmt)(nil))
5183+
code.PreorderStack(pass, fn, (*ast.IfStmt)(nil))
51845184
return nil, nil
51855185
}

0 commit comments

Comments
 (0)