Open bradleygore opened 2 years ago
@bradleygore note as written this would not work ever since generics can only be used in source mode currently, reflection is not supported.
Hey @codyoss - so are you saying that if I ran it as mockgen -source=./custom.go -destination=./mocks/CustomWorker.go CustomWorker
it would work? I will try it this way soon and report back - thanks!!
@bradleygore it does not, but just wanted to be clear with expectations that reflect mode will never work with generics.(At least for the foreseeable future)
Ah, ok - I see. Thanks for the explanation π
Hey @codyoss - my team and I love gomock
so I wanted to try to contribute back. I took a stab at helping with this and it seems to work nicely (I think... π
). https://github.com/golang/mock/pull/663
There is a bot on it stating I need to sign a Contributor's License Agreement
- so I just did that.
I really hope this is helpful, and am looking forward to feedback!
Thank you!
+1 for fixing this please :pray:
Actual behavior
Typing for nested generic interface is scoped to package the interface belongs to and not the pkgs the type belongs to.
Here is a complete example: https://github.com/bradleygore/gomock-generics-issue/blob/master/workers/custom.go
I pulled down
gomock
repo into~/git/gomock
and checked outmaster
and didcd mockgen && go install ./...
to install it.I then updated the
go.mod
to path to that resource:I then ran the cmd to generate mocks against the dev branch:
This did not produce any error, but it did produce an issue in the output:
Expected behavior
Expected behavior would be that the type for the generic parameter is not presumed to come from the same pkg as the generic interface's definition, as this causes the mock to not compile.
In this specific scenario, the mock would import
workers
pkg, and the output of the above would look like this:Additional Information
My primary use-case for this is a
Repository
style setup. Consider:Notes for the Maintainers
π Y'all are awesome and
gomock
is fantastic! π