Skip to content

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

Closed
@adonovan

Description

@adonovan

@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.

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions