Skip to content
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

gopls/modernize: "for i = range n {}" fix is wrong if there are later uses of i #71952

Closed
Tracked by #71847
adonovan opened this issue Feb 25, 2025 · 1 comment
Closed
Tracked by #71847
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls.

Comments

@adonovan
Copy link
Member

@dethi reports:

I found one additional bug in the transformation of i := 0; for i = 0; i < n; i++ -> for i = range n if i is used outside of the for loop body. See the minimal reproduction: https://go.dev/play/p/9tlB2oilyJn

In particular, the postcondition of the original loop is that i has the value n, whereas for the range loop it has the value n-1.

@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Feb 25, 2025
@adonovan adonovan self-assigned this Feb 25, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/652496 mentions this issue: gopls/internal/analysis/modernize: fix bug in rangeint

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 25, 2025
@golang golang deleted a comment from chingkonglim0815 Feb 28, 2025
@golang golang deleted a comment from chingkonglim0815 Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls.
Projects
None yet
Development

No branches or pull requests

3 participants