-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/compile: //go:build file version ignored when using generic function from package "slices" in Go 1.21 #66064
Comments
Does this has anything to do with That looks like a Go 2 proposal to me. |
The priority of It is true that this is a "slices" unrelated problem. |
Why? I lack the insight, so please help me out. In any case, I've run into this because of Docker dependencies. What basically happens is that there are always non-mod indirect dependencies. If the Go 1 toolchain breaks than this is a severe issue when not being able to use the existing code. You can't update the whole world ... or can you? |
This looks like a |
Actually, was respecting per-file Go versions a feature itself added in 1.22? |
CC @golang/compiler |
The error is coming from the type checker. Go 1.21 did introduce the ability to upgrade the language version per file, so I would expect this to work. Investigating. |
Related to #64759 which addressed another aspect of the same problem. In that issue, we had missing position information for embedded elements of interfaces in the same package. In this issue we have missing position information for an imported type. |
Analysis: During type-checking, the method func (t *Interface) Empty() bool { return t.typeSet().IsAll() } is invoked which calls Furthermore, because the type in question here is imported, we don't have position information in the first place for embedded elements. In fact we shouldn't do a version check at all in this case. |
cc: @findleyr for visibility |
Change https://go.dev/cl/571075 mentions this issue: |
… embedded types of imported interfaces Imported interfaces don't have position information for embedded types. When computing the type set of such interfaces, doing a version check may fail because it will rely on the Go version of the current package. We must not do a version check for features of types from imported packages - those types have already been typechecked and are "correct". The version check code does look at packages to avoid such incorrect version checks, but we don't have the package information available in an interface type (divorced from its object). Instead, for now rely on the fact that imported interfaces don't have position information for embedded types: if the position is unknown, don't do a version check. We may want to assert that positions are known in all other cases, but since this is an older release, don't add such additional changes to avoid introducing other bugs. Fixes #66064. Change-Id: I773d57e5410c3d4a911ab3e018b3233c2972b3c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/571075 Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
Closing as fixed in the 1.21 branch. |
Change https://go.dev/cl/571137 mentions this issue: |
Reopened. CL reverted. Will re-submit later. Thanks. |
@gopherbot please backport this to Go 1.21 release. This causes build failure for valid Go code. We'll re-apply CL 571075. |
Backport issue(s) opened: #66326 (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. |
Hi @griesemer what is the status of this bug with respect to fixes on the release branches? Are there any CLs that need to be submitted? Saw comment by @cherrymui about how there was a revert, so wanted to check (wearing my release interrupts hat). Thanks. |
I don't know what the status is at the moment. @cherrymui mentioned that she will re-submit. |
Thanks. I will look into it then... |
Change https://go.dev/cl/574736 mentions this issue: |
… embedded types of imported interfaces [This is a re-apply of CL 571075] Imported interfaces don't have position information for embedded types. When computing the type set of such interfaces, doing a version check may fail because it will rely on the Go version of the current package. We must not do a version check for features of types from imported packages - those types have already been typechecked and are "correct". The version check code does look at packages to avoid such incorrect version checks, but we don't have the package information available in an interface type (divorced from its object). Instead, for now rely on the fact that imported interfaces don't have position information for embedded types: if the position is unknown, don't do a version check. We may want to assert that positions are known in all other cases, but since this is an older release, don't add such additional changes to avoid introducing other bugs. Fixes #66326. Updates #66064. Change-Id: I158cf51aa382f85d612ab958ba4b591de1c5fdb2 Reviewed-on: https://go-review.googlesource.com/c/go/+/574736 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Go version
go version go1.21.7 linux/amd64
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/-yiceeveEDz?v=goprev
Details
What did you see happen?
Go 1.21:
Go 1.22:
What did you expect to see?
I expect the program to type-check successfully on Go 1.21, same as it does with Go 1.22.
This issue is making it impossible to use packages in non-module repositories which use the
slices
ormaps
packages with Go modules as the synthesized go.mod file has an implied language version of go1.16.The text was updated successfully, but these errors were encountered: