go version devel go1.18-c2397905e0 Sat Nov 13 03:33:55 2021 +0000 linux/amd64
I ran this code: https://gotipplay.golang.org/p/D0f2z4hHt4W
package main
func main() {
}
type I[F any] interface {
Q(*F)
}
func G[F any]() I[any] {
return g[F]{}
}
type g[F any] struct{}
func (*g[F]) Q(*any) {}
It correctly diagnoses that g[F] doesn't implement the required interface (because Q is implemented on the pointer type, not the value type), but the error message that I see looks wrong:
./prog.go:11:9: cannot use g[F]{} (value of type g[F]) as type I[interface{}] in return statement:
g[F] does not implement I[interface{}] (wrong type for Q method)
have Q^^%!s(<nil>)
want Q(*interface{})
I ran this code: https://gotipplay.golang.org/p/D0f2z4hHt4W
It correctly diagnoses that
g[F]doesn't implement the required interface (becauseQis implemented on the pointer type, not the value type), but the error message that I see looks wrong: