Commit ef351ebe authored by Etienne Renault's avatar Etienne Renault
Browse files

Restricted support for closures encountered in RERS

Thanks to A. Martin for this patch

* transform/functiondefs.go: here.
parent 894a07f1
......@@ -29,6 +29,7 @@ func G2PFunction_fibonacci(G2PState G2PStateType) []G2PStateType {
// FunctionDefs visitor type, keeps track of the current function definition.
type FunctionDefs struct {
currentFunction *ast.Object
inFuncLit bool
}
// Pre traversal applies the transformation.
......@@ -63,8 +64,12 @@ func (t *FunctionDefs) Pre(meta *Meta, v *Visitor) bool {
},
},
})
case *ast.FuncLit:
t.inFuncLit = true
return true
case *ast.ReturnStmt:
if len(n.Results) == 0 {
if len(n.Results) == 0 || t.inFuncLit {
// Either the function returns nothing or we used named return values.
return true
}
......@@ -81,6 +86,12 @@ func (t *FunctionDefs) Pre(meta *Meta, v *Visitor) bool {
}
// Post traversal does nothing.
func (FunctionDefs) Post(meta *Meta, v *Visitor) bool {
func (t *FunctionDefs) Post(meta *Meta, v *Visitor) bool {
c := v.Cursor()
switch c.Node().(type) {
case *ast.FuncLit:
t.inFuncLit = false
}
return true
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment