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)
}

Activity

self-assigned this
on Feb 13, 2025
added
BugReportIssues describing a possible bug in the Go implementation.
gopls/analysisIssues related to running analysis in gopls
on Feb 13, 2025
added
goplsIssues related to the Go language server, gopls.
on Feb 13, 2025
added
RefactoringIssues related to refactoring tools
and removed
goplsIssues related to the Go language server, gopls.
BugReportIssues describing a possible bug in the Go implementation.
on Feb 13, 2025
added this to the gopls/v0.18.0 milestone on Feb 13, 2025
added
BugReportIssues describing a possible bug in the Go implementation.
on Feb 13, 2025
changed the title [-]gopls/internal/analysis/modernize: minmax generates incorrect transformation[/-] [+]x/tools/gopls/internal/analysis/modernize: minmax generates incorrect transformation[/+] on Feb 13, 2025
gopherbot

gopherbot commented on Feb 13, 2025

@gopherbot
Contributor

Change https://go.dev/cl/649357 mentions this issue: gopls/internal/analysis/modernize: fix bug in minmax

added a commit that references this issue on Feb 13, 2025
809cde4
removed this from the gopls/v0.18.0 milestone on Feb 20, 2025

7 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @adonovan@gopherbot@findleyr@gabyhelp

      Issue actions

        x/tools/gopls/internal/analysis/modernize: minmax generates incorrect transformation · Issue #71721 · golang/go