-
-
Notifications
You must be signed in to change notification settings - Fork 133
Closed
Description
When mocking a method with a generic type, moq ignores package names of type arguments.
This works:
package example
//go:generate moq -skip-ensure -stub -rm -out mocks.go . Foo:FooMock
type Bar[T any] struct{}
type Foo interface {
Foo(bar Bar[Type])
}
But this does not:
package example
//go:generate moq -skip-ensure -stub -rm -out mocks.go . Foo:FooMock
import "path/to/pkg"
type Bar[T any] struct{}
type Foo interface {
Foo(bar Bar[pkg.Type])
}
The generated code instantiates Bar
as Bar[Type]
instead of Bar[pkg.Type]
, failing to compile:
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package example
import (
"sync"
)
type FooMock struct {
// FooFunc mocks the Foo method.
FooFunc func(bar Bar[Type])
// calls tracks calls to the methods.
calls struct {
// Foo holds details about calls to the Foo method.
Foo []struct {
// Bar is the bar argument value.
Bar Bar[Type]
}
}
lockFoo sync.RWMutex
}
I've tried workarounds like dot imports and type aliases, but got the same results. If Bar
type is a built-in like map
, it works fine.
moq version v0.2.7
.
dongxiaoman and TheFellow
Metadata
Metadata
Assignees
Labels
No labels