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)
if variable == nil {
if ns == "" || ns == "local" {
// New variable.
// XXX We depend on the fact that this variable will
// immeidately be set.
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
}