Skip to content

Commit e5fe074

Browse files
adonovangopherbot
authored andcommitted
[gopls-release-branch.0.18] 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 <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> (cherry picked from commit 809cde4) Reviewed-on: https://go-review.googlesource.com/c/tools/+/651236 Reviewed-by: Robert Findley <[email protected]>
1 parent e59d1ba commit e5fe074

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

gopls/internal/analysis/modernize/minmax.go

+1-1
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

+11
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

+11
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)