lang: Make sure to call Init for functions that arrive via import

We weren't calling Init on some functions which should have had this
done. I'm not sure whether this is the right place, or if it should be
elsewhere as part of the scope building process. Good enough for now.
This commit is contained in:
James Shubin
2019-07-22 06:47:25 -04:00
parent 2980523a5b
commit 4b6b91c08b

View File

@@ -3061,6 +3061,16 @@ func (obj *StmtProg) importSystemScope(name string) (*interfaces.Scope, error) {
isEmpty = false
}
// perform any normal "startup" for these functions...
for _, fn := range funcs {
// XXX: is this the right place for this, or should it be elsewhere?
// XXX: do we need a modified obj.data for this b/c it's in a scope?
if err := fn.Init(obj.data); err != nil {
return nil, errwrap.Wrapf(err, "could not init function")
}
// TODO: do we want to run Interpolate or SetScope?
}
// initial scope, built from core golang code
scope := &interfaces.Scope{
// TODO: we could add core API's for variables and classes too!
@@ -6654,7 +6664,7 @@ func (obj *ExprFunc) Apply(fn func(interfaces.Node) error) error {
// Init initializes this branch of the AST, and returns an error if it fails to
// validate.
func (obj *ExprFunc) Init(data *interfaces.Data) error {
obj.data = data
obj.data = data // TODO: why is this sometimes nil?
// validate that we're using *only* one correct representation
a := obj.Body != nil