From 4b6b91c08bdcf7219b550d84eb8288c91a6b4d6a Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 22 Jul 2019 06:47:25 -0400 Subject: [PATCH] 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. --- lang/structs.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lang/structs.go b/lang/structs.go index 4d14c113..eb82641d 100644 --- a/lang/structs.go +++ b/lang/structs.go @@ -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