go/types, types2: improved constant handling guarded by go1.21 but other inference improvements are not #60566
Labels
FrozenDueToAge
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
The Go 1.21 compiler implements significantly more powerful and precise type inference than Go 1.20. One of the improvements made is for untyped constants (#58671). That change was implemented based on the language version: -lang must be >= go1.21.
produces an error (
default type float64 of 2.0 does not match inferred type int for P
) with -lang=go1.20 but runs fine with -lang >= go1.21.However, there are plenty of other inference improvements that that were made for 1.21 which are accessible even if -lang < go1.21. For instance:
In this case the change and error is not fundamentally different from above: in Go 1.20 we couldn't infer a type argument and now we can. In both these cases one can provide explicit type arguments and make the code compile. Also, all inference improvements are fully backwards-compatible.
I propose that we remove the -lang check for the more lenient constant handling for consistency with the other inference improvements. (Making all improvements -lang dependent is not practical.)
The text was updated successfully, but these errors were encountered: