Skip to content

Commit 81fce1a

Browse files
committed
internal/lsp/source: fix panic in addFieldItems
I have no idea what I did to trigger this, but I got a panic in this codepath. Since this is for completion, it should be OK to simply make this code defensive, without fully understanding the cause. Here's the panic: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0xc570f3] goroutine 5914644 [running]: golang.org/x/tools/internal/lsp/source/completion.(*completer).addFieldItems(0xc0996ee240, 0x1032020, 0xc0dd21e2a0, 0xc0b99b26f0) /usr/local/google/home/rfindley/src/tools/internal/lsp/source/completion/completion.go:1065 +0x193 Change-Id: I82350b30172ead95b6611962c2e040cc49259dc2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/254697 Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]> (cherry picked from commit 2350fe8) Reviewed-on: https://go-review.googlesource.com/c/tools/+/254794
1 parent 839a5bb commit 81fce1a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

internal/lsp/source/completion/completion.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,9 @@ func (c *completer) addFieldItems(ctx context.Context, fields *ast.FieldList) {
10511051
continue
10521052
}
10531053
obj := c.pkg.GetTypesInfo().ObjectOf(name)
1054+
if obj == nil {
1055+
continue
1056+
}
10541057

10551058
// if we're in a field comment/doc, score that field as more relevant
10561059
score := stdScore

0 commit comments

Comments
 (0)