[tools] go/analysis/passes/modernize: don't consider selects for min/max pass

5 views
Skip to first unread message

Daniel Morsing (Gerrit)

unread,
Feb 18, 2026, 10:33:37 AM (9 days ago) Feb 18
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Daniel Morsing has uploaded the change for review

Commit message

go/analysis/passes/modernize: don't consider selects for min/max pass

Fixes golang/go#77671.
Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964

Change diff

diff --git a/go/analysis/passes/modernize/minmax.go b/go/analysis/passes/modernize/minmax.go
index a77ed83..b4b8dba 100644
--- a/go/analysis/passes/modernize/minmax.go
+++ b/go/analysis/passes/modernize/minmax.go
@@ -147,6 +147,13 @@
lhs0 := fassign.Lhs[0]
rhs0 := fassign.Rhs[0]

+ // If the assignment occurs within a select
+ // comms clause (like "case lhs0 := <-rhs0:"),
+ // there's no way of rewriting it into a min/max call.
+ if prev.ParentEdgeKind() == edge.CommClause_Comm {
+ return
+ }
+
if astutil.EqualSyntax(lhs, lhs0) {
if astutil.EqualSyntax(rhs, a) && (astutil.EqualSyntax(rhs0, b) || astutil.EqualSyntax(lhs0, b)) {
sign = +sign
diff --git a/go/analysis/passes/modernize/testdata/src/minmax/minmax.go b/go/analysis/passes/modernize/testdata/src/minmax/minmax.go
index 74d84b2..4ef6723 100644
--- a/go/analysis/passes/modernize/testdata/src/minmax/minmax.go
+++ b/go/analysis/passes/modernize/testdata/src/minmax/minmax.go
@@ -169,3 +169,14 @@
}
return x
}
+
+// Regression test for https://go.dev/issue/77671
+func selectComm(ch chan int) int {
+ select {
+ case n := <-ch:
+ if n > 100 {
+ n = 100
+ }
+ return n
+ }
+}
diff --git a/go/analysis/passes/modernize/testdata/src/minmax/minmax.go.golden b/go/analysis/passes/modernize/testdata/src/minmax/minmax.go.golden
index f8dc94b..96b4965 100644
--- a/go/analysis/passes/modernize/testdata/src/minmax/minmax.go.golden
+++ b/go/analysis/passes/modernize/testdata/src/minmax/minmax.go.golden
@@ -168,3 +168,14 @@
}
return x
}
+
+// Regression test for https://go.dev/issue/77671
+func selectComm(ch chan int) int {
+ select {
+ case n := <-ch:
+ if n > 100 {
+ n = 100
+ }
+ return n
+ }
+}

Change information

Files:
  • M go/analysis/passes/modernize/minmax.go
  • M go/analysis/passes/modernize/testdata/src/minmax/minmax.go
  • M go/analysis/passes/modernize/testdata/src/minmax/minmax.go.golden
Change size: S
Delta: 3 files changed, 29 insertions(+), 0 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
Gerrit-Change-Number: 746541
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Morsing <daniel....@gmail.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Feb 23, 2026, 11:44:03 AM (4 days ago) Feb 23
to Daniel Morsing, goph...@pubsubhelper.golang.org, Madeline Kalil, golang-co...@googlegroups.com
Attention needed from Daniel Morsing

Alan Donovan voted and added 1 comment

Votes added by Alan Donovan

Code-Review+2

1 comment

Patchset-level comments
File-level comment, Patchset 1 (Latest):
Alan Donovan . resolved

Thanks for this fix. I feel like this is one of a whole category of grammar restrictions that we need to document in my (long awaiting) checklist for analyzer writers. Another example (of many) is that `if STMT; EXPR { ... }` can hold only certain kinds of STMT.

Open in Gerrit

Related details

Attention is currently required from:
  • Daniel Morsing
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
Gerrit-Change-Number: 746541
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Morsing <daniel....@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-CC: Madeline Kalil <mka...@google.com>
Gerrit-Attention: Daniel Morsing <daniel....@gmail.com>
Gerrit-Comment-Date: Mon, 23 Feb 2026 16:44:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Feb 23, 2026, 11:44:26 AM (4 days ago) Feb 23
to Daniel Morsing, goph...@pubsubhelper.golang.org, Madeline Kalil, golang-co...@googlegroups.com
Attention needed from Daniel Morsing

Alan Donovan voted and added 1 comment

Votes added by Alan Donovan

Auto-Submit+1
Commit-Queue+1

1 comment

Patchset-level comments
Alan Donovan . resolved

Thanks for this fix. I feel like this is one of a whole category of grammar restrictions that we need to document in my (long awaiting) checklist for analyzer writers. Another example (of many) is that `if STMT; EXPR { ... }` can hold only certain kinds of STMT.

Alan Donovan

*long awaited

Open in Gerrit

Related details

