[tools] go/analysis/passes/modernize: forvar: handle "if v := v; cond {"

1 view
Skip to first unread message

Alan Donovan (Gerrit)

unread,
Nov 11, 2025, 12:09:04 PM (yesterday) Nov 11
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Robert Findley, Peter Weinberger, Michael Matloob, Gopher Robot, golang-co...@googlegroups.com

Alan Donovan submitted the change

Change information

Commit message:
go/analysis/passes/modernize: forvar: handle "if v := v; cond {"

Some analyzers' (especially stditerator's) fixes result
in redundant v := v assignments, often as the "init" part of
an if statement. This change causes the forvar analyzer to
clean them up when the if statement is the sole statement
of the loop body.

+ test

For golang/go#76241
For golang/go#76240
Change-Id: I327d8726b0d2439a5cc55765acefdfa463282728
Reviewed-by: Robert Findley <rfin...@google.com>
Files:
  • M go/analysis/passes/modernize/forvar.go
  • M go/analysis/passes/modernize/testdata/src/forvar/forvar.go
  • M go/analysis/passes/modernize/testdata/src/forvar/forvar.go.golden
Change size: M
Delta: 3 files changed, 74 insertions(+), 24 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Robert Findley
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I327d8726b0d2439a5cc55765acefdfa463282728
Gerrit-Change-Number: 719360
Gerrit-PatchSet: 4
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Peter Weinberger <p...@google.com>
Gerrit-Reviewer: Robert Findley <rfin...@google.com>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Michael Matloob <mat...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages