diff --git a/analyzer/analyzer.go b/analyzer/analyzer.go index 1596050..7e6650e 100644 --- a/analyzer/analyzer.go +++ b/analyzer/analyzer.go @@ -29,21 +29,21 @@ func run(pass *analysis.Pass) (interface{}, error) { inspector.Preorder(nodeFilter, func(node ast.Node) { var funcBody *ast.BlockStmt - switch n := node.(type) { + switch function := node.(type) { case *ast.FuncLit: - funcBody = n.Body + funcBody = function.Body for _, statement := range funcBody.List { - s, ok := statement.(*ast.ReturnStmt) - if ok && s.Results == nil { - pass.Reportf(s.Pos(), "implicit return found for anonymous function") + returnStmt, ok := statement.(*ast.ReturnStmt) + if ok && returnStmt.Results == nil && function.Type.Results != nil { + pass.Reportf(returnStmt.Pos(), "implicit return found for anonymous function") } } case *ast.FuncDecl: - funcBody = n.Body + funcBody = function.Body for _, statement := range funcBody.List { - s, ok := statement.(*ast.ReturnStmt) - if ok && s.Results == nil { - pass.Reportf(s.Return, "implicit return found in function %s", n.Name) + returnStmt, ok := statement.(*ast.ReturnStmt) + if ok && returnStmt.Results == nil && function.Type.Results != nil { + pass.Reportf(returnStmt.Return, "implicit return found in function %s", function.Name) } } default: diff --git a/example.go b/example.go index 48d4ad5..44560dc 100644 --- a/example.go +++ b/example.go @@ -4,6 +4,10 @@ func DoConfusingStuff() (x int, y string) { return } +func DoProceduralStuff() { + return +} + func DoSensibleStuff() (x int, y string) { return x, y }