diff --git a/lang/core/fmt/printf.go b/lang/core/fmt/printf.go index 769023d1..8d92dde2 100644 --- a/lang/core/fmt/printf.go +++ b/lang/core/fmt/printf.go @@ -354,6 +354,16 @@ func (obj *PrintfFunc) Stream(ctx context.Context) error { } } +// Copy is implemented so that the obj.Type value is not lost if we copy this +// function. +func (obj *PrintfFunc) Copy() interfaces.Func { + return &PrintfFunc{ + Type: obj.Type, // don't copy because we use this after unification + + init: obj.init, // likely gets overwritten anyways + } +} + // Call this function with the input args and return the value if it is possible // to do so at this time. func (obj *PrintfFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) { diff --git a/lang/core/golang/template.go b/lang/core/golang/template.go index 41d69246..05c37ce6 100644 --- a/lang/core/golang/template.go +++ b/lang/core/golang/template.go @@ -393,6 +393,17 @@ func (obj *TemplateFunc) Stream(ctx context.Context) error { } } +// Copy is implemented so that the obj.built value is not lost if we copy this +// function. +func (obj *TemplateFunc) Copy() interfaces.Func { + return &TemplateFunc{ + Type: obj.Type, // don't copy because we use this after unification + built: obj.built, + + init: obj.init, // likely gets overwritten anyways + } +} + // Call this function with the input args and return the value if it is possible // to do so at this time. func (obj *TemplateFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) { diff --git a/lang/core/history.go b/lang/core/history.go index e80fc2b0..28e51024 100644 --- a/lang/core/history.go +++ b/lang/core/history.go @@ -134,6 +134,16 @@ func (obj *HistoryFunc) Build(typ *types.Type) (*types.Type, error) { return obj.sig(), nil } +// Copy is implemented so that the type value is not lost if we copy this +// function. +func (obj *HistoryFunc) Copy() interfaces.Func { + return &HistoryFunc{ + Type: obj.Type, // don't copy because we use this after unification + + init: obj.init, // likely gets overwritten anyways + } +} + // Validate makes sure we've built our struct properly. It is usually unused for // normal functions that users can use directly. func (obj *HistoryFunc) Validate() error { diff --git a/lang/core/iter/filter.go b/lang/core/iter/filter.go index 0f8743ed..fc771dad 100644 --- a/lang/core/iter/filter.go +++ b/lang/core/iter/filter.go @@ -459,3 +459,13 @@ func (obj *FilterFunc) replaceSubGraph(subgraphInput interfaces.Func) error { return obj.init.Txn.Commit() } + +// Copy is implemented so that the type value is not lost if we copy this +// function. +func (obj *FilterFunc) Copy() interfaces.Func { + return &FilterFunc{ + Type: obj.Type, // don't copy because we use this after unification + + init: obj.init, // likely gets overwritten anyways + } +} diff --git a/lang/core/iter/map.go b/lang/core/iter/map.go index c2282fff..b03f39b0 100644 --- a/lang/core/iter/map.go +++ b/lang/core/iter/map.go @@ -454,3 +454,14 @@ func (obj *MapFunc) replaceSubGraph(subgraphInput interfaces.Func) error { return obj.init.Txn.Commit() } + +// Copy is implemented so that the type values are not lost if we copy this +// function. +func (obj *MapFunc) Copy() interfaces.Func { + return &MapFunc{ + Type: obj.Type, // don't copy because we use this after unification + RType: obj.RType, // don't copy because we use this after unification + + init: obj.init, // likely gets overwritten anyways + } +} diff --git a/lang/core/lookup.go b/lang/core/lookup.go index a4947b8b..1fd24848 100644 --- a/lang/core/lookup.go +++ b/lang/core/lookup.go @@ -195,6 +195,20 @@ func (obj *LookupFunc) Build(typ *types.Type) (*types.Type, error) { return obj.fn.Build(typ) } +// Copy is implemented so that the type value is not lost if we copy this +// function. +func (obj *LookupFunc) Copy() interfaces.Func { + fn := &LookupFunc{ + Type: obj.Type, // don't copy because we use this after unification + + //init: obj.init, // likely gets overwritten anyways + } + if _, err := fn.Build(obj.Type); err != nil { + // ignore, since we just didn't set the type + } + return fn +} + // Validate tells us if the input struct takes a valid form. func (obj *LookupFunc) Validate() error { if obj.fn == nil { // build must be run first diff --git a/lang/core/lookup_default.go b/lang/core/lookup_default.go index d40c9c1c..113c34d3 100644 --- a/lang/core/lookup_default.go +++ b/lang/core/lookup_default.go @@ -140,6 +140,21 @@ func (obj *LookupDefaultFunc) Build(typ *types.Type) (*types.Type, error) { return obj.fn.Build(typ) } +// Copy is implemented so that the type value is not lost if we copy this +// function. +func (obj *LookupDefaultFunc) Copy() interfaces.Func { + fn := &LookupDefaultFunc{ + Type: obj.Type, // don't copy because we use this after unification + //fn: get this through Build() + + //init: obj.init, // likely gets overwritten anyways + } + if _, err := fn.Build(obj.Type); err != nil { + // ignore, since we just didn't set the type + } + return fn +} + // Validate tells us if the input struct takes a valid form. func (obj *LookupDefaultFunc) Validate() error { if obj.fn == nil { // build must be run first diff --git a/lang/core/value/get.go b/lang/core/value/get.go index 1671e4e4..18f17249 100644 --- a/lang/core/value/get.go +++ b/lang/core/value/get.go @@ -181,6 +181,16 @@ func (obj *GetFunc) Build(typ *types.Type) (*types.Type, error) { return obj.sig(), nil } +// Copy is implemented so that the type value is not lost if we copy this +// function. +func (obj *GetFunc) Copy() interfaces.Func { + return &GetFunc{ + Type: obj.Type, // don't copy because we use this after unification + + init: obj.init, // likely gets overwritten anyways + } +} + // Validate makes sure we've built our struct properly. It is usually unused for // normal functions that users can use directly. func (obj *GetFunc) Validate() error { diff --git a/lang/core/world/schedule.go b/lang/core/world/schedule.go index 56ec46ee..94961a40 100644 --- a/lang/core/world/schedule.go +++ b/lang/core/world/schedule.go @@ -247,6 +247,17 @@ func (obj *ScheduleFunc) Build(typ *types.Type) (*types.Type, error) { return obj.sig(), nil } +// Copy is implemented so that the type value is not lost if we copy this +// function. +func (obj *ScheduleFunc) Copy() interfaces.Func { + return &ScheduleFunc{ + Type: obj.Type, // don't copy because we use this after unification + built: obj.built, + + init: obj.init, // likely gets overwritten anyways + } +} + // Validate tells us if the input struct takes a valid form. func (obj *ScheduleFunc) Validate() error { if !obj.built { diff --git a/lang/funcs/operators/operators.go b/lang/funcs/operators/operators.go index c8b6fb07..b0731421 100644 --- a/lang/funcs/operators/operators.go +++ b/lang/funcs/operators/operators.go @@ -722,6 +722,16 @@ func (obj *OperatorFunc) Stream(ctx context.Context) error { } } +// Copy is implemented so that the obj.Type value is not lost if we copy this +// function. +func (obj *OperatorFunc) Copy() interfaces.Func { + return &OperatorFunc{ + Type: obj.Type, // don't copy because we use this after unification + + init: obj.init, // likely gets overwritten anyways + } +} + // Call this function with the input args and return the value if it is possible // to do so at this time. func (obj *OperatorFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {