derision-test / go-mockgen

MIT License
57 stars 7 forks source link

Surrogate interfaces don't support generics #42

Closed treyburn closed 1 year ago

treyburn commented 1 year ago

Perhaps I am missing a command line arg - but I do not see anything in the documentation that addresses this.

Using go-mockgen@v1.3.7 I see the following error related to generics and surrogate interfaces where the surrogate interface does not contain the required type parameter.

Using the following code and go:generate directive:

package foo

//go:generate go-mockgen -f github.com/user/mod/pkg/foo -i fooer -o ./mock/mock_fooer.go
type fooer[T any] interface {
    Foo() T
}

The resulting output for the surrogate interface is as follows:

// surrogateMockFooer is a copy of the fooer interface (from the package
// github.com/user/mod/pkg/foo). It is redefined here as it is
// unexported in the source package.
type surrogateMockFooer interface {
    Foo() T
}

The expected output would be:

// surrogateMockFooer is a copy of the fooer interface (from the package
// github.com/user/mod/pkg/foo). It is redefined here as it is
// unexported in the source package.
type surrogateMockFooer[T interface{}] interface {
    Foo() T
}
efritz commented 1 year ago

Thanks for catching this! Would you like to see if all the output related to a generic surrogate interfaces matches your expectations in #46? You can see this comment specifically for the entire generated output.

treyburn commented 1 year ago

Thanks for the super quick turn around on that one! I'll be sure to take a look at this tonight

treyburn commented 1 year ago

Pull your branch and messed around with it - working perfectly for surrogates and generics for me. Thank you!