Skip to content

x/tools/gopls/internal/analysis/modernize: crash in minmax #73566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
adonovan opened this issue May 1, 2025 · 3 comments
Closed

x/tools/gopls/internal/analysis/modernize: crash in minmax #73566

adonovan opened this issue May 1, 2025 · 3 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented May 1, 2025

I got this crash today while running modernize, but don't have time to investigate at this moment:

xtools$ modernize -diff ./internal/...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x104be0014]

goroutine 964 [running]:
golang.org/x/tools/internal/typeparams.CoreType({0x0?, 0x0?})
	/Users/adonovan/w/xtools/internal/typeparams/coretype.go:16 +0x24
golang.org/x/tools/gopls/internal/analysis/modernize.maybeNaN({0x0?, 0x0?})
	/Users/adonovan/w/xtools/gopls/internal/analysis/modernize/minmax.go:234 +0x24
golang.org/x/tools/gopls/internal/analysis/modernize.minmax.minmax.filesUsing.func2.minmax.minmax.filesUsing.func2.Cursor.Children.func3.minmax.minmax.filesUsing.func2-range3.minmax-range1-range4({0x14002defa88?, 0x4c56e18?})
	/Users/adonovan/w/xtools/gopls/internal/analysis/modernize/minmax.go:190 +0x114
golang.org/x/tools/internal/astutil/cursor.Cursor.Preorder.func1(0x140086bd3e0)
	/Users/adonovan/w/xtools/internal/astutil/cursor/cursor.go:129 +0xbc
golang.org/x/tools/gopls/internal/analysis/modernize.minmax-range1(...)
	/Users/adonovan/w/xtools/gopls/internal/analysis/modernize/minmax.go:184
golang.org/x/tools/gopls/internal/analysis/modernize.minmax.minmax.filesUsing.func2-range3(...)
	/Users/adonovan/w/xtools/gopls/internal/analysis/modernize/modernize.go:136
golang.org/x/tools/gopls/internal/analysis/modernize.minmax.minmax.filesUsing.func2.Cursor.Children.func3(...)
	/Users/adonovan/w/xtools/internal/astutil/cursor/cursor.go:422
golang.org/x/tools/gopls/internal/analysis/modernize.minmax.filesUsing.func2(...)
	/Users/adonovan/w/xtools/gopls/internal/analysis/modernize/modernize.go:134
golang.org/x/tools/gopls/internal/analysis/modernize.minmax(0x1400837f420)
	/Users/adonovan/w/xtools/gopls/internal/analysis/modernize/minmax.go:182 +0x268
golang.org/x/tools/gopls/internal/analysis/modernize.run(0x1400837f420)
	/Users/adonovan/w/xtools/gopls/internal/analysis/modernize/modernize.go:87 +0x150
golang.org/x/tools/go/analysis/checker.(*Action).execOnce.func3(...)
	/Users/adonovan/w/xtools/go/analysis/checker/checker.go:367
golang.org/x/tools/go/analysis/checker.(*Action).execOnce(0x140041b8f20)
	/Users/adonovan/w/xtools/go/analysis/checker/checker.go:388 +0x898
sync.(*Once).doSlow(0x0?, 0x0?)
	/Users/adonovan/w/goroot/src/sync/once.go:78 +0xe8
sync.(*Once).Do(...)
	/Users/adonovan/w/goroot/src/sync/once.go:69
golang.org/x/tools/go/analysis/checker.(*Action).exec(...)
	/Users/adonovan/w/xtools/go/analysis/checker/checker.go:265
golang.org/x/tools/go/analysis/checker.execAll.func1(0x0?)
	/Users/adonovan/w/xtools/go/analysis/checker/checker.go:253 +0x4c
created by golang.org/x/tools/go/analysis/checker.execAll in goroutine 1
	/Users/adonovan/w/xtools/go/analysis/checker/checker.go:259 +0x140
xtools$ 
@adonovan adonovan self-assigned this May 1, 2025
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label May 1, 2025
@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. BugReport Issues describing a possible bug in the Go implementation. labels May 1, 2025
@seankhliao seankhliao changed the title gopls/internal/analysis/modernize: crash in minmax x/tools/gopls/internal/analysis/modernize: crash in minmax May 1, 2025
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 1, 2025
@gopherbot gopherbot added this to the Unreleased milestone May 1, 2025
@xieyuschen
Copy link
Member

I recalled this has been fixed in https://go-review.googlesource.com/c/tools/+/662195, and we have guard the input of CoreType won't be nil. Did you try the tip of gopls @adonovan ?

@adonovan
Copy link
Member Author

adonovan commented May 2, 2025

I had used go install ./local/path/to/main.go at tip, but apparently that doesn't actually install anything. Using go build -o exe did the right thing, and the bug does appear to be fixed. Sorry for the false alarm.

@adonovan adonovan closed this as not planned Won't fix, can't repro, duplicate, stale May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants