[tools] go/analysis/passes/modernize: avoid invalid stringscut fixes in multi-assignments

0 views
Skip to first unread message

Madeline Kalil (Gerrit)

unread,
Apr 14, 2026, 4:18:08 PM (19 hours ago) Apr 14
to Chencheng Jiang, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, golang...@luci-project-accounts.iam.gserviceaccount.com, Alan Donovan, golang-co...@googlegroups.com

Madeline Kalil submitted the change

Change information

Commit message:
go/analysis/passes/modernize: avoid invalid stringscut fixes in multi-assignments

The stringscut modernizer could rewrite Index calls that appear in
multi-value assignments, producing invalid code such as:

ret, before, _, ok := 0, strings.Cut(s, sub)

Restrict the fix to single-name, single-value definitions, and add a
regression test covering the multi-assignment case.

Fixes golang/go#78643
Change-Id: I959ecd0eff812e0d262932952ed344667d63f9e4
Reviewed-by: Alan Donovan <adon...@google.com>
Reviewed-by: Madeline Kalil <mka...@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, 33 insertions(+), 0 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: I959ecd0eff812e0d262932952ed344667d63f9e4
Gerrit-Change-Number: 766600
Gerrit-PatchSet: 4
Gerrit-Owner: Chencheng Jiang <dorb...@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages