-
Notifications
You must be signed in to change notification settings - Fork 157
Description
Actual behavior A clear and concise description of what the bug is.
When running this uber mockgen in a codebase with reference to the golang mockgen, the reflect program would panic on the gob.Register call:
panic: gob: registering duplicate types for "*model.ArrayType": *model.ArrayType != *model.ArrayType
goroutine 1 [running]:
encoding/gob.RegisterName({0x10fad4f, 0x10}, {0x110b460, 0xc000010468})
/usr/local/go/src/encoding/gob/type.go:820 +0x3f4
encoding/gob.Register({0x110b460, 0xc000010468})
/usr/local/go/src/encoding/gob/type.go:874 +0x1c5
github.com/golang/mock/mockgen/model.init.0()
$HOME/workshop/go/pkg/mod/github.com/golang/[email protected]/mockgen/model/model.go:146 +0x39
panic: gob: registering duplicate types for "*model.ArrayType": *model.ArrayType != *model.ArrayType
...
Expected behavior A clear and concise description of what you expected to
happen.
This is because in our code base (or similar code base created before go mod area) contains import path like this:
_ "github.com/golang/mock/mockgen/model"
This call will register the model types with the same name, and result in gob panic. This import call is suggested by golang mockgen as a workaround for vendor usage:
https://github.com/golang/mock#reflect-vendoring-error
I believe this would be a blocker for migrating from golang mockgen as upstream libraries might have such import path, and it would take time to migrate all these upstream libraries as it requires multiple steps.
Therefore, I would like to propose a fix to register these model types with a prefix.
To Reproduce Steps to reproduce the behavior
To produce this issue, please check out this commit: https://github.com/bcho/gomock-migrate/tree/4148048b8a313fa0be6164d1cdcdc941e523c0c1
I have a fix poc in this commit: https://github.com/bcho/gomock-migrate/tree/2de73982ee899e4e0a3986a021b584c08feb3e5f , which updated the uber gomock to use the fixed model in my local fork.
Additional Information
- gomock mode (reflect or source): reflect
- gomock version or git ref:
0.2.0 - golang version: go version go1.20.2 darwin/amd64
Triage Notes for the Maintainers