5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 06:51:26 +08:00

Fix for variadic args in bound methods

This commit is contained in:
Lea Anthony 2023-03-22 20:36:46 +11:00
parent 4165caa02e
commit 42fb91bc73

View File

@ -239,14 +239,22 @@ func (b *BoundMethod) Call(args []interface{}) (interface{}, error) {
// Check inputs // Check inputs
expectedInputLength := len(b.Inputs) expectedInputLength := len(b.Inputs)
actualInputLength := len(args) actualInputLength := len(args)
// 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 { if expectedInputLength != actualInputLength {
return nil, fmt.Errorf("%s takes %d inputs. Received %d", b.Name, expectedInputLength, actualInputLength) return nil, fmt.Errorf("%s takes %d inputs. Received %d", b.Name, expectedInputLength, actualInputLength)
} }
}
/** Convert inputs to reflect values **/ /** Convert inputs to reflect values **/
// Create slice for the input arguments to the method call // Create slice for the input arguments to the method call
callArgs := make([]reflect.Value, expectedInputLength) callArgs := make([]reflect.Value, actualInputLength)
// Iterate over given arguments // Iterate over given arguments
for index, arg := range args { for index, arg := range args {