Closed
Description
commit 8ea0120
The type inference algorithm does not work when the actual parameter is a concrete type and the formal parameter is a generic interface type. It looks like the type inference description in the proposal doesn't cover interfaces, but I suspect it should.
https://go2goplay.golang.org/p/C53vOfwA9vq
package main
type S struct {}
func (S) M() byte {
return 0
}
type I[T any] interface {
M() T
}
func F[T any](x I[T]) {
x.M()
}
func main() {
F(S{})
}
This fails with the error:
prog.go2:18:4: type S of (S literal) does not match I[T] (cannot infer T)
FWIW type interfence doesn't work when the interface argument is a type parameter either, but I can't work out if that's covered by the proposal or not: https://go2goplay.golang.org/p/pAouk3xkmOX
func F[X I[T], T any](x X) {
x.M()
}