x/tools/gopls: Hover: panic in lookup{ObjectByName,DocLinkSymbol}
Closed this issue · 20 comments
#!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) // <--- panicVariant 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:
crash/crashruntime.gopanic:+69runtime.panicmem:=262runtime.sigpanic:+19go/types.(*Scope).Lookup:+10golang.org/x/tools/gopls/internal/golang.lookupObjectByName:+4golang.org/x/tools/gopls/internal/golang.parseDocLink:+58golang.org/x/tools/gopls/internal/golang.hover:+43golang.org/x/tools/gopls/internal/golang.Hover:+4golang.org/x/tools/gopls/internal/server.(*server).Hover:+30golang.org/x/tools/gopls/internal/protocol.serverDispatch:+335golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.16.1 go1.23.0 linux/amd64 vscode (1)
Dups: z79pXw p3-DZQ oHmaZg 5F-J2A UxUyAQ 1qaY1Q 7fS6aA jVkbpg wt4MLQ 9Xt7NQ z93tjA
Related Issues and Documentation
- x/tools/gopls: crash in Hover (telemetry) #69362
- x/tools/gopls: panic in hover #52211 (closed)
- x/tools/gopls: FindFileInPackage nil pointer dereference #38100 (closed)
- x/tools/gopls: crash in packageReferences (reported by telemetry) #66250 (closed)
- x/tools/gopls: automated issue report (crash) #44300 (closed)
- x/tools/gopls: crash in signature help on error.Error #63578 (closed)
- x/tools/gopls: automated issue report (crash) #48492 (closed)
- gopls: automated issue report (crash) #40464 (closed)
- x/tools/gopls: panic in mod.hoverOnModuleStatement #59077 (closed)
- x/tools/gopls: automated issue report (crash) #40449 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
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).
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.
Change https://go.dev/cl/633095 mentions this issue: gopls/internal/golang: avoid crash in lookupDocLinkSymbol
Change https://go.dev/cl/633707 mentions this issue: gopls/internal/golang: avoid crash in lookupDocLinkSymbol
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.
This stack z79pXw was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35golang.org/x/tools/gopls/internal/util/bug.Reportf:+1golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+14golang.org/x/tools/gopls/internal/golang.parseDocLink:+58golang.org/x/tools/gopls/internal/golang.hover:+78golang.org/x/tools/gopls/internal/golang.Hover:+4golang.org/x/tools/gopls/internal/server.(*server).Hover:+30golang.org/x/tools/gopls/internal/protocol.serverDispatch:+335golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.17.1 go1.23.2 windows/amd64 vscode (1)
This stack p3-DZQ was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35golang.org/x/tools/gopls/internal/util/bug.Reportf:+1golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+16golang.org/x/tools/gopls/internal/golang.parseDocLink:+58golang.org/x/tools/gopls/internal/golang.hover:+78golang.org/x/tools/gopls/internal/golang.Hover:+4golang.org/x/tools/gopls/internal/server.(*server).Hover:+30golang.org/x/tools/gopls/internal/protocol.serverDispatch:+335golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.17.1 go1.23.4 linux/amd64 vscode (1)
No time to look into this one. Bumping to v0.18.1.
This stack oHmaZg was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35golang.org/x/tools/gopls/internal/util/bug.Reportf:+1golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+14golang.org/x/tools/gopls/internal/golang.parseDocLink:+58golang.org/x/tools/gopls/internal/golang.docLinkDefinition:+1golang.org/x/tools/gopls/internal/golang.Definition:+53golang.org/x/tools/gopls/internal/server.(*server).Definition:+19golang.org/x/tools/gopls/internal/protocol.serverDispatch:+215golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.18.1 go1.23.6 darwin/amd64 vscode (1)
This stack 5F-J2A was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35golang.org/x/tools/gopls/internal/util/bug.Reportf:+1golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+16golang.org/x/tools/gopls/internal/golang.parseDocLink:+58golang.org/x/tools/gopls/internal/golang.docLinkDefinition:+1golang.org/x/tools/gopls/internal/golang.Definition:+53golang.org/x/tools/gopls/internal/server.(*server).Definition:+19golang.org/x/tools/gopls/internal/protocol.serverDispatch:+215golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3runtime.goexit:+0
golang.org/x/tools/gopls@v0.18.1 go1.23.7 darwin/arm64 other (1)
This stack UxUyAQ was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35,+0x412golang.org/x/tools/gopls/internal/util/bug.Reportf:+1,+0x24golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+14,+0x45egolang.org/x/tools/gopls/internal/golang.parseDocLink:+54,+0x373golang.org/x/tools/gopls/internal/golang.hover:+78,+0x5b4golang.org/x/tools/gopls/internal/golang.Hover:+4,+0xbegolang.org/x/tools/gopls/internal/server.(*server).Hover:+30,+0x3aagolang.org/x/tools/gopls/internal/protocol.serverDispatch:+335,+0xe99golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x908golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xc5golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x95runtime.goexit:+0,+0x0
golang.org/x/tools/gopls@v0.19.1 go1.24.4 linux/amd64 vscode (1)
Change https://go.dev/cl/684615 mentions this issue: gopls/internal/golang: reproduce various edge cases of issue 69616
This stack 1qaY1Q was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35,+0x412golang.org/x/tools/gopls/internal/util/bug.Reportf:+1,+0x24golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+14,+0x45egolang.org/x/tools/gopls/internal/golang.parseDocLink:+54,+0x373golang.org/x/tools/gopls/internal/golang.docLinkDefinition:+1,+0x44golang.org/x/tools/gopls/internal/golang.Definition:+53,+0x2begolang.org/x/tools/gopls/internal/server.(*server).Definition:+19,+0x50egolang.org/x/tools/gopls/internal/protocol.serverDispatch:+215,+0x26e1golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x908golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xc5golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x95runtime.goexit:+0,+0x0
golang.org/x/tools/gopls@v0.19.1 go1.24.3 windows/amd64 vscode (1)
This stack 7fS6aA was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35,+0x393golang.org/x/tools/gopls/internal/util/bug.Reportf:+1,+0x27golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+14,+0x423golang.org/x/tools/gopls/internal/golang.parseDocLink:+54,+0x33bgolang.org/x/tools/gopls/internal/golang.docLinkDefinition:+1,+0x3bgolang.org/x/tools/gopls/internal/golang.Definition:+53,+0x1f3golang.org/x/tools/gopls/internal/server.(*server).Definition:+19,+0x3d7golang.org/x/tools/gopls/internal/protocol.serverDispatch:+215,+0x204fgolang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x73golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x68fgolang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xbfgolang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x8fruntime.goexit:+0,+0x3
golang.org/x/tools/gopls@v0.19.1 go1.24.4 darwin/arm64 other (1)
This stack jVkbpg was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35,+0x35bgolang.org/x/tools/gopls/internal/util/bug.Reportf:+1,+0x52golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+16,+0x498golang.org/x/tools/gopls/internal/golang.parseDocLink:+54,+0x3c4golang.org/x/tools/gopls/internal/golang.docLinkDefinition:+1,+0x42golang.org/x/tools/gopls/internal/golang.Definition:+53,+0x367golang.org/x/tools/gopls/internal/server.(*server).Definition:+19,+0x510golang.org/x/tools/gopls/internal/protocol.serverDispatch:+215,+0x2b3agolang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x83golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x1c3golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xb1golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x91runtime.goexit:+0,+0x0
golang.org/x/tools/gopls@v0.19.1 go1.24.2 windows/386 vscode (1)
This stack wt4MLQ was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35,+0x393golang.org/x/tools/gopls/internal/util/bug.Reportf:+1,+0x27golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+16,+0x443golang.org/x/tools/gopls/internal/golang.parseDocLink:+54,+0x33bgolang.org/x/tools/gopls/internal/golang.hover:+78,+0x4f3golang.org/x/tools/gopls/internal/golang.Hover:+4,+0x8bgolang.org/x/tools/gopls/internal/server.(*server).Hover:+30,+0x29bgolang.org/x/tools/gopls/internal/protocol.serverDispatch:+335,+0xc57golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x73golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x68fgolang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xbfgolang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x8fruntime.goexit:+0,+0x3
golang.org/x/tools/gopls@v0.19.1 go1.24.4 darwin/arm64 vscode (1)
This stack 9Xt7NQ was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35,+0x412golang.org/x/tools/gopls/internal/util/bug.Reportf:+1,+0x24golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+16,+0x479golang.org/x/tools/gopls/internal/golang.parseDocLink:+54,+0x373golang.org/x/tools/gopls/internal/golang.hover:+78,+0x5b4golang.org/x/tools/gopls/internal/golang.Hover:+4,+0xbegolang.org/x/tools/gopls/internal/server.(*server).Hover:+30,+0x3aagolang.org/x/tools/gopls/internal/protocol.serverDispatch:+335,+0xe99golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x84golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x908golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xc5golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x95runtime.goexit:+0,+0x0
golang.org/x/tools/gopls@v0.19.1 go1.24.4 linux/amd64 vscode (1)
This stack z93tjA was reported by telemetry:
gopls/buggolang.org/x/tools/gopls/internal/util/bug.report:+35,+0x393golang.org/x/tools/gopls/internal/util/bug.Reportf:+1,+0x27golang.org/x/tools/gopls/internal/golang.lookupDocLinkSymbol:+16,+0x443golang.org/x/tools/gopls/internal/golang.parseDocLink:+54,+0x33bgolang.org/x/tools/gopls/internal/golang.docLinkDefinition:+1,+0x3bgolang.org/x/tools/gopls/internal/golang.Definition:+53,+0x1f3golang.org/x/tools/gopls/internal/server.(*server).Definition:+19,+0x3d7golang.org/x/tools/gopls/internal/protocol.serverDispatch:+215,+0x204fgolang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func4:+5,+0x73golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func5:+52,+0x68fgolang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2,+0xbfgolang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3,+0x8fruntime.goexit:+0,+0x3
golang.org/x/tools/gopls@v0.19.1 go1.24.3 darwin/arm64 vscode (1)