fix: add support for out of order declarations of empty global variables

This commit is contained in:
Marc Vertes
2019-09-11 12:52:04 +02:00
committed by Traefiker Bot
parent 3645904a15
commit 058c121273
2 changed files with 17 additions and 2 deletions

8
_test/fun8.go Normal file
View File

@@ -0,0 +1,8 @@
package main
func main() { println(f == nil) }
var f func()
// Output:
// true

View File

@@ -72,8 +72,15 @@ func (interp *Interpreter) gta(root *node, rpath string) ([]*node, error) {
err = compDefineX(sc, n)
case valueSpec:
// TODO: handle global ValueSpec
//err = n.cfgError("global ValueSpec not implemented")
l := len(n.child) - 1
if n.typ = n.child[l].typ; n.typ == nil {
if n.typ, err = nodeType(interp, sc, n.child[l]); err != nil {
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}
}
case funcDecl:
if n.typ, err = nodeType(interp, sc, n.child[2]); err != nil {