Restrict var statements to the top of functions

This commit is contained in:
Nigel Tao committed 2018-12-27 11:19:22 +11:00
1 parent 84f9d3a915
commit cbe19f50e0
5 files changed
+36 -56

No files matched your search

+5 -10
View File
@@ -150,17 +150,12 @@ func (g *gen) findVars() error {
}
f := g.currFunk.astFunc
if err := f.AsNode().Walk(func(n *a.Node) error {
if n.Kind() == a.KVar {
name := n.AsVar().Name()
if _, ok := h.vars[name]; !ok {
g.currFunk.varList = append(g.currFunk.varList, n.AsVar())
h.vars[name] = len(h.vars)
}
for _, n := range f.Body() {
if n.Kind() != a.KVar {
break
}
return nil
}); err != nil {
return err
g.currFunk.varList = append(g.currFunk.varList, n.AsVar())
h.vars[n.AsVar().Name()] = len(h.vars)
}
if f.Effect().Coroutine() {