-
Notifications
You must be signed in to change notification settings - Fork 163
Open
Description
Actual behavior
- GIVEN an archive for a go package which contains an interface with an argument which contains a type parameter.
- WHEN running mockgen in archive mode to generate the mocks for the archive
- THEN the generated file is an invalid go file which does not compile due to type parameters being missing.
e.g.
...
func (m *MockIFace) Method(param example.Param) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Method", param)
}
...
Expected behavior
The file is generated with the type parameter initialised
...
func (m *MockIFace) Method(param example.Param[int]) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Method", param)
}
...
To Reproduce Steps to reproduce the behavior
- Create a new example module
$ mkdir example
$ cd example
$ go mod init example.com/m
- Create new go package within the module which contains an interface with a method with a type parameter
$ echo "package example\n\ntype Param[T any] struct {\n Field T\n}\n\ntype IFace interface {\n Method(param Param[int])\n}\n" > example.go
- build the archive for the example module
$ go build -buildmode=archive -o example.a
- Generate the mocks for the archive
$ mkdir mocks
$ mockgen -archive example.a example IFace > mocks/mocks.go
- Attempt to build the mocks
$ go get go.uber.org/mock/gomock
$ go build ./mocks
# example.com/m/mocks
mocks/mocks.go:44:34: cannot use generic type example.Param[T any] without instantiation
Additional Information
- gomock mode (reflect or source): archive
- gomock version or git ref: v0.6.0
- golang version: go version go1.25.3 linux/amd64
Triage Notes for the Maintainers
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels