You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Do and DoAndReturn panic when a variadic argument is nil #315
Actual behavior A mocked variadic method whose expectation carries a Do or DoAndReturn function panics when the code under test passes nil as a variadic element. Both actions synthesize the zero value for a nil argument from ft.In(i), where i counts the arguments flattened as the mock passes them, but a variadic func type holds the slice at its last position and nothing beyond it. At the last position the zero value is the slice itself and reflect.Call panics with reflect: cannot use []error as type error in Call; past it, ft.In(i) panics with index out of range.
Expected behavior The function receives nil in that variadic position, the same as it does for a nil fixed argument.
To Reproduce Steps to reproduce the behavior
Build a Call for func(string, ...error) and attach Do(func(_ string, errs ...error) {}).
Run the action with the arguments "msg", nil, nil.
The test binary panics instead of calling the function with two nil errors.
TestCall_Do_NilVariadicArg and TestCall_DoAndReturn_NilVariadicArg in the branch below do exactly this and fail on main at d8c3a2a.
Additional Information
gomock mode (reflect or source): both, the failure is in gomock/call.go
I have a fix with the two tests ready at https://github.com/lenamonj/mock/commit/17c9aeeb071acccf62bc6c4e4c6912774616db16: an argTypeAt helper that folds every position from the variadic one onwards onto the element type, used at both zero-value sites. go vet, go build, ci/test.sh, ci/check_panic_handling.sh and the module tests pass on it. CONTRIBUTING asks for an issue before a pull request, so I am opening this first and will open the pull request if you want the change.
Activity