Skip to content

x/tools/gopls/internal/analysis/modernize: minmax generates incorrect transformation #71721

Closed
@adonovan

Description

@adonovan

(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

BugReportIssues describing a possible bug in the Go implementation.RefactoringIssues related to refactoring toolsgopls/analysisIssues related to running analysis in gopls

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions