-
Notifications
You must be signed in to change notification settings - Fork 0
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
quick hack #1
Comments
Unfortunately, this kind of defeats the usefulness of having a base interface that I can embed into other interfaces. My specific situation is with a data access layer and repository pattern:
I would have to duplicate all the embedded interface funcs if I go this route. I have dozens of repositories at present and would really love to not have to do this 😅 |
Just for ease of documentation, if anyone else runs across this repo, the catalyst of this is golang/mock#621 |
Well… if we'll have to choose between some copy&paste of interfaces content or avoid using generics until gomock will support generics (no ETA at all AFAIK), or stop using gomock… I'll choose to copy&paste interfaces. This is harmless, it can be probably done in separate temporary files, it can be easily checked for errors at compile time by applying interface conversion for Also, I think you get the idea - probably there are some other ways to work around gomock limitation, experiment with it and maybe you'll find another one to avoid or minimize copy&paste. |
@powerman - I tried this and it does not work:
Output in terminal (b/c it does not write to file on error):
Notice that even though my interface references Sorry if I'm totally missing something, but I don't think this workaround will work with non-primitive values. If I change the definition of |
As you can see in my diff above - I didn't used type alias this time. As long as non-aliased type is an interface there is no difference between alias or not - but without alias gomock code generation works. |
I'm sorry - I looked back over the diff and I'm confused how this is not a type alias?
I've tried the suggestion you posted above, per my earlier comment, and it just does not work then the value for |
No, it's not: there is no |
Oh - I see, I added an |
I tried it as a new type definition instead of a type alias, and that won't work in my case. In my case, I have common utility functions that rely on interface implementation. Consider:
If I change the type as Here's an example from the situation I'm working on:
I guess I'll just have to wait until mockgen supports this a bit better. |
I suppose |
Also you probably should (or at least can try to) define |
Yeah, that's the problem I'm running into. If I use it as a new type, |
From what I have found mockgen requires interface types to be non-aliases and usual types to be aliases. |
I'm too sleepy (it's 6AM here), so I didn't actually tried to understand the code, sorry. But this quick hack looks like works around code generation in ./workers:
The text was updated successfully, but these errors were encountered: