Consider the following source file
package whatever
type Command[T any] interface {
Execute() T
}
Running the official mock generation tool produces source code that does not compile. The maintainer of golang/mock claims that he has merged PRs that fixes it but building the latest version from the master branch still fails in the same way. Did I mention that he does it >for free?
Fine, whatever, generics considered harmful. What if you have two non-generic interfaces in the same file?
package whatever
type Tool interface {
Use()
}
type Craftsman interface {
Wield(t Tool)
}
func MakeItSo(c Crafsman, t Tool) {
c.Wield(t)
}
If you run mockgen on this file and write a test case for MakeItSo, you will find that it once again does not build because import cycles are not allowed. The only workaround is to put the interfaces in a separate package.
The language and its ecosystem is one giant cargo cult.