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/gopls: nil Signature (?) deref in Completion #70634

Closed
adonovan opened this issue Dec 2, 2024 · 9 comments
Closed

x/tools/gopls: nil Signature (?) deref in Completion #70634

adonovan opened this issue Dec 2, 2024 · 9 comments
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

adonovan commented Dec 2, 2024

#!stacks
"runtime.sigpanic" && "go/types.(*Signature).Results:=94" && "expectedReturnStmtType"

Issue created by stacks.

// expectedReturnStmtType returns the expected type of a return statement.
// Returns nil if enclosingSig is nil.
func expectedReturnStmtType(enclosingSig *types.Signature, node *ast.ReturnStmt, pos token.Pos) types.Type {
	if enclosingSig != nil {
		if resultIdx := exprAtPos(pos, node.Results); resultIdx < len(node.Results) {
			return enclosingSig.Results().At(resultIdx).Type()
		}
	}
	return nil
}

This stack sZBuvA was reported by telemetry:

golang.org/x/tools/[email protected] go1.23.3 darwin/arm64 other,vscode (10)

Dups: mCLZHw

@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/telemetry-wins labels Dec 2, 2024
@gopherbot gopherbot added this to the Unreleased milestone Dec 2, 2024
@adonovan
Copy link
Member Author

adonovan commented Dec 2, 2024

This is a strange one: the nil deref is dominated by a non-nil check.

@adonovan
Copy link
Member Author

adonovan commented Dec 2, 2024

Closely related to #70636.

@findleyr
Copy link
Member

findleyr commented Dec 2, 2024

There's definitely a bug here though. The condition checked is against len(node.Results), but in the presence of ill typed code, the signature length need not match the length of the return statement.

if resultIdx := exprAtPos(pos, node.Results); resultIdx < len(node.Results) {
    return enclosingSig.Results().At(resultIdx).Type()
}

My guess is that the compiler is somehow reporting the panic from the wrong call.

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.17.0 Dec 2, 2024
@findleyr
Copy link
Member

findleyr commented Dec 2, 2024

Aha, well the bug I spotted is exactly #70636.

Therefore, I'm not sure what this bug is. If it were a bug in the compiler's pclntab, I'd have expected it to always report the wrong function.

@findleyr
Copy link
Member

findleyr commented Dec 2, 2024

For triaging: we expect that this is really a dupe of #70636, somehow obscured by a misreported stack from the compiler. I'll leave this in the v0.17.0 milestone, but if it does not recur in the next prerelease, where #70636 is fixed, I think we can safely transfer this to a compiler/runtime bug.

@findleyr findleyr added FixPending Issues that have a fix which has not yet been reviewed or submitted. and removed FixPending Issues that have a fix which has not yet been reviewed or submitted. labels Dec 2, 2024
@findleyr findleyr modified the milestones: gopls/v0.17.0, gopls/v0.18.0 Dec 5, 2024
@findleyr
Copy link
Member

findleyr commented Dec 5, 2024

FWIW, I can reproduce this exact crash with [email protected], and the repro from my fix for #70636. Therefore, this is a dupe.

@findleyr findleyr closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2024
@adonovan
Copy link
Member Author

adonovan commented Dec 5, 2024

https://go.dev/cl/634038 is a reproducer for the problem that doesn't depend on telemetry.

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

4 participants