diff --git a/lang/funcs/structs/const.go b/lang/funcs/structs/const.go index 38965b89..c9696a3b 100644 --- a/lang/funcs/structs/const.go +++ b/lang/funcs/structs/const.go @@ -111,6 +111,16 @@ func (obj *ConstFunc) Stream(ctx context.Context) error { // Call this function with the input args and return the value if it is possible // to do so at this time. func (obj *ConstFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) { + if obj.Info() == nil { + return nil, fmt.Errorf("info is empty") + } + if obj.Info().Sig == nil { + return nil, fmt.Errorf("sig is empty") + } + if i, j := len(args), len(obj.Info().Sig.Ord); i != j { + return nil, fmt.Errorf("arg length doesn't match, got %d, exp: %d", i, j) + } + if obj.Value == nil { return nil, fmt.Errorf("no value available from const") } diff --git a/lang/funcs/structs/if.go b/lang/funcs/structs/if.go index 253c3647..a242ea67 100644 --- a/lang/funcs/structs/if.go +++ b/lang/funcs/structs/if.go @@ -148,6 +148,16 @@ func (obj *IfFunc) Stream(ctx context.Context) error { // to do so at this time. // XXX: Is is correct to implement this here for this particular function? func (obj *IfFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) { + if obj.Info() == nil { + return nil, fmt.Errorf("info is empty") + } + if obj.Info().Sig == nil { + return nil, fmt.Errorf("sig is empty") + } + if i, j := len(args), len(obj.Info().Sig.Ord); i != j { + return nil, fmt.Errorf("arg length doesn't match, got %d, exp: %d", i, j) + } + if c := args[0].Bool(); c { return args[1], nil // true branch }