Skip to content

Commit 6a139ca

Browse files
authored
fix #1029 (#1030)
1 parent 251470b commit 6a139ca

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

rule/defer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (w lintDeferRule) Visit(node ast.Node) ast.Visitor {
111111
// but it is very likely to be a misunderstanding of defer's behavior around arguments.
112112
w.newFailure("recover must be called inside a deferred function, this is executing recover immediately", n, 1, "logic", "immediate-recover")
113113
}
114-
114+
return nil // no need to analyze the arguments of the function call
115115
case *ast.DeferStmt:
116116
if isIdent(n.Call.Fun, "recover") {
117117
// defer recover()

testdata/defer.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,20 @@ func f() {
4747
return nil
4848
})
4949
}
50+
51+
// Issue #1029
52+
func verify2(a any) func() {
53+
return func() {
54+
fn := a.(func() error)
55+
if err := fn(); err != nil {
56+
panic(err)
57+
}
58+
}
59+
60+
}
61+
62+
func mainf() {
63+
defer verify2(func() error { // MATCH /prefer not to defer chains of function calls/
64+
return nil
65+
})()
66+
}

0 commit comments

Comments
 (0)