From 25f686858b10443c4a69ac9197b93fd9c72e8217 Mon Sep 17 00:00:00 2001 From: chavacava Date: Wed, 21 Aug 2024 09:05:56 +0200 Subject: [PATCH] fix #1029 --- rule/defer.go | 2 +- testdata/defer.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/rule/defer.go b/rule/defer.go index adc6478ae..9a1972274 100644 --- a/rule/defer.go +++ b/rule/defer.go @@ -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() diff --git a/testdata/defer.go b/testdata/defer.go index a035cfe08..2cb4f5736 100644 --- a/testdata/defer.go +++ b/testdata/defer.go @@ -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 + })() +}