Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: panic if subdirectories have files with different package #40043

sorenisanerd opened this issue Jul 4, 2020 · 4 comments


Copy link

@sorenisanerd sorenisanerd commented Jul 4, 2020

What did you do?

During some refactoring I added a comment and gopls crashed. I managed to narrow it down to the fact that I accidentally had two files in the same directory with different packages. I have autocompletion within comments enabled in VSCode.

It only seems to apply in subdirectories. has steps to reproduce. It wasn't 100% reproducible. It seemed to be most reliably reproducible if I opened VSCode afresh (with a directory tree as found in that repo) and then tried adding a comment.

What did you expect to see?

gopls shouldn't crash.

What did you see instead?

gopls panicked

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x7bc3a3]

goroutine 226 [running]:*completer).populateCommentCompletions(0xc0001083c0, 0xeae040, 0xc000398f60, 0xc0004bbc40)
	/home/soren/src/tools/internal/lsp/source/completion.go:763 +0x363, 0xc000398f60, 0xec39e0, 0xc0001be500, 0xeb1dc0, 0xc0003987e0, 0x4000000000000000, 0x4024000000000000, 0x0, 0x0, ...)
	/home/soren/src/tools/internal/lsp/source/completion.go:542 +0xb7e*Server).completion(0xc0001be200, 0xeadfc0, 0xc0000823c0, 0xc000398f00, 0x0, 0x0, 0xc00052d290)
	/home/soren/src/tools/internal/lsp/completion.go:27 +0x6b9*Server).Completion(0xc0001be200, 0xeadfc0, 0xc0000823c0, 0xc000398f00, 0xc000398f00, 0x0, 0x0)
	/home/soren/src/tools/internal/lsp/server_gen.go:24 +0x49, 0xc0000823c0, 0xecc440, 0xc0001be200, 0xc000433020, 0xeae200, 0xc000082340, 0x0, 0x0, 0xbfb85daf83e61bc2)
	/home/soren/src/tools/internal/lsp/protocol/tsserver.go:255 +0x2606, 0xc0000823c0, 0xc000433020, 0xeae200, 0xc000082340, 0x0, 0x0)
	/home/soren/src/tools/internal/lsp/protocol/protocol.go:62 +0xc0, 0xc0000823c0, 0xc000433020, 0xeae200, 0xc000082340, 0x0, 0x0)
	/home/soren/src/tools/internal/lsp/lsprpc/lsprpc.go:509 +0x43a, 0xc0000823c0, 0xc0002de600, 0xeae200, 0xc000082340, 0x1ee9b0001ee8b, 0x1eea30001eea1)
	/home/soren/src/tools/internal/jsonrpc2/handler.go:35 +0xd3, 0xc000326a50, 0xc0001aaca0, 0xeadfc0, 0xc0000823c0, 0xc0002de600, 0xeae200, 0xc000082340)
	/home/soren/src/tools/internal/jsonrpc2/handler.go:103 +0x86
created by
	/home/soren/src/tools/internal/jsonrpc2/handler.go:100 +0x171
[Error - 12:14:22 AM] Connection to server got closed. Server will not be restarted.

Build info master h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ= h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= => ../ h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8= h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

Go info

go version go1.13.8 linux/amd64

Copy link

@gopherbot gopherbot commented Jul 4, 2020

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@gopherbot gopherbot added this to the Unreleased milestone Jul 4, 2020
Copy link

@sorenisanerd sorenisanerd commented Jul 4, 2020 returns nil, and then on line 763, we call obj.Name() which causes the panic. Adding a simple "if obj == nil { continue; }" would do the trick, but I'm pretty sure something more clever should happen if someone accidentally has a directory with files with different package names.

Copy link

@sorenisanerd sorenisanerd commented Jul 5, 2020

Submitted a (naïve) patch for this problem:

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.5.0 Jul 6, 2020
Copy link

@gopherbot gopherbot commented Jul 6, 2020

Change mentions this issue: internal/lsp/source: handle nil pointer in comment completions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants