Open firelizzard18 opened 5 months ago
CC @griesemer
I ran into an inference issue that is very similar to OP's issue:
type X struct {}
func (x X) M() int { return 42 }
func CallM1[T interface{M() R}, R any](t T) R {
return t.M()
}
func CallM2[T interface{X; M() R}, R any](t T) R {
return t.M()
}
func main() {
CallM1(X{}) // OK
CallM2(X{}) // cannot infer R
}
I wasn't expecting CallM2
to fail inference on R
because of the added T=X
constraint.
Go version
go version go1.22.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/fVSkvTEgYx_1
What did you see happen?
Inference succeeds on all three calls.
What did you expect to see?
Inference succeeds on the first two but fails on the third. If inference of B for
withPtr
orwithFoo
failed, it would make sense. But inference succeeds on both of those so it's surprising and confusing that it fails forwithBoth
.