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

Wrong mock generated for the interface with generics #700

Open
heww opened this issue Mar 30, 2023 · 0 comments
Open

Wrong mock generated for the interface with generics #700

heww opened this issue Mar 30, 2023 · 0 comments

Comments

@heww
Copy link

heww commented Mar 30, 2023

Actual behavior A clear and concise description of what the bug is.

For the interface with generics

type Model[T any] interface {
	*T
	TableName() string
}
type Client[T any, P types.Model[T]] interface {
	Create(*P) error
}

The generated mock is like this

// MockClient is a mock of Client interface.
type MockClient[T any, P types.Model[client.T]] struct {
	ctrl     *gomock.Controller
	recorder *MockClientMockRecorder[T, P]
}

// MockClientMockRecorder is the mock recorder for MockClient.
type MockClientMockRecorder[T any, P types.Model[client.T]] struct {
	mock *MockClient[T, P]
}

// NewMockClient creates a new mock instance.
func NewMockClient[T any, P types.Model[client.T]](ctrl *gomock.Controller) *MockClient[T, P] {
	mock := &MockClient[T, P]{ctrl: ctrl}
	mock.recorder = &MockClientMockRecorder[T, P]{mock}
	return mock
}

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

The argument for the P should be T, not the client.T.

// MockClient is a mock of Client interface.
type MockClient[T any, P types.Model[T]] struct {
	ctrl     *gomock.Controller
	recorder *MockClientMockRecorder[T, P]
}

To Reproduce Steps to reproduce the behavior

  1. git clone https://github.com/heww/gomock-issue.git
  2. go generate ./...

Additional Information

  • gomock mode (reflect or source):
  • gomock version or git ref: v1.7.0-rc.1
  • golang version: 1.19.7

Triage Notes for the Maintainers

@heww heww changed the title Wrong mock generated for the generics interface Wrong mock generated for the interface with generics Mar 30, 2023
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

1 participant