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/ + }() +}