Attention is currently required from:
  • Daniel Morsing
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
Gerrit-Change-Number: 746541
Gerrit-PatchSet: 1
Gerrit-Owner: Daniel Morsing <daniel....@gmail.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-CC: Madeline Kalil <mka...@google.com>
Gerrit-Attention: Daniel Morsing <daniel....@gmail.com>
Gerrit-Comment-Date: Mon, 23 Feb 2026 16:44:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Alan Donovan <adon...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

David Chase (Gerrit)

unread,
Feb 23, 2026, 3:43:25 PM (4 days ago) Feb 23
to Daniel Morsing, goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, Madeline Kalil, golang-co...@googlegroups.com
Attention needed from Daniel Morsing

David Chase voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Daniel Morsing
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
    Gerrit-Change-Number: 746541
    Gerrit-PatchSet: 1
    Gerrit-Owner: Daniel Morsing <daniel....@gmail.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-CC: Madeline Kalil <mka...@google.com>
    Gerrit-Attention: Daniel Morsing <daniel....@gmail.com>
    Gerrit-Comment-Date: Mon, 23 Feb 2026 20:43:19 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Gopher Robot (Gerrit)

    unread,
    Feb 23, 2026, 4:01:46 PM (4 days ago) Feb 23
    to Daniel Morsing, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, David Chase, Go LUCI, Alan Donovan, Madeline Kalil, golang-co...@googlegroups.com

    Gopher Robot submitted the change

    Change information

    Commit message:
    go/analysis/passes/modernize: don't consider selects for min/max pass

    Fixes golang/go#77671.
    Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
    Auto-Submit: Alan Donovan <adon...@google.com>
    Reviewed-by: Alan Donovan <adon...@google.com>
    Reviewed-by: David Chase <drc...@google.com>
    Files:
    • M go/analysis/passes/modernize/minmax.go
    • M go/analysis/passes/modernize/testdata/src/minmax/minmax.go
    • M go/analysis/passes/modernize/testdata/src/minmax/minmax.go.golden
    Change size: S
    Delta: 3 files changed, 29 insertions(+), 0 deletions(-)
    Branch: refs/heads/master
    Submit Requirements:
    • requirement satisfiedCode-Review: +2 by Alan Donovan, +1 by David Chase
    • 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: I704fc5327218c5041fa56c29b92f23376a6a6964
    Gerrit-Change-Number: 746541
    Gerrit-PatchSet: 2
    Gerrit-Owner: Daniel Morsing <daniel....@gmail.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-CC: Madeline Kalil <mka...@google.com>
    open
    diffy
    satisfied_requirement

    David Chase (Gerrit)

    unread,
    Feb 26, 2026, 3:31:06 PM (24 hours ago) Feb 26
    to goph...@pubsubhelper.golang.org, Daniel Morsing, golang-co...@googlegroups.com

    David Chase has uploaded the change for review

    Commit message

    [internal-branch.go1.26-vendor] go/analysis/passes/modernize: don't consider selects for min/max pass

    Updates golang/go#77804.


    Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
    Reviewed-on: https://go-review.googlesource.com/c/tools/+/746541
    Auto-Submit: Alan Donovan <adon...@google.com>
    Reviewed-by: Alan Donovan <adon...@google.com>
    LUCI-TryBot-Result: Go LUCI <golang...@luci-project-accounts.iam.gserviceaccount.com>
    Reviewed-by: David Chase <drc...@google.com>
    (cherry picked from commit 5c2a45909eac659b93659e0853eb43738b672c33)

    Change diff

    diff --git a/go/analysis/passes/modernize/minmax.go b/go/analysis/passes/modernize/minmax.go
    index 23a0977..812bad8 100644

    Change information

    Files:
    • M go/analysis/passes/modernize/minmax.go
    • M go/analysis/passes/modernize/testdata/src/minmax/minmax.go
    • M go/analysis/passes/modernize/testdata/src/minmax/minmax.go.golden
    Change size: S
    Delta: 3 files changed, 29 insertions(+), 0 deletions(-)
    Open in Gerrit

    Related details

    Attention set is empty
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newchange
    Gerrit-Project: tools
    Gerrit-Branch: internal-branch.go1.26-vendor
    Gerrit-Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
    Gerrit-Change-Number: 749502
    Gerrit-PatchSet: 1
    Gerrit-Owner: David Chase <drc...@google.com>
    Gerrit-CC: Daniel Morsing <daniel....@gmail.com>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    David Chase (Gerrit)

    unread,
    Feb 26, 2026, 3:31:32 PM (24 hours ago) Feb 26
    to Daniel Morsing, goph...@pubsubhelper.golang.org, Alan Donovan, Mark Freeman, golang-co...@googlegroups.com
    Attention needed from Alan Donovan and Mark Freeman

    David Chase voted Commit-Queue+1

    Commit-Queue+1
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alan Donovan
    • Mark Freeman
    Submit Requirements:
    • requirement is not satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: tools
    Gerrit-Branch: internal-branch.go1.26-vendor
    Gerrit-Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
    Gerrit-Change-Number: 749502
    Gerrit-PatchSet: 1
    Gerrit-Owner: David Chase <drc...@google.com>
    Gerrit-Reviewer: Alan Donovan <adon...@google.com>
    Gerrit-Reviewer: David Chase <drc...@google.com>
    Gerrit-Reviewer: Mark Freeman <markf...@google.com>
    Gerrit-CC: Daniel Morsing <daniel....@gmail.com>
    Gerrit-Attention: Alan Donovan <adon...@google.com>
    Gerrit-Attention: Mark Freeman <markf...@google.com>
    Gerrit-Comment-Date: Thu, 26 Feb 2026 20:31:29 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Daniel Morsing (Gerrit)

    unread,
    5:55 AM (9 hours ago) 5:55 AM
    to David Chase, goph...@pubsubhelper.golang.org, Go LUCI, Alan Donovan, Mark Freeman, golang-co...@googlegroups.com
    Attention needed from Alan Donovan, David Chase and Mark Freeman

    Daniel Morsing added 1 comment

    File go/analysis/passes/modernize/minmax.go
    Line 153, Patchset 1 (Latest): if prev.ParentEdgeKind() == edge.CommClause_Comm {
    Daniel Morsing . unresolved
    ```suggestion
    if ek, _ := prev.ParentEdge(); ek == edge.CommClause_Comm {
    ```
    Since the vendor copy is from before we added `Cursor.ParentEdgeKind`
    Open in Gerrit

    Related details

    Attention is currently required from:
    • Alan Donovan
    • David Chase
    • Mark Freeman
    Submit Requirements:
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      • requirement is not satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: tools
      Gerrit-Branch: internal-branch.go1.26-vendor
      Gerrit-Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
      Gerrit-Change-Number: 749502
      Gerrit-PatchSet: 1
      Gerrit-Owner: David Chase <drc...@google.com>
      Gerrit-Reviewer: Alan Donovan <adon...@google.com>
      Gerrit-Reviewer: David Chase <drc...@google.com>
      Gerrit-Reviewer: Mark Freeman <markf...@google.com>
      Gerrit-CC: Daniel Morsing <daniel....@gmail.com>
      Gerrit-Attention: David Chase <drc...@google.com>
      Gerrit-Attention: Alan Donovan <adon...@google.com>
      Gerrit-Attention: Mark Freeman <markf...@google.com>
      Gerrit-Comment-Date: Fri, 27 Feb 2026 10:55:42 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      unsatisfied_requirement
      open
      diffy

      Alan Donovan (Gerrit)

      unread,
      9:54 AM (5 hours ago) 9:54 AM
      to David Chase, Daniel Morsing, goph...@pubsubhelper.golang.org, Go LUCI, Mark Freeman, golang-co...@googlegroups.com
      Attention needed from Daniel Morsing, David Chase and Mark Freeman

      Alan Donovan voted and added 1 comment

      Votes added by Alan Donovan

      Code-Review+2

      1 comment

      File go/analysis/passes/modernize/minmax.go
      Line 153, Patchset 1 (Latest): if prev.ParentEdgeKind() == edge.CommClause_Comm {
      Daniel Morsing . resolved
      ```suggestion
      if ek, _ := prev.ParentEdge(); ek == edge.CommClause_Comm {
      ```
      Since the vendor copy is from before we added `Cursor.ParentEdgeKind`
      Alan Donovan

      Acknowledged

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Daniel Morsing
      • David Chase
      • Mark Freeman
      Submit Requirements:
      • requirement satisfiedCode-Review
      • requirement satisfiedNo-Unresolved-Comments
      • requirement satisfiedReview-Enforcement
      • requirement is not satisfiedTryBots-Pass
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: tools
      Gerrit-Branch: internal-branch.go1.26-vendor
      Gerrit-Change-Id: I704fc5327218c5041fa56c29b92f23376a6a6964
      Gerrit-Change-Number: 749502
      Gerrit-PatchSet: 1
      Gerrit-Owner: David Chase <drc...@google.com>
      Gerrit-Reviewer: Alan Donovan <adon...@google.com>
      Gerrit-Reviewer: David Chase <drc...@google.com>
      Gerrit-Reviewer: Mark Freeman <markf...@google.com>
      Gerrit-CC: Daniel Morsing <daniel....@gmail.com>
      Gerrit-Attention: David Chase <drc...@google.com>
      Gerrit-Attention: Daniel Morsing <daniel....@gmail.com>
      Gerrit-Attention: Mark Freeman <markf...@google.com>
      Gerrit-Comment-Date: Fri, 27 Feb 2026 14:54:17 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Daniel Morsing <daniel....@gmail.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages