Skip to content

Commit

Permalink
fix: literal and goroutines calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mfederowicz committed Sep 26, 2023
1 parent 70ceb1c commit 6140e99
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions rule/unconditional-recursion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
12 changes: 12 additions & 0 deletions testdata/unconditional-recursion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/
}()
}

0 comments on commit 6140e99

Please sign in to comment.