Open alexandreLamarre opened 2 years ago
In mockgen.go
GenerateMockInterface:
longTp, shortTp := g.formattedTypeParams(intf, outputPackagePath)
longTp
is initialized as [T notifier.Clonable[notifier.T]]
because :
for i, v := range it.TypeParams {
if i != 0 {
long.WriteString(", ")
short.WriteString(", ")
}
long.WriteString(v.Name)
short.WriteString(v.Name)
long.WriteString(fmt.Sprintf(" %s", v.Type.String(g.packageMap, pkgOverride)))
}
the nested T
in [T notifier.Clonable[T]]
is parsed into ast.NamedType in mockgen/generic_go118.go
and Name()
on NamedType always prefixes the NamedType with the package the NamedType is declared in.
Not very familiar with the codebase, but I would assume that to support nested generic interfaces, we would need to introduce another TypeParam
implementation, e.g, something along the lines of PlaceholderType
or GenericType
. Let me know what you think, I'd be happy to work on this
Consider a source file
notifier.go
we want to mock, with the following pattern :Actual behavior A clear and concise description of what the bug is.
The three following functions are generated
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 benotifier.Clonable[T]
in the function signaturesTo Reproduce Steps to reproduce the behavior
Additional Information
github.com/golang/mock v1.6.1-0.20220512030613-73266f9366fc
Triage Notes for the Maintainers
Seems like a fun one