Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1029 #1030

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
})()
}
Loading