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) {
|
inspector.Preorder(nodeFilter, func(node ast.Node) {
|
||||||
var funcBody *ast.BlockStmt
|
var funcBody *ast.BlockStmt
|
||||||
|
|
||||||
switch n := node.(type) {
|
switch function := node.(type) {
|
||||||
case *ast.FuncLit:
|
case *ast.FuncLit:
|
||||||
funcBody = n.Body
|
funcBody = function.Body
|
||||||
for _, statement := range funcBody.List {
|
for _, statement := range funcBody.List {
|
||||||
s, ok := statement.(*ast.ReturnStmt)
|
returnStmt, ok := statement.(*ast.ReturnStmt)
|
||||||
if ok && s.Results == nil {
|
if ok && returnStmt.Results == nil && function.Type.Results != nil {
|
||||||
pass.Reportf(s.Pos(), "implicit return found for anonymous function")
|
pass.Reportf(returnStmt.Pos(), "implicit return found for anonymous function")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *ast.FuncDecl:
|
case *ast.FuncDecl:
|
||||||
funcBody = n.Body
|
funcBody = function.Body
|
||||||
for _, statement := range funcBody.List {
|
for _, statement := range funcBody.List {
|
||||||
s, ok := statement.(*ast.ReturnStmt)
|
returnStmt, ok := statement.(*ast.ReturnStmt)
|
||||||
if ok && s.Results == nil {
|
if ok && returnStmt.Results == nil && function.Type.Results != nil {
|
||||||
pass.Reportf(s.Return, "implicit return found in function %s", n.Name)
|
pass.Reportf(returnStmt.Return, "implicit return found in function %s", function.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -4,6 +4,10 @@ func DoConfusingStuff() (x int, y string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DoProceduralStuff() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func DoSensibleStuff() (x int, y string) {
|
func DoSensibleStuff() (x int, y string) {
|
||||||
return x, y
|
return x, y
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user