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: Hover: panic in lookup{ObjectByName,DocLinkSymbol} #69616

Open
adonovan opened this issue Sep 24, 2024 · 7 comments
Open

x/tools/gopls: Hover: panic in lookup{ObjectByName,DocLinkSymbol} #69616

adonovan opened this issue Sep 24, 2024 · 7 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 Sep 24, 2024

#!stacks
"runtime.sigpanic" && ("lookupObjectByName" || "lookupDocLinkSymbol")

Issue created by stacks.

func lookupObjectByName(pkg *cache.Package, pgf *parsego.File, name string) types.Object {
	scope := pkg.Types().Scope()
	fileScope := pkg.TypesInfo().Scopes[pgf.File]
	pkgName, suffix, _ := strings.Cut(name, ".")
	obj, ok := fileScope.Lookup(pkgName).(*types.PkgName) // <--- panic

This stack l9BGAQ was reported by telemetry:

golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (1)
@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 Sep 24, 2024
@adonovan
Copy link
Member Author

This is mysterious. The crash is in go/types.(*Scope).Lookup on this line:

func (s *Scope) Lookup(name string) Object {
	obj := resolve(name, s.elems[name])
	if obj == universeAnyAlias && !aliasAny() { // <---------- panic
		return universeAnyNoAlias
	}
	return obj
}

but the only way that line can panic (short of a compiler error that causes the wrong line to be reported) is if obj is a types.Object value of the same concrete type as universeAnyAlias and that concrete type does not support == comparison. However, universeAnyAlias clearly has type *TypeName, a pointer, which supports == comparison. (And presumably resolve also returns only pointers to various struct types).

@findleyr
Copy link
Member

I do not understand how this crash is possible, and so suggest that we move it to the next milestone and see if it reoccurs in v0.17.0.

@findleyr findleyr modified the milestones: gopls/v0.17.0, gopls/v0.18.0 Nov 14, 2024
@adonovan
Copy link
Member Author

@dr2chase Got any ideas how this crash could possibly occur?

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633095 mentions this issue: gopls/internal/golang: avoid crash in lookupDocLinkSymbol

gopherbot pushed a commit to golang/tools that referenced this issue Dec 2, 2024
Avoid a theoretical crash in lookupDocLinkSymbol (nee
lookupObjectByName), with a refining bug report.

For golang/go#69616

Change-Id: I5305583c541eb54bb89bed1dc680c9b0e93b90d9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/633095
Reviewed-by: Alan Donovan <adonovan@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/633707 mentions this issue: gopls/internal/golang: avoid crash in lookupDocLinkSymbol

@findleyr
Copy link
Member

findleyr commented Dec 5, 2024

I was just looking through my telemetry data, and saw that I encountered this crash 3 times on 12/2 (I hadn't noticed the crashes), so it must be reachable without a GOPACKAGESDRIVER.

Unfortunately, logs were lost.

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