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 in deslice when completing unknown type in append #38091

chlunde opened this issue Mar 26, 2020 · 1 comment

x/tools/gopls: panic in deslice when completing unknown type in append #38091

chlunde opened this issue Mar 26, 2020 · 1 comment


Copy link

@chlunde chlunde commented Mar 26, 2020

What did you do?

Type t in struct in an append variadic arg for a slice with a type now yet defined.

package bad

func _() {
       a := unknown
       a = append(a, struct) //@complete(")")

What did you expect to see?

Not much

What did you see instead?


Stack trace
panic: runtime error: invalid memory address or nil pointer dereference                                                                                                                                                                        
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x79e7db]                                                                                                                                                                        

goroutine 10025 [running]:
/home/chlunde/opt/gotoolpath/pkg/mod/*completer).builtinArgType(0xc0086f0600, 0xe25040, 0xc000100cd0, 0xc0071bc240, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/home/chlunde/opt/gotoolpath/pkg/mod/ +0x3bb, 0xe25040, 0xc000100cd0, 0xc0071bc240, 0xc01032c160)
/home/chlunde/opt/gotoolpath/pkg/mod/ +0xd1, 0xc00025b4b0, 0xc010ae66c0, 0xc0000c5300, 0x116f, 0x1300, 0xb9e2e2, 0x52, 0xc0101eb990, 0x6, ...)
/home/chlunde/opt/gotoolpath/pkg/mod/ +0x3c7, 0xc010ae66c0, 0xe24f00, 0xc012cc2120, 0xe11560, 0xc012cc20c0, 0x4065a00000000000, 0x4045000000000000, 0x0, 0x0, ...)
/home/chlunde/opt/gotoolpath/pkg/mod/ +0x9eb*Server).completion(0xc0002e6680, 0xe12e60, 0xc010b00450, 0xc010536060, 0x0, 0x0, 0xc01032c000)
/home/chlunde/opt/gotoolpath/pkg/mod/ +0x6b0*Server).Completion(0xc0002e6680, 0xe12e60, 0xc010b00450, 0xc010536060, 0xc010536060, 0x0, 0x0)
/home/chlunde/opt/gotoolpath/pkg/mod/ +0x49, 0xc0002e6680, 0xe12e60, 0xc010b00450, 0xc010a7e1c0, 0xae8c00, 0xe10000)
/home/chlunde/opt/gotoolpath/pkg/mod/ +0x2064*Conn).Run.func1(0xc0075ec4e0, 0xc010a7e1c0, 0xc0002eaba0, 0xe12e60, 0xc010b00450, 0x0, 0x0, 0xc0071500f0)
/home/chlunde/opt/gotoolpath/pkg/mod/ +0x160
created by*Conn).Run

Build info

gopls v0.3.4 v0.3.4 h1:4GC7q/pXQ/tsxHBGVdsMdlB4gCxVC06m/7rIXg1Px4E= h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E= h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= h1:hKrQy/q8/Xivoqgw6nGiz1jqpn1WGBLDcWLZwW0983E= h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA= h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U= h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=


Not sure if this is the right approach ¯\(ツ)

diff --git a/internal/lsp/testdata/lsp/primarymod/bad/bad2.go b/internal/lsp/testdata/lsp/primarymod/bad/bad2.go
new file mode 100644
index 00000000..acce3e45
--- /dev/null
+++ b/internal/lsp/testdata/lsp/primarymod/bad/bad2.go
@@ -0,0 +1,6 @@
+package bad
+func _() {
+       a := unknown
+       a = append(a, struct) //@complete(")")
diff --git a/internal/lsp/testdata/lsp/summary.txt.golden b/internal/lsp/testdata/lsp/summary.txt.golden
index c4e7d68d..ece318e5 100644
--- a/internal/lsp/testdata/lsp/summary.txt.golden
+++ b/internal/lsp/testdata/lsp/summary.txt.golden
@@ -1,6 +1,6 @@
 -- summary --
 CodeLensCount = 2
-CompletionsCount = 237
+CompletionsCount = 238
 CompletionSnippetCount = 75
 UnimportedCompletionsCount = 11
 DeepCompletionsCount = 5
diff --git a/internal/lsp/source/completion_builtin.go b/internal/lsp/source/completion_builtin.go
index d65eb8f4..26c553f0 100644
--- a/internal/lsp/source/completion_builtin.go
+++ b/internal/lsp/source/completion_builtin.go
@@ -64,7 +64,7 @@ func (c *completer) builtinArgType(obj types.Object, call *ast.CallExpr, parentI
                // Check if we are completing the variadic append() param.
                if exprIdx == 1 && len(call.Args) <= 2 {
                        inf.variadicType = deslice(inf.objType)
-               } else if exprIdx > 0 {
+               } else if exprIdx > 0 && inf.objType != nil {
                        // If we are completing an individual element of the variadic
                        // param, "deslice" the expected type.
                        inf.objType = deslice(inf.objType)
@gopherbot gopherbot added this to the Unreleased milestone Mar 26, 2020

This comment has been minimized.

Copy link

@stamblerre stamblerre commented Mar 26, 2020

Thanks for the report! The patch you proposed above sounds reasonable to me - please send us a PR if you're interested in contributing :)

/cc @muirdm

@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.4.0 Mar 26, 2020
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
You can’t perform that action at this time.