x/tools/gopls/internal/analysis/modernize: range over int rule doesn't consider potential slice appends #73022
Labels
gopls
Issues related to the Go language server, gopls.
ToolProposal
Issues describing a requested change to a Go tool or command-line program.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
Go version
go version go1.24.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I have an insertion ordered map implementation; a subset of it is:
The loop here is explicitly a plain for loop such that the len is reevaluated each iteration, so that adding new entries to the map still yield them.
What did you see happen?
Modernizer reports that the plain for loop could be turned into an int range loop:
What did you expect to see?
Potentially no suggestion of a range over int, since iterating over a mutable slice has differing behavior. However, this case is certainly rare, most people don't do this.
(Mainly I'm worried for the potential future where modernizers are run by
go vet
or similar and thus cannot be ignored.)The text was updated successfully, but these errors were encountered: