From 6140e998ec0ae3ca1b54df280900184ffc204a17 Mon Sep 17 00:00:00 2001 From: Marcin Federowicz Date: Tue, 26 Sep 2023 03:13:39 +0200 Subject: [PATCH] fix: literal and goroutines calls --- rule/unconditional-recursion.go | 6 +++--- test/utils.go | 3 --- testdata/unconditional-recursion.go | 12 ++++++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/rule/unconditional-recursion.go b/rule/unconditional-recursion.go index bad907533..9e1b42f0c 100644 --- a/rule/unconditional-recursion.go +++ b/rule/unconditional-recursion.go @@ -62,13 +62,11 @@ func (w lintUnconditionalRecursionRule) Visit(node ast.Node) ast.Visitor { var rec *ast.Ident switch { case n.Recv == nil: - rec = nil case n.Recv.NumFields() < 1 || len(n.Recv.List[0].Names) < 1: - rec = &ast.Ident{Name: "_"} + rec = nil default: rec = n.Recv.List[0].Names[0] } - w.currentFunc = &funcStatus{&funcDesc{rec, n.Name}, false} case *ast.CallExpr: var funcID *ast.Ident @@ -125,6 +123,8 @@ 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/test/utils.go b/test/utils.go index 0b3b0bd4d..b1f95c7ab 100644 --- a/test/utils.go +++ b/test/utils.go @@ -86,9 +86,6 @@ func assertFailures(t *testing.T, baseDir string, fi os.FileInfo, src []byte, ru for _, in := range ins { ok := false for i, p := range failures { - if p.Position.Start.Line != in.Line { - continue - } if in.Match == p.Failure { // check replacement if we are expecting one if in.Replacement != "" { diff --git a/testdata/unconditional-recursion.go b/testdata/unconditional-recursion.go index b6267691a..41227d2a9 100644 --- a/testdata/unconditional-recursion.go +++ b/testdata/unconditional-recursion.go @@ -187,3 +187,15 @@ func (*fooType) BarFunc() { func (_ *fooType) BazFunc() { BazFunc() } + +// Tests for #902 +func falsePositiveFuncLiteral() { + _ = foo(func() { + falsePositiveFuncLiteral() + }) +} +func nr902() { + go func() { + nr902() // MATCH /unconditional recursive call/ + }() +}