Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Generating mocks (reflect mode) fails if interface contains methods with generic types #677

Closed
daolis opened this issue Sep 19, 2022 · 2 comments

Comments

@daolis
Copy link

daolis commented Sep 19, 2022

Generating mocks (reflect mode) fails with Failed to format generated source code: if the interface contains methods with generic types.

The generated code contains the full package path as the type.
The wrong type is returned from reflect.typeOf (see golang/go#55147)

Reproduceable with

package test

import (
	_ "github.com/golang/mock/gomock"
)

type TestType string

type TestGenericType[T any] struct {
	blaa T
}

//go:generate mockgen -destination zz_generated_mock.go -package mockst . TestGenericInterface

type TestGenericInterface interface {
	TestMethod() TestGenericType[TestType]
}

generated file contains e.g. this method

// TestMethod mocks base method.
func (m *MockTestGenericInterface) TestMethod() test.TestGenericType[github.com/daolis/mockgentest/test.TestType] {
        m.ctrl.T.Helper()
        ret := m.ctrl.Call(m, "TestMethod")
        ret0, _ := ret[0].(test.TestGenericType[github.com/daolis/mockgentest/test.TestType])
        return ret0
}
@tra4less
Copy link
Contributor

#669 fix it

@daolis
Copy link
Author

daolis commented Mar 14, 2023

Closing issue: see #669

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants