mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Restrict var statements to the top of functions
This commit is contained in:
1 parent
84f9d3a915
commit
cbe19f50e0
5 files changed
+36
-56
No files matched your search
@@ -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() {
|
||||
|
||||
Reference in new issue
Block a user