-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spec, go/types, types2: restore Go 1.20 unification when compiling for Go 1.20 #61903
Comments
I believe this is a consequence of #60377. |
It sounds like we should at least restore the old behavior when go.mod says "go 1.20". |
The fix needs to land on the main branch first (i.e., where Go 1.22 development happens), and then it can be backported to release-branch.go1.21. I'll move this to Go1.22 milestone and create a backport issue to track the fix for Go 1.21.1. @gopherbot Please backport to Go 1.21 with the rationale @rsc provided:
|
Backport issue(s) opened: #61930 (for 1.21). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
The 1.20 behavior was incorrect. For instance, taking the (slightly pared down, but equivalent) example from above: package main
type T[P any] interface{}
func f[P any](T[P]) {}
func main() {
var x T[int]
f(x)
} which works with Go1.20 but doesn't work with Go1.21 (because any arbitrary type argument would be acceptable for type parameter package main
type T[P any] interface{}
func f[P any](T[P], P) {}
func main() {
var x T[int]
var y string
f(x, y)
} Now this code doesn't work with Go1.20 because the inferred argument for We can try to restore the incorrect behavior for 1.20, and it will "fix" this particular case, but it will also re-introduce a bug. |
Change https://go.dev/cl/519855 mentions this issue: |
I wouldn't say that it introduces bugs so much as it preserves them, which is what compatibility tends to be all about. 😄 |
Change https://go.dev/cl/520195 mentions this issue: |
…erence" This reverts CL 514715. This will make it easier to make interface inference conditional based on the current language version. For #61903. Change-Id: I07820c861d6ebfd04899e41eb4123f26af2da1ee Reviewed-on: https://go-review.googlesource.com/c/go/+/520195 Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Robert Griesemer <[email protected]>
What version of Go are you using (
go version
)?1.21.0
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?I can reproduce this issue using playground only
What did you do?
use code
What did you expect to see?
no error as it is with go 1.20 https://go.dev/play/p/CEVB_qbwsPu?v=goprev
What did you see instead?
error
./prog.go:13:5: cannot infer T (prog.go:7:10)
https://go.dev/play/p/CEVB_qbwsPuThe text was updated successfully, but these errors were encountered: