lang: funcs: structs: Add some extra safety checks
Not sure if these are even needed.
This commit is contained in:
@@ -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
|
// Call this function with the input args and return the value if it is possible
|
||||||
// to do so at this time.
|
// to do so at this time.
|
||||||
func (obj *ConstFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
|
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 {
|
if obj.Value == nil {
|
||||||
return nil, fmt.Errorf("no value available from const")
|
return nil, fmt.Errorf("no value available from const")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,16 @@ func (obj *IfFunc) Stream(ctx context.Context) error {
|
|||||||
// to do so at this time.
|
// to do so at this time.
|
||||||
// XXX: Is is correct to implement this here for this particular function?
|
// 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) {
|
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 {
|
if c := args[0].Bool(); c {
|
||||||
return args[1], nil // true branch
|
return args[1], nil // true branch
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user