diff --git a/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIfaceWithInterfaceTypedParam.go b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIfaceWithInterfaceTypedParam.go new file mode 100644 index 000000000..3ac33b9e0 --- /dev/null +++ b/mocks/github.com/vektra/mockery/v2/pkg/fixtures/RequesterIfaceWithInterfaceTypedParam.go @@ -0,0 +1,83 @@ +// Code generated by mockery. DO NOT EDIT. + +package mocks + +import ( + io "io" + + mock "github.com/stretchr/testify/mock" +) + +// RequesterIfaceWithInterfaceTypedParam is an autogenerated mock type for the RequesterIfaceWithInterfaceTypedParam type +type RequesterIfaceWithInterfaceTypedParam[T io.Reader] struct { + mock.Mock +} + +type RequesterIfaceWithInterfaceTypedParam_Expecter[T io.Reader] struct { + mock *mock.Mock +} + +func (_m *RequesterIfaceWithInterfaceTypedParam[T]) EXPECT() *RequesterIfaceWithInterfaceTypedParam_Expecter[T] { + return &RequesterIfaceWithInterfaceTypedParam_Expecter[T]{mock: &_m.Mock} +} + +// Get provides a mock function with given fields: +func (_m *RequesterIfaceWithInterfaceTypedParam[T]) Get() T { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Get") + } + + var r0 T + if rf, ok := ret.Get(0).(func() T); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(T) + } + } + + return r0 +} + +// RequesterIfaceWithInterfaceTypedParam_Get_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Get' +type RequesterIfaceWithInterfaceTypedParam_Get_Call[T io.Reader] struct { + *mock.Call +} + +// Get is a helper method to define mock.On call +func (_e *RequesterIfaceWithInterfaceTypedParam_Expecter[T]) Get() *RequesterIfaceWithInterfaceTypedParam_Get_Call[T] { + return &RequesterIfaceWithInterfaceTypedParam_Get_Call[T]{Call: _e.mock.On("Get")} +} + +func (_c *RequesterIfaceWithInterfaceTypedParam_Get_Call[T]) Run(run func()) *RequesterIfaceWithInterfaceTypedParam_Get_Call[T] { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *RequesterIfaceWithInterfaceTypedParam_Get_Call[T]) Return(_a0 T) *RequesterIfaceWithInterfaceTypedParam_Get_Call[T] { + _c.Call.Return(_a0) + return _c +} + +func (_c *RequesterIfaceWithInterfaceTypedParam_Get_Call[T]) RunAndReturn(run func() T) *RequesterIfaceWithInterfaceTypedParam_Get_Call[T] { + _c.Call.Return(run) + return _c +} + +// NewRequesterIfaceWithInterfaceTypedParam creates a new instance of RequesterIfaceWithInterfaceTypedParam. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewRequesterIfaceWithInterfaceTypedParam[T io.Reader](t interface { + mock.TestingT + Cleanup(func()) +}) *RequesterIfaceWithInterfaceTypedParam[T] { + mock := &RequesterIfaceWithInterfaceTypedParam[T]{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/fixtures/requester_iface.go b/pkg/fixtures/requester_iface.go index c9df99e03..e110e6ca4 100644 --- a/pkg/fixtures/requester_iface.go +++ b/pkg/fixtures/requester_iface.go @@ -5,3 +5,7 @@ import "io" type RequesterIface interface { Get() io.Reader } + +type RequesterIfaceWithInterfaceTypedParam[T io.Reader] interface { + Get() T +} diff --git a/pkg/generator.go b/pkg/generator.go index f015a6510..4f600c78b 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -665,7 +665,7 @@ func isNillable(typ types.Type) bool { switch t := typ.(type) { case *types.Pointer, *types.Array, *types.Map, *types.Interface, *types.Signature, *types.Chan, *types.Slice: return true - case *types.Named, *types.Alias: + case *types.Named, *types.Alias, *types.TypeParam: return isNillable(t.Underlying()) } return false diff --git a/pkg/generator_test.go b/pkg/generator_test.go index 293ea2eb4..cdf50bf64 100644 --- a/pkg/generator_test.go +++ b/pkg/generator_test.go @@ -337,6 +337,22 @@ func (s *GeneratorSuite) TestGeneratorChecksInterfacesForNilable() { s.checkGeneration("requester_iface.go", "RequesterIface", false, "", "") } +func (s *GeneratorSuite) TestGeneratorChecksInterfacesWithGenericInterfaceTypedParamForNilable() { + expectedBytes, err := os.ReadFile(getMocksPath("RequesterIfaceWithInterfaceTypedParam.go")) + s.Require().NoError(err) + + expected := string(expectedBytes) + expected = expected[strings.Index(expected, "// RequesterIfaceWithInterfaceTypedParam is"):] + + cfg := GeneratorConfig{ + StructName: "RequesterIfaceWithInterfaceTypedParam", + WithExpecter: true, + UnrollVariadic: false, + } + + s.checkGenerationWithConfig("requester_iface.go", "RequesterIfaceWithInterfaceTypedParam", cfg, expected) +} + func (s *GeneratorSuite) TestGeneratorTreatsAnyAsNilable() { cfg := GeneratorConfig{ WithExpecter: true,