Closed
Description
(Splitting out of #70815 (comment) on behalf of @spencerschrock.)
Currently at HEAD (44b61a1d174cc06329b20f5de60c2b0c800741a4):
main.go:7:5: if/else statement can be modernized using max
package main
import "fmt"
func main() {
var x, y int
if x <= 0 { // a value of -1 or 0 will use a default value (30)
y = 30
} else {
y = x
}
fmt.Print(y)
}
Applying the suggested fix doesn't yield an equivalent result:
package main
import "fmt"
func main() {
var x, y int
y = max(x, 0)
fmt.Print(y)
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-]gopls/internal/analysis/modernize: minmax generates incorrect transformation[/-][+]x/tools/gopls/internal/analysis/modernize: minmax generates incorrect transformation[/+]gopherbot commentedon Feb 13, 2025
Change https://go.dev/cl/649357 mentions this issue:
gopls/internal/analysis/modernize: fix bug in minmax
gopls/internal/analysis/modernize: fix bug in minmax
7 remaining items