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
There is no way to have an interface that clones itself without using generics.
It would help if there was a way to tell Mockery to replace the generics with a specific type, in this case, itself.
Actual Behavior
Is correct, but also doesnt work. It generates the mocks usings the interface definition but it needs more flexibility to work correctly.
The text was updated successfully, but these errors were encountered:
It took me a minute to wrap my head around the question but I think I understand. This is basically a self-referential problem coming from the fact that .Clone() is returning the same generic type that was used when instantiating the mocks.MockClient type. This loop is generated when providing concrete types to the generic constraints:
I forked your example and manually modified the mocks to provide a completely working example of what we would ultimately want mockery to generate: LandonTClipp/mockery-cloneable@d18f1dd
The proposal is to add new config parameters that allow mockery to replace the generic constraints with concrete types. The changes I made to the mock implementation should be what mockery would generate.
My questions for you:
Does my fork of your reproducer seem to actually fix your problem?
Would you be willing to submit a PR for this, assuming we both agree on the solution I proposed?
Okay great. It would be much appreciated if you could try for an implementation here. Otherwise, I can probably do it myself sometime in the next few weeks. Although, this is such a rare situation that it might get thrown behind some other high priority tasks.
Description
When using an interface that describes a method that returns a clone of the struct, the generated mocks cannot be used.
Take this interface for example:
This can be implemented and used normally with this struct (note, no generics used here):
This struct can successfully be injected into a function that expects the Repository[T] interface:
However, the generated mocks generate a struct that follows the interface (as expected):
The problem is that these generated structs now cannot be used in the Foo function because their clone methods cannot infer T.
For an example with a little bit more added, please see this repository: https://github.com/DustinJSilk/mockery-cloneable/tree/main
Mockery Version
v2.39.2
Golang Version
1.21.6
Installation Method
Steps to Reproduce
Expected Behavior
There is no way to have an interface that clones itself without using generics.
It would help if there was a way to tell Mockery to replace the generics with a specific type, in this case, itself.
Actual Behavior
Is correct, but also doesnt work. It generates the mocks usings the interface definition but it needs more flexibility to work correctly.
The text was updated successfully, but these errors were encountered: