Skip to content

Commit

Permalink
fix: handle out of order type declaration for global var declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored Feb 3, 2020
1 parent e434892 commit 92a63db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions _test/fun11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

var f F

type F func(int)

func main() {
println("ok")
}

// Output:
// ok
7 changes: 6 additions & 1 deletion interp/gta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 92a63db

Please sign in to comment.