internal/lsp/source/completion: avoid invalid AST in enclosingSignature

Guard against the panic in golang/go#49397, though it should not be
possible with well-formed AST.

Updates golang/go#49397

Change-Id: I3428504a4cfd361c1f51316d8c9aeee4aa9d7f42
Reviewed-on: https://go-review.googlesource.com/c/tools/+/364675
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Robert Findley 2021-11-17 11:20:46 -05:00
parent 8122e49f73
commit 7d6c71f28a
1 changed files with 6 additions and 0 deletions

View File

@ -1694,6 +1694,12 @@ func enclosingFunction(path []ast.Node, info *types.Info) *funcInfo {
}
case *ast.FuncLit:
if typ, ok := info.Types[t]; ok {
if sig, _ := typ.Type.(*types.Signature); sig == nil {
// golang/go#49397: it should not be possible, but we somehow arrived
// here with a non-signature type, most likely due to AST mangling
// such that node.Type is not a FuncType.
return nil
}
return &funcInfo{
sig: typ.Type.(*types.Signature),
body: t.Body,