fix: handle out of order type declaration for global var declaration

This commit is contained in:
Marc Vertes
2020-02-03 17:36:04 +01:00
committed by GitHub
parent e434892b9a
commit 92a63dbe09
2 changed files with 18 additions and 1 deletions

12
_test/fun11.go Normal file
View File

@@ -0,0 +1,12 @@
package main
var f F
type F func(int)
func main() {
println("ok")
}
// Output:
// ok

View File

@@ -52,7 +52,7 @@ func (interp *Interpreter) gta(root *node, rpath, pkgID string) ([]*node, error)
val = src.rval
}
if typ.incomplete {
// Come back when type is known
// Come back when type is known.
revisit = append(revisit, n)
return false
}
@@ -80,6 +80,11 @@ func (interp *Interpreter) gta(root *node, rpath, pkgID string) ([]*node, error)
if n.typ, err = nodeType(interp, sc, n.child[l]); err != nil {
return false
}
if n.typ.incomplete {
// Come back when type is known.
revisit = append(revisit, n)
return false
}
}
for _, c := range n.child[:l] {
sc.sym[c.ident] = &symbol{index: sc.add(n.typ), kind: varSym, global: true, typ: n.typ}