Skip to content

Commit

Permalink
Merge commit 'pullrequests/Ralph7C2/genericparams'
Browse files Browse the repository at this point in the history
  • Loading branch information
joefitzgerald committed Jan 12, 2024
2 parents c1028da + 69e693e commit 2c17700
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 0 deletions.
16 changes: 16 additions & 0 deletions fixtures/genericparam/genericparam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package genericparam

import (
"github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam/genericparamtype"
"github.com/maxbrunsfeld/counterfeiter/v6/fixtures/genericparam/genericreturntype"
)

//counterfeiter:generate . GenericParamFunc
type GenericParamFunc func(Generic[genericparamtype.T]) Generic[genericreturntype.R]

//counterfeiter:generate . GenericParamInterface
type GenericParamInterface interface {
DoSomething(Generic[genericparamtype.T]) Generic[genericreturntype.R]
}

type Generic[T any] struct{ _ T }
112 changes: 112 additions & 0 deletions fixtures/genericparam/genericparamfakes/fake_generic_param_func.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions fixtures/genericparam/genericparamtype/genericparamtype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package genericparamtype

type T string
3 changes: 3 additions & 0 deletions fixtures/genericparam/genericreturntype/genericreturntype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package genericreturntype

type R struct{}
4 changes: 4 additions & 0 deletions generator/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (f *Fake) addImportsFor(typ types.Type) {
f.addImportsFor(t.Elem())
case *types.Named:
if t.Obj() != nil && t.Obj().Pkg() != nil {
typeArgs := t.TypeArgs()
for i := 0; i < typeArgs.Len(); i++ {
f.addImportsFor(typeArgs.At(i))
}
f.Imports.Add(t.Obj().Pkg().Name(), t.Obj().Pkg().Path())
}
case *types.Slice:
Expand Down

0 comments on commit 2c17700

Please sign in to comment.