Skip to content

Commit ffc2075

Browse files
committed
internal/lsp: fix nil pointer in hover when (types.Object).Pkg() is nil
We haven't been able to reproduce this scenario, but it may be possible when the user is in a broken state. Avoid panicking by gating every use of obj.Pkg() with nil checks. Fixes golang/go#44300 Change-Id: Ia0c56a7fd5d6b89795dded1efdf05838f3de8209 Reviewed-on: https://go-review.googlesource.com/c/tools/+/292671 Trust: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent fca8992 commit ffc2075

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/lsp/source/hover.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ func HoverIdentifier(ctx context.Context, i *IdentifierInfo) (*HoverInformation,
187187
}
188188
}
189189
}
190+
if obj.Pkg() == nil {
191+
event.Log(ctx, fmt.Sprintf("nil package for %s", obj))
192+
return h, nil
193+
}
190194
h.importPath = obj.Pkg().Path()
191195
h.LinkPath = h.importPath
192196
if mod, version, ok := moduleAtVersion(h.LinkPath, i); ok {

0 commit comments

Comments
 (0)