Skip to content

Commit 9b2264a

Browse files
committed
gopls/internal/golang/completion: ensure expectedCompositeLiteralType arg is not nil
It was possible for expectedCompositeLiteralType to be given a nil *compLitInfo. Check for nilness outside the offending call site and skip the call. Fixes golang/go#72136. Change-Id: Idc661145ae409a19909e0b4e1f74163acb11f5b5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/659375 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent cfd8cf5 commit 9b2264a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

gopls/internal/golang/completion/completion.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,8 @@ func (c *completer) structLiteralFieldName(ctx context.Context) error {
20012001

20022002
// enclosingCompositeLiteral returns information about the composite literal enclosing the
20032003
// position.
2004+
// It returns nil on failure; for example, if there is no type information for a
2005+
// node on path.
20042006
func enclosingCompositeLiteral(path []ast.Node, pos token.Pos, info *types.Info) *compLitInfo {
20052007
for _, n := range path {
20062008
switch n := n.(type) {
@@ -2565,7 +2567,7 @@ func inferExpectedResultTypes(c *completer, callNodeIdx int) []types.Type {
25652567
switch node := c.path[callNodeIdx+1].(type) {
25662568
case *ast.KeyValueExpr:
25672569
enclosingCompositeLiteral := enclosingCompositeLiteral(c.path[callNodeIdx:], callNode.Pos(), c.pkg.TypesInfo())
2568-
if !wantStructFieldCompletions(enclosingCompositeLiteral) {
2570+
if enclosingCompositeLiteral != nil && !wantStructFieldCompletions(enclosingCompositeLiteral) {
25692571
expectedResults = append(expectedResults, expectedCompositeLiteralType(enclosingCompositeLiteral, callNode.Pos()))
25702572
}
25712573
case *ast.AssignStmt:

0 commit comments

Comments
 (0)