Skip to content

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

Closed
@adonovan

Description

@adonovan
#!stacks
("bug.Reportf" || "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

Variant after the function was renamed:

func lookupDocLinkSymbol(pkg *cache.Package, pgf *parsego.File, name string) types.Object {
	scope := pkg.Types().Scope()

	prefix, suffix, _ := strings.Cut(name, ".")

	// Try treating the prefix as a package name,
	// allowing for non-renaming and renaming imports.
	fileScope := pkg.TypesInfo().Scopes[pgf.File]
	if fileScope == nil {
		// This is theoretically possible if pgf is a GoFile but not a
		// CompiledGoFile. However, we do not know how to produce such a package
		// without using an external GoPackagesDriver.
		// See if this is the source of golang/go#70635
		if slices.Contains(pkg.CompiledGoFiles(), pgf) {
			bug.Reportf("missing file scope for compiled file")  //  <--- reached
		} else {
			bug.Reportf("missing file scope for non-compiled file")
		}

This stack l9BGAQ was reported by telemetry:

golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (1)

Dups: z79pXw p3-DZQ oHmaZg 5F-J2A UxUyAQ

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/memory-corruption"can't happen" gopls crashes (races, unsafe, miscompile, runtime bugs, faulty HW)gopls/telemetry-wins

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions