This repository was archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 607
This repository was archived by the owner on Jun 27, 2023. It is now read-only.
Incorrectly treating generic types as exported types #658
Copy link
Copy link
Open
Milestone
Description
Consider a source file notifier.go
we want to mock, with the following pattern :
type Clonable[T any] interface {
Clone() T
}
type Finder[T Clonable[T]] interface {
Find(ctx context.Context) ([]T, error)
}
type UpdateNotifier[T any] interface {
NotifyC(ctx context.Context) <-chan []T
Refresh(ctx context.Context)
}
Actual behavior A clear and concise description of what the bug is.
The three following functions are generated
// MockFinder is a mock of Finder interface.
type MockFinder[T notifier.Clonable[notifier.T]] struct {
ctrl *gomock.Controller
recorder *MockFinderMockRecorder[T]
}
// MockFinderMockRecorder is the mock recorder for MockFinder.
type MockFinderMockRecorder[T notifier.Clonable[notifier.T]] struct {
mock *MockFinder[T]
}
// NewMockFinder creates a new mock instance.
func NewMockFinder[T notifier.Clonable[notifier.T]](ctrl *gomock.Controller) *MockFinder[T] {
mock := &MockFinder[T]{ctrl: ctrl}
mock.recorder = &MockFinderMockRecorder[T]{mock}
return mock
}
Note that in the above the generic type T is treated as an exported type from notifier
Expected behavior A clear and concise description of what you expected to
happen.
notifier.Clonable[notifier.T]
should be notifier.Clonable[T]
in the function signatures
// MockFinder is a mock of Finder interface.
type MockFinder[T notifier.Clonable[T]] struct {
/* ... */
}
// MockFinderMockRecorder is the mock recorder for MockFinder.
type MockFinderMockRecorder[T notifier.Clonable[T]] struct {
/* ... */
}
// NewMockFinder creates a new mock instance.
func NewMockFinder[T notifier.Clonable[T]](ctrl *gomock.Controller) *MockFinder[T] {
/* ... */
}
To Reproduce Steps to reproduce the behavior
- mockgen -source notifier.go -output notifier_mock.go
Additional Information
- gomock mode (reflect or source): source
- gomock version or git ref:
github.com/golang/mock v1.6.1-0.20220512030613-73266f9366fc
- golang version: go version go1.18.2 darwin/arm64
Triage Notes for the Maintainers
Seems like a fun one
Metadata
Metadata
Assignees
Labels
No labels