[tools] go/analysis/passes/modernize: stringscut: detect use in multi-assign

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Apr 29, 2026, 4:25:03 PM (20 hours ago) Apr 29
to Madeline Kalil, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Alan Donovan, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
go/analysis/passes/modernize: stringscut: detect modifying use in all assignments

In the stringscut modernizer, we skip suggesting a fix if any of the uses of the input variable "s" (after the call to Index) are modifying uses, as a fix would not preserve the existing semantics.

When looking at a use of "s" in an assignment, we previously only check Lhs[0]. If the "s" is modified in a multi-assignment but is not the first variable in the list, we will miss this modifying use and may end up suggesting an invalid fix.

Instead, we should treat any use of "s" on the lhs as a modifying use.
Change-Id: I4ba58d720f2df2db3fca71927d0704cbb9e8813d
Commit-Queue: Alan Donovan <adon...@google.com>
Reviewed-by: Alan Donovan <adon...@google.com>
Auto-Submit: Alan Donovan <adon...@google.com>
Files:
  • M go/analysis/passes/modernize/stringscut.go
  • M go/analysis/passes/modernize/testdata/src/stringscut/stringscut.go
  • M go/analysis/passes/modernize/testdata/src/stringscut/stringscut.go.golden
Change size: S
Delta: 3 files changed, 26 insertions(+), 7 deletions(-)
Branch: refs/heads/master
Submit Requirements:
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: I4ba58d720f2df2db3fca71927d0704cbb9e8813d
Gerrit-Change-Number: 766541
Gerrit-PatchSet: 5
Gerrit-Owner: Madeline Kalil <mka...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages