I'm expecting the compiler to properly infer Uand T types. As there are multiple options for T but only one of them is valid, it should be able to try to deduce U just like it does when using the Ptr[T] or Slice[T] constraint.
What did you see instead?
./prog.go:20:8: cannot infer U (prog.go:15:13)
Go build failed.
You should be able to reproduce this with the go.dev/play link provided above.
The text was updated successfully, but these errors were encountered:
changed the title
affected/package: generics Fail to infer type with only one valid solutionDec 16, 2021
Constraint type inference requires that there's a structural type present in the constraint (the inference part is not yet in the spec, but the generics proposal describes a much). Here we have two types in the constraint and they are different, so there's no structural type.
We're not going to change that for 1.18. Feel free to send out a detailed proposal. Thanks.