Skip to content

Commit

Permalink
internal/lsp/source/completion: avoid invalid AST in enclosingSignature
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
findleyr committed Nov 17, 2021
1 parent 8122e49 commit 7d6c71f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/lsp/source/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7d6c71f

Please sign in to comment.