Skip to content

Commit 809cde4

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/analysis/modernize: fix bug in minmax
Wrong operator. D'oh. + test Fixes golang/go#71721 Change-Id: Ia7fe314df07afa9a9de63c2b6031e678755e9d56 Reviewed-on: https://go-review.googlesource.com/c/tools/+/649357 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent ab04c19 commit 809cde4

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

gopls/internal/analysis/modernize/minmax.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func minmax(pass *analysis.Pass) {
5757
if equalSyntax(lhs, lhs2) {
5858
if equalSyntax(rhs, a) && equalSyntax(rhs2, b) {
5959
sign = +sign
60-
} else if equalSyntax(rhs2, a) || equalSyntax(rhs, b) {
60+
} else if equalSyntax(rhs2, a) && equalSyntax(rhs, b) {
6161
sign = -sign
6262
} else {
6363
return

gopls/internal/analysis/modernize/testdata/src/minmax/minmax.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ func nopeAssignHasIncrementOperator() {
9292
}
9393
print(y)
9494
}
95+
96+
// Regression test for https://github.com/golang/go/issues/71721.
97+
func nopeNotAMinimum(x, y int) int {
98+
// A value of -1 or 0 will use a default value (30).
99+
if x <= 0 {
100+
y = 30
101+
} else {
102+
y = x
103+
}
104+
return y
105+
}

gopls/internal/analysis/modernize/testdata/src/minmax/minmax.go.golden

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,14 @@ func nopeAssignHasIncrementOperator() {
6969
}
7070
print(y)
7171
}
72+
73+
// Regression test for https://github.com/golang/go/issues/71721.
74+
func nopeNotAMinimum(x, y int) int {
75+
// A value of -1 or 0 will use a default value (30).
76+
if x <= 0 {
77+
y = 30
78+
} else {
79+
y = x
80+
}
81+
return y
82+
}

0 commit comments

Comments
 (0)