From 92a63dbe097e9d85948272cf1eacbf385ddee27a Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 3 Feb 2020 17:36:04 +0100 Subject: [PATCH] fix: handle out of order type declaration for global var declaration --- _test/fun11.go | 12 ++++++++++++ interp/gta.go | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 _test/fun11.go diff --git a/_test/fun11.go b/_test/fun11.go new file mode 100644 index 000000000..a7e1fd2b7 --- /dev/null +++ b/_test/fun11.go @@ -0,0 +1,12 @@ +package main + +var f F + +type F func(int) + +func main() { + println("ok") +} + +// Output: +// ok diff --git a/interp/gta.go b/interp/gta.go index 3f2441953..38eff35f5 100644 --- a/interp/gta.go +++ b/interp/gta.go @@ -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}