From 6a67ee823f36bc4dba902d89e169ae96c0a42bb4 Mon Sep 17 00:00:00 2001 From: Marcin Federowicz Date: Tue, 26 Sep 2023 03:13:39 +0200 Subject: [PATCH] fix: literal calls case --- rule/unconditional-recursion.go | 4 +++- testdata/unconditional-recursion.go | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/rule/unconditional-recursion.go b/rule/unconditional-recursion.go index bad907533..54a7b2150 100644 --- a/rule/unconditional-recursion.go +++ b/rule/unconditional-recursion.go @@ -125,7 +125,9 @@ func (w lintUnconditionalRecursionRule) Visit(node ast.Node) ast.Visitor { } // unconditional loop return w - } + case *ast.FuncLit: + return nil // literal call (closure) is not an issue + } return w } diff --git a/testdata/unconditional-recursion.go b/testdata/unconditional-recursion.go index b6267691a..7a95f93aa 100644 --- a/testdata/unconditional-recursion.go +++ b/testdata/unconditional-recursion.go @@ -187,3 +187,10 @@ func (*fooType) BarFunc() { func (_ *fooType) BazFunc() { BazFunc() } + +// Tests for #902 +func falsePositiveFuncLiteral() { + _ = foo(func() { + falsePositiveFuncLiteral() + }) +}