You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BugReportIssues describing a possible bug in the Go implementation.goplsIssues related to the Go language server, gopls.ToolsThis label describes issues relating to any tools in the x/tools repository.
package modernizebugrepo
import"time"vardefaultInterval=60*time.Secondfuncfoo(interval time.Duration) time.Duration {
vari time.Duration// imagine this was actually a part of an already initialized structure and isn't set to defaultIntervalifinterval<=0 {
i=defaultInterval
} else {
i=interval
}
returni
}
I ran go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test .
What did you see happen?
The code was "modernized" into a call to max which got rid of the defaultInterval all together.
package modernizebugrepo
import"time"vardefaultInterval=60*time.Secondfuncfoo(interval time.Duration) time.Duration {
vari time.Duration// imagine this was actually a part of an already initialized structure and isn't set to defaultIntervali=max(interval, 0)
returni
}
What did you expect to see?
In this case I am guessing modernizer needs to leave the code alone. There may be some magic refactoring for this to try to use max (or min) but it really probably worth it.
The text was updated successfully, but these errors were encountered:
gopherbot
added
Tools
This label describes issues relating to any tools in the x/tools repository.
gopls
Issues related to the Go language server, gopls.
labels
Feb 21, 2025
BugReportIssues describing a possible bug in the Go implementation.goplsIssues related to the Go language server, gopls.ToolsThis label describes issues relating to any tools in the x/tools repository.
Go version
go1.24.0
Output of
go env
in your module/workspace:What did you do?
Given this code:
I ran
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test .
What did you see happen?
The code was "modernized" into a call to max which got rid of the defaultInterval all together.
What did you expect to see?
In this case I am guessing modernizer needs to leave the code alone. There may be some magic refactoring for this to try to use max (or min) but it really probably worth it.
The text was updated successfully, but these errors were encountered: