-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Cannot return nil for generic type T, when T is an interface #513
Comments
This is a workaround to get the test working with the current version of mockery: thingBuilder.On("Build").Return(func() Thing { return nil }, errors.New("some error")) |
Possible fix: Generate the following code in all non-error cases, instead of the current v := ret.Get(0)
if !reflect.ValueOf(&v).Elem().IsZero() && !reflect.ValueOf(v).IsZero() {
r0 = v.(T)
}
This also requires an addition of (The second check may not be strictly necessary, I was just trying to match the behavior of the code that mockery currently generates. It seems to work fine with just |
Even just putting |
Description
For the interfaces
I'd like to mock
Builder
behavior asBut I get an error like:
Shouldn't mockery know that
Thing
is an interface and soBuilder[Thing].Build()
should be able to return(nil, error)
?Mockery Version
Golang Version
Installation Method
Expected Behavior
Can mock generic return types as nil when they are in fact interfaces.
Actual Behavior
Tests panic
The text was updated successfully, but these errors were encountered: