Skip to content

Commit 7d6c71f

Browse files
committed
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 <[email protected]> Run-TryBot: Robert Findley <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 8122e49 commit 7d6c71f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

internal/lsp/source/completion/completion.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,6 +1694,12 @@ func enclosingFunction(path []ast.Node, info *types.Info) *funcInfo {
16941694
}
16951695
case *ast.FuncLit:
16961696
if typ, ok := info.Types[t]; ok {
1697+
if sig, _ := typ.Type.(*types.Signature); sig == nil {
1698+
// golang/go#49397: it should not be possible, but we somehow arrived
1699+
// here with a non-signature type, most likely due to AST mangling
1700+
// such that node.Type is not a FuncType.
1701+
return nil
1702+
}
16971703
return &funcInfo{
16981704
sig: typ.Type.(*types.Signature),
16991705
body: t.Body,

0 commit comments

Comments
 (0)