Support procedural (nil return) functions
This commit is contained in:
parent
6298880b06
commit
a065a68449
|
@ -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:
|
||||
|
|
|
@ -4,6 +4,10 @@ func DoConfusingStuff() (x int, y string) {
|
|||
return
|
||||
}
|
||||
|
||||
func DoProceduralStuff() {
|
||||
return
|
||||
}
|
||||
|
||||
func DoSensibleStuff() (x int, y string) {
|
||||
return x, y
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue