Skip to content

Commit

Permalink
fix #1029 (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavacava authored Aug 21, 2024
1 parent 251470b commit 6a139ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rule/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (w lintDeferRule) Visit(node ast.Node) ast.Visitor {
// but it is very likely to be a misunderstanding of defer's behavior around arguments.
w.newFailure("recover must be called inside a deferred function, this is executing recover immediately", n, 1, "logic", "immediate-recover")
}

return nil // no need to analyze the arguments of the function call
case *ast.DeferStmt:
if isIdent(n.Call.Fun, "recover") {
// defer recover()
Expand Down
17 changes: 17 additions & 0 deletions testdata/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,20 @@ func f() {
return nil
})
}

// Issue #1029
func verify2(a any) func() {
return func() {
fn := a.(func() error)
if err := fn(); err != nil {
panic(err)
}
}

}

func mainf() {
defer verify2(func() error { // MATCH /prefer not to defer chains of function calls/
return nil
})()
}

0 comments on commit 6a139ca

Please # to comment.