-
Notifications
You must be signed in to change notification settings - Fork 18k
go/types, types2: scope for :=
-defined range iteration variables is incorrect
#51437
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
Comments
Another repro example which does not involve In 1.17, this yields |
CC @randall77 |
Marking as a release blocker because this is a compiler crash on valid code. |
Seems there's disagreement between old and new typechecker, cc @griesemer @mdempsky If I read the Go spec correctly, the old typechecker behavior seems correct. The |
@cuonglm
Never mind. I see what you mean. Investigating. |
Simpler reproducer: package p
type T struct{}
func (T) m() []T { return nil }
func f(x T) {
for _, x := range func() []T {
return x.m()
}() {
_ = x
}
} Renaming the |
The following program should type-check but doesn't: package p
type T struct{}
func (T) m() []int { return nil }
func f(x T) {
for _, x := range func() []int {
return x.m()
}() {
_ = x
}
} Error:
Looks like a 0-day bug to me. |
@griesemer So old typechecker works correctly. Seems that we need to fix |
Yeah. Fixes forthcoming. |
Change https://go.dev/cl/389594 mentions this issue: |
:=
-defined range iteration variables is incorrect
Change https://go.dev/cl/390018 mentions this issue: |
…ariables declared by range clause Also correct scope position for such variables. Adjusted some comments. Fixes #51437. Change-Id: Ic49a1459469c8b2c7bc24fe546795f7d56c67cb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/389594 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Robert Findley <rfindley@google.com> (cherry picked from commit d3fe4e1) Reviewed-on: https://go-review.googlesource.com/c/go/+/390018 Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It reproduces with the latest release candidate.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/cO3Omj1diPk?v=gotip
What did you expect to see?
The same result as running with go1.17.7: "Hello, 世界"
https://go.dev/play/p/cO3Omj1diPk
What did you see instead?
The text was updated successfully, but these errors were encountered: