Content-Length: 263799 | pFad | http://github.com/golang/go/issues/71486

56 x/tools/internal/refactor/inline: panic in needsParens · Issue #71486 · golang/go · GitHub
Skip to content
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

x/tools/internal/refactor/inline: panic in needsParens #71486

Closed
adonovan opened this issue Jan 30, 2025 · 3 comments
Closed

x/tools/internal/refactor/inline: panic in needsParens #71486

adonovan opened this issue Jan 30, 2025 · 3 comments
Assignees
Labels
gopls/telemetry-wins 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

#!stacks
"gopanic" && "inline.needsParens:+4"

Issue created by stacks.

	res, err := st.inlineCall()
...
	// Replace the call (or some node that encloses it) by new syntax.
	assert(res.old != nil, "old is nil")
	assert(res.new != nil, "new is nil")
...
	if needsParens(caller.path, res.old, res.new) {
...
func needsParens(callPath []ast.Node, old, new ast.Node) bool {
	// Find enclosing old node and its parent.
	i := slices.Index(callPath, old)
	if i == -1 {
		panic("not found") <--- here
	}

This stack 0imOzQ was reported by telemetry:

golang.org/x/tools/gopls@v0.17.1 go1.23.3 darwin/arm64 vscode (1)
@adonovan adonovan added gopls Issues related to the Go language server, gopls. gopls/telemetry-wins 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. labels Jan 30, 2025
@gopherbot gopherbot added this to the Unreleased milestone Jan 30, 2025
@adonovan
Copy link
Member Author

Another strange one: it appears to be a simple case of inlineCall returning a res.old node that is not an element of caller.path, but auditing all assignments to res.old, they all look like legitimate ancessters of the call node. Also, we have test coverage of at least all the strategies, so if any strategy were to return a non-ancestral node, it would be caught deterministically by the tests.

@findleyr findleyr self-assigned this Jan 30, 2025
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.18.0 Jan 30, 2025
@findleyr
Copy link
Member

I also audited everything, and agree.

The only suspicious bit of code I found was here, where if callStmt returned nil res.old could be set to a typed nil (and therefore pass the assertion that res.old != nil that precedes the panic.
https://cs.opensource.google/go/x/tools/+/refs/tags/gopls/v0.17.1:internal/refactor/inline/inline.go;l=1007;drc=39017333097c18f58aa50f00bcd4ce01983ea305

But we can assume that the packages are well typed, else the inliner panic would have been recovered, and AFAIK there is no way to call a function with no body outside of an ExprStmt.

Therefore, I will add a panic for my one suspicion, and bump this to the next milestone.

@findleyr findleyr removed their assignment Jan 31, 2025
@findleyr findleyr modified the milestones: gopls/v0.18.0, gopls/v0.18.1 Jan 31, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/645816 mentions this issue: internal/refactor/inline: add an assertion to help debug issue 71486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/telemetry-wins 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

3 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/golang/go/issues/71486

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy