1
0
mirror of https://github.com/mgechev/revive.git synced 2025-02-09 13:37:14 +02:00
This commit is contained in:
chavacava 2024-08-21 10:38:34 +02:00 committed by GitHub
parent 251470be6a
commit 6a139caf92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View File

@ -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()

17
testdata/defer.go vendored
View File

@ -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
})()
}