golang / mock

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

Cannot parse type parameters on return interface types #666

Closed Fryuni closed 1 year ago

Fryuni commented 1 year ago

Actual behavior A clear and concise description of what the bug is. When the return of an interface includes another interface that uses one of the available type parameter the parsing fails with:

❯ mockgen -source=foo.go
2022/07/21 01:01:20 Loading input failed: foo.go:5:6: failed parsing returns: don't know how to parse type *ast.IndexExpr

This seems similar to #643, but that issue was using reflect mode.

Expected behavior A clear and concise description of what you expected to happen.

The mock should be generated like any other generic interface, keeping the return type exactly as defined.

To Reproduce Steps to reproduce the behavior

Minimal reproduction Save this file:

package bugTest

type (
    Foo[T any] interface {
        Bar() Bar[T]
    }
    Bar[T any] interface {
        Baz() T
    }
)

Run mockgen -source <path to file>

Additional Information

Triage Notes for the Maintainers

bradleygore commented 1 year ago

I have a PR that aims to address this in source mode: https://github.com/golang/mock/pull/663

codyoss commented 1 year ago

Closing as a dupe of #643