golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.26k stars 608 forks source link

Use of -aux_files causes incorrect generated code in case of embedded interface with package name overlap #691

Open GillesMoris-NexuzHealth opened 1 year ago

GillesMoris-NexuzHealth commented 1 year ago

Actual behavior Using -aux_files when generating a mock for an interface with an embedded interface, combined with overlapping package names and a resulting named import can cause the generated code to use the wrong package name for parameters of the nested interface. Generating without the -aux_files flag does not have the same issue.

Expected behavior No errors in generated code when using -aux_files.

To Reproduce Steps to reproduce the behavior

mockgen_issue.zip The attached zip contains a minimal reproduction case that is somewhat modeled after how it occurred in our codebase, running the mockgen command in foo.go will generate an invalid mock.

Additional Information

Can be worked around by not using -aux_files or by turning the overlapping package name import into a differently named import as well.

Triage Notes for the Maintainers Issue regarding -aux_files, which we were using but after retrying without it seems like we might not need it anymore, but as long as it's not deprecated it should still result in correct mock generation.