-
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 calling generic fn which has related type params (reproduces with 1.21 and 1.20, not at tip) #64759
Comments
This looks like a typechecker issue. My understanding of 804d786's commit message is that this should be valid. (Not sure if there's more permanent documentation describing the expected behavior here; for example, I don't see any mention of the backwards compatibility logic for M >= 21 at https://pkg.go.dev/cmd/go. /cc @rsc) /cc @griesemer @findleyr |
I cannot reproduce this. With
and $ cat x.go
//go:build go1.18
package repro
func genericfn[S ~[]E, E any](s S) S {
return s
}
func do() []string {
return genericfn([]string{})
} compilation succeeds:
To double-check, I added a print statement in the relevant code section, and it does indeed select Please verify that you are indeed using a new compiler version. |
@griesemer I know that Go 1.22 is not affected. I said as much in the issue report. The issue is reproducible on Go 1.21.5. |
@corhere Ah. Apologies for not reading more carefully. Hm, the relevant code didn't exist for 1.21.5 I believe. Not sure if we can easily/should backport. Reopening, to determine next steps. |
Confirming that this issue exists for go1.21.5. Smaller reproducer source code: //go:build go1.18
package p
func f[S ~[]E, E any](S) {}
func _() {
f([]string{})
} |
Change https://go.dev/cl/555275 mentions this issue: |
@griesemer This appears to reproduce with Go 1.20.13 as well, is that right? If so, our backport policy is to support last two Go versions equally (see here). Will the backport CL you've prepared work on |
Change https://go.dev/cl/555295 mentions this issue: |
Change https://go.dev/cl/555296 mentions this issue: |
We will fix this issue in the 1.22 branch (the code is incorrect there as well, though the issue seems to be masked) and then backport. |
@gopherbot Please consider this for backport to 1.21 and 1.20, this causes a compilation failure for code that chooses to select a future Go version in one of its source files. |
Backport issue(s) opened: #65052 (for 1.20), #65053 (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. |
Accurate position information for embedded types in interfaces is crucial to identify the corresponding source file, and with that the Go language version associated with that file. (The position information is also important for proper error messages.) Before this CL, the position information for embedded types was discarded after type set computation, in the assumption that it was not needed anymore. However, substitutions that update the interface may lead to repeated type set computations which then won't have the correct position information. This CL does preserve the position information for embedded types until the end of type checking (cleanup phase), and also copy the position information during a substitution of the interface. The respective bug (#64759) doesn't seem to appear in 1.22 (most likely because it's hidden by some of the changes made with respect to the file version logic), but the existing code is still wrong. The backport of this code to 1.21 and 1.20 fixes the issue in those releases. For #64759. Change-Id: I80f4004c9d79cb02eac6739c324c477706615102 Reviewed-on: https://go-review.googlesource.com/c/go/+/555296 Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Change https://go.dev/cl/555415 mentions this issue: |
Forward-compatibility (specifically, the ability to have a The fix for this issue does not need to (and cannot) be backported to 1.20. |
This was fixed at tip (1.22). |
… interface embeddings Accurate position information for embedded types in interfaces is crucial to identify the corresponding source file, and with that the Go language version associated with that file. (The position information is also important for proper error messages.) Before this CL, the position information for embedded types was discarded after type set computation, in the assumption that it was not needed anymore. However, substitutions that update the interface may lead to repeated type set computations which then won't have the correct position information. This CL does preserve the position information for embedded types until the end of type checking (cleanup phase), and also copy the position information during a substitution of the interface. The respective bug (#64759) doesn't seem to appear in 1.22 (most likely because it's hidden by some of the changes made with respect to the file version logic), but the existing code is still wrong. The backport of this code to 1.21 and 1.20 fixes the issue in those releases. For #64759. Fixes #65053. Change-Id: I80f4004c9d79cb02eac6739c324c477706615102 Reviewed-on: https://go-review.googlesource.com/c/go/+/555296 Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/555415 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Accurate position information for embedded types in interfaces is crucial to identify the corresponding source file, and with that the Go language version associated with that file. (The position information is also important for proper error messages.) Before this CL, the position information for embedded types was discarded after type set computation, in the assumption that it was not needed anymore. However, substitutions that update the interface may lead to repeated type set computations which then won't have the correct position information. This CL does preserve the position information for embedded types until the end of type checking (cleanup phase), and also copy the position information during a substitution of the interface. The respective bug (golang#64759) doesn't seem to appear in 1.22 (most likely because it's hidden by some of the changes made with respect to the file version logic), but the existing code is still wrong. The backport of this code to 1.21 and 1.20 fixes the issue in those releases. For golang#64759. Change-Id: I80f4004c9d79cb02eac6739c324c477706615102 Reviewed-on: https://go-review.googlesource.com/c/go/+/555296 Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
Avoid golang/go#64759 Signed-off-by: Rob Murray <rob.murray@docker.com>
Avoid golang/go#64759 Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com> Signed-off-by: Rob Murray <rob.murray@docker.com>
Avoid golang/go#64759 Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com> Signed-off-by: Rob Murray <rob.murray@docker.com>
Avoid golang/go#64759 Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com> Signed-off-by: Rob Murray <rob.murray@docker.com>
Avoid golang/go#64759 Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com> Signed-off-by: Rob Murray <rob.murray@docker.com>
Avoid golang/go#64759 Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com> Signed-off-by: Rob Murray <rob.murray@docker.com>
Go version
go version go1.21.5 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
Compilation succeeds. It succeeds with
go version devel go1.22-b60bf8f8e1 Fri Dec 15 19:35:21 2023 +0000 darwin/amd64
.What did you see instead?
The text was updated successfully, but these errors were encountered: