-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Open
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.Issues related to the Go language server, gopls.
Milestone
Description
Steps to reproduce
go.mod
module main
go 1.24.5 //1.22+
main.go
package main
func main() {
for i, v := range []string{"a", "b", "c"} {
i := i
v := v
println(i, v)
}
}
Run
modernize -fix ./...
Only the first redeclaration is removed. The second remains:
for i, v := range []string{"a", "b", "c"} {
v := v
println(i, v)
}
And whats even worse, if you run the tool again, it removes the remaining redeclaration, leading to a different result on the second run. This is unexpected and unacceptable for a static analysis tool - it should be idempotent and consistent across runs.
This issue also affected the gopls
source itself, which is how I discovered it. See this change:
https://go-review.googlesource.com/c/tools/+/665215/1/gopls/internal/golang/references.go
There is a test case that expects this behavior, but I believe it is flawed.
The correct behavior should be to remove both redundant redeclarations in a single pass.
Metadata
Metadata
Assignees
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.Issues related to the Go language server, gopls.