mdempsky / gocode

An autocompletion daemon for the Go programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GO 1.11 PANIC - embedded struct field without name?

EmpireJones opened this issue · comments

I'm not exactly sure what other tools gocode depends on, but this functionality works with go 1.10.4, then when I update to go 1.11, followed by vscode updating the following tools, I get a panic when auto-completing the following example (even via the command line).

Tools updated after updating to go 1.11:

  gocode
  gopkgs
  go-outline
  go-symbols
  guru
  gorename
  dlv
  godef
  godoc
  goreturns
  golint
  gomodifytags

Demo code:
src/main.go:

package main

import "service"

type Service struct {
    service.CommonService
}

func (svc *Service) GetName() {
    svc. // TRYING TO AUTO-COMPLETE THIS LINE
}

func main() {}

src/service/service.go:

package service


type CommonService struct {
    Name string
}

Then I ran this command:
./bin/gocode -in='./src/main.go' autocomplete ./src/main.go 123

and I get the following output:

Found 1 candidates:
  PANIC PANIC PANIC

If I run the server via ./bin/gocode -s -debug and make the request via vscode, I get the following panic info:

2018/09/28 01:28:24 Got autocompletion request for '/home/kevin/panic_demo/src/main.go'
2018/09/28 01:28:24 Cursor at: 123
2018/09/28 01:28:24 -------------------------------------------------------
package main

import "service"

type Service struct {
    service.CommonService
}

func (svc *Service) GetName() {
    svc.# // TRYING TO AUTO-COMPLETE THIS LINE
}

func main() {}
2018/09/28 01:28:24 -------------------------------------------------------
2018/09/28 01:28:24 Error parsing input file (outer block):
2018/09/28 01:28:24  /home/kevin/panic_demo/src/main.go:10:9: expected selector or type assertion, found ';'
panic: embedded struct field without name?

goroutine 35 [running]:
runtime/debug.Stack(0xb, 0xc00019b228, 0x1)
	/usr/local/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
main.(*Server).AutoComplete.func1(0xc00014c780)
	/home/kevin/panic_demo/src/github.com/mdempsky/gocode/server.go:72 +0x94
panic(0x82b980, 0x9500e0)
	/usr/local/go/src/runtime/panic.go:513 +0x1b9
github.com/mdempsky/gocode/internal/lookdot.walk(0x955000, 0xc000148850, 0xc000140101, 0xc00019b7f8)
	/home/kevin/panic_demo/src/github.com/mdempsky/gocode/internal/lookdot/lookdot.go:77 +0xaef
github.com/mdempsky/gocode/internal/lookdot.Walk(0xc00019b858, 0xc00019b7f8, 0x7c)
	/home/kevin/panic_demo/src/github.com/mdempsky/gocode/internal/lookdot/lookdot.go:12 +0xd2
github.com/mdempsky/gocode/internal/suggest.(*Config).Suggest(0xc00019ba90, 0xc0001463f0, 0x22, 0xc0001ae000, 0xb3, 0xb3, 0x7b, 0x4ae270, 0xc5eb40, 0x875000, ...)
	/home/kevin/panic_demo/src/github.com/mdempsky/gocode/internal/suggest/suggest.go:47 +0x5ac
main.(*Server).AutoComplete(0xc7cb78, 0xc00017c410, 0xc00014c780, 0x0, 0x0)
	/home/kevin/panic_demo/src/github.com/mdempsky/gocode/server.go:104 +0x210
reflect.Value.call(0xc0001421e0, 0xc00014e038, 0x13, 0x8d22bd, 0x4, 0xc00018cf18, 0x3, 0x3, 0xc00014a240, 0x82bc40, ...)
	/usr/local/go/src/reflect/value.go:447 +0x449
reflect.Value.Call(0xc0001421e0, 0xc00014e038, 0x13, 0xc000043718, 0x3, 0x3, 0x8a2260, 0x8b2101, 0xc00014a140)
	/usr/local/go/src/reflect/value.go:308 +0xa4
net/rpc.(*service).call(0xc00014a0c0, 0xc0000d4500, 0xc000150028, 0xc000150050, 0xc00017e000, 0xc00014c0e0, 0x817a40, 0xc00017c410, 0x16, 0x817a00, ...)
	/usr/local/go/src/net/rpc/server.go:384 +0x14e
created by net/rpc.(*Server).ServeCodec
	/usr/local/go/src/net/rpc/server.go:481 +0x47e

Might be related to #61

Sent with GitHawk

It seems that gocode does not get custom package "service" imported, so the service.CommonService is regarded as a undefined type: a types.Basic but not typs.Named. This cause nameOf returns nil.

This will be fixed by #58 once tests are added to that PR.

Fixed by #58.