From 42fb91bc73abb80775455bdd67658dd4a77f4f7d Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 22 Mar 2023 20:36:46 +1100 Subject: [PATCH] Fix for variadic args in bound methods --- v3/pkg/application/bindings.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/v3/pkg/application/bindings.go b/v3/pkg/application/bindings.go index 5a94ee9c9..9ae792e2e 100644 --- a/v3/pkg/application/bindings.go +++ b/v3/pkg/application/bindings.go @@ -239,14 +239,22 @@ func (b *BoundMethod) Call(args []interface{}) (interface{}, error) { // Check inputs expectedInputLength := len(b.Inputs) actualInputLength := len(args) - if expectedInputLength != actualInputLength { - return nil, fmt.Errorf("%s takes %d inputs. Received %d", b.Name, expectedInputLength, actualInputLength) + + // If the method is variadic, we need to check the minimum number of inputs + if b.Method.Type().IsVariadic() { + if actualInputLength < expectedInputLength-1 { + return nil, fmt.Errorf("%s takes at least %d inputs. Received %d", b.Name, expectedInputLength, actualInputLength) + } + } else { + if expectedInputLength != actualInputLength { + return nil, fmt.Errorf("%s takes %d inputs. Received %d", b.Name, expectedInputLength, actualInputLength) + } } /** Convert inputs to reflect values **/ // Create slice for the input arguments to the method call - callArgs := make([]reflect.Value, expectedInputLength) + callArgs := make([]reflect.Value, actualInputLength) // Iterate over given arguments for index, arg := range args {