[pkg/ottl] Break lambda arity validation into its own function#49421
[pkg/ottl] Break lambda arity validation into its own function#49421evan-bradley wants to merge 5 commits into
Conversation
| if len(l.formals) != arity { | ||
| return nil, fmt.Errorf("lambda expects exactly %d argument(s), got %d", arity, len(l.formals)) | ||
| } | ||
| func (l *LambdaExpression[K]) Activate(ctx context.Context) (*LambdaActivation[K], error) { |
There was a problem hiding this comment.
Whats the error if a function calls activate with the wrong parity? Will it panic?
There was a problem hiding this comment.
It doesn't panic, you have one of two things happen:
- If there are more arguments than parameters, you'll get an error returned when you try to bind an argument that doesn't have a defined parameter.
- If there are fewer arguments than parameters, some parameters are not bound and are essentially
nilfrom my rudimentary testing.
If we're really concerned about ValidateArity not being called before Activate, we could include a flag on the lambda expression to check that ValidateArity has been called.
There was a problem hiding this comment.
If we're really concerned about ValidateArity not being called before Activate, we could include a flag on the lambda expression to check that ValidateArity has been called.
I'd add this validation to ensure usages are consistent and all functions implementations are correct.
If for some reason the function do not to validate it, Eval((a, b, c) => a, [1, 2]) for example, would be accepted.
Description
Follow up from #49184 (comment).
Authorship