[tools] go/analysis/passes/modernize: slicescontains: check for side effects

0 views
Skip to first unread message

Madeline Kalil (Gerrit)

unread,
May 11, 2026, 12:59:22 PM (11 hours ago) May 11
to 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: slicescontains: check for side effects

We should avoid suggesting a fix if the needle or predicate may
have side effects. Otherwise, the program behavior may change.
For example, in converting from a loop to slices.ContainsFunc,
the needle expression goes from being evaluated once per
iteration to only once before iteration.

Fixes golang/go#77564
Change-Id: I3db190b0e5d65cb9eeaca8f0e9c2e1a2aa65669b
Reviewed-by: Alan Donovan <adon...@google.com>
Files:
  • M go/analysis/passes/modernize/slicescontains.go
  • M go/analysis/passes/modernize/testdata/src/slicescontains/slicescontains.go
  • M go/analysis/passes/modernize/testdata/src/slicescontains/slicescontains.go.golden
Change size: S
Delta: 3 files changed, 30 insertions(+), 6 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: I3db190b0e5d65cb9eeaca8f0e9c2e1a2aa65669b
Gerrit-Change-Number: 776800
Gerrit-PatchSet: 3
Gerrit-Owner: Madeline Kalil <mka...@google.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