Implement setting of variables in other modules correctly.

This fixes #141.
This commit is contained in:
Qi Xiao 2016-02-19 20:39:22 +01:00
parent 2cdbf67147
commit 2e08ae0975

View File

@ -312,11 +312,18 @@ func (cp *compiler) singleVariable(n *parse.Indexing, msg string) VariableOp {
} }
variable := ec.ResolveVar(ns, barename) variable := ec.ResolveVar(ns, barename)
if variable == nil { if variable == nil {
// New variable. if ns == "" || ns == "local" {
// XXX We depend on the fact that this variable will // New variable.
// immeidately be set. // XXX We depend on the fact that this variable will
variable = NewPtrVariable(nil) // immeidately be set.
ec.local[barename] = variable variable = NewPtrVariable(nil)
ec.local[barename] = variable
} else if mod, ok := ec.modules[ns]; ok {
variable = NewPtrVariable(nil)
mod[barename] = variable
} else {
ec.errorf(p, "cannot set $%s", varname)
}
} }
return variable return variable
} }