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: segfault when renaming variable to error #37963

Closed
Jesse-Bakker opened this issue Mar 20, 2020 · 3 comments
Closed

x/tools/gopls: segfault when renaming variable to error #37963

Jesse-Bakker opened this issue Mar 20, 2020 · 3 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@Jesse-Bakker
Copy link

Jesse-Bakker commented Mar 20, 2020

What did you do?

Start with:
https://play.golang.org/p/D9f3gVB1v_t
Then try to rename the variable a to error:

{  id = 2,  jsonrpc = "2.0",  method = "textDocument/rename",  params = {    newName = "error",    position = {      character = 7,      line = 3    },    textDocument = {      uri = "file:///tmp/hello/hello.go"    }  }}

What did you expect to see?

The variable a renamed to error

What did you see instead?

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

goroutine 137 [running]:
go/types.(*Package).Scope(...)
go/types/package.go:41
golang.org/x/tools/internal/lsp/source.lexicalLookup(0xc00007f7c0, 0xc000484fd8, 0x5, 0xe7, 0xc00007f7c0, 0xe25460, 0xc00007f860)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/rename_check.go:261 +0xc2
golang.org/x/tools/internal/lsp/source.(*renamer).checkInLexicalScope.func2(0xc0003d0dc0, 0xc00007f7c0, 0x5)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/rename_check.go:220 +0xb7
golang.org/x/tools/internal/lsp/source.forEachLexicalRef.func1(0xe059a0, 0xc0003d0dc0, 0xc000310b00)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/rename_check.go:302 +0x593
go/ast.inspector.Visit(0xc00046e320, 0xe059a0, 0xc0003d0dc0, 0x0, 0x0)
go/ast/walk.go:373 +0x3a
go/ast.Walk(0xe021c0, 0xc00046e320, 0xe059a0, 0xc0003d0dc0)
go/ast/walk.go:52 +0x66
go/ast.walkExprList(0xe021c0, 0xc00046e320, 0xc0000d6170, 0x1, 0x1)
go/ast/walk.go:26 +0x9e
go/ast.Walk(0xe021c0, 0xc00046e320, 0xe050a0, 0xc0002e4780)
go/ast/walk.go:206 +0x2111
go/ast.walkStmtList(0xe021c0, 0xc00046e320, 0xc0003d0e00, 0x2, 0x2)
go/ast/walk.go:32 +0x9e
go/ast.Walk(0xe021c0, 0xc00046e320, 0xe052e0, 0xc000391dd0)
go/ast/walk.go:224 +0x1adf
go/ast.Walk(0xe021c0, 0xc00046e320, 0xe05860, 0xc000391ec0)
go/ast/walk.go:344 +0xd98
go/ast.walkDeclList(0xe021c0, 0xc00046e320, 0xc0000d6190, 0x1, 0x1)
go/ast/walk.go:38 +0x9e
go/ast.Walk(0xe021c0, 0xc00046e320, 0xe057e0, 0xc0000be400)
go/ast/walk.go:353 +0x264e
go/ast.Inspect(...)
go/ast/walk.go:385
golang.org/x/tools/internal/lsp/source.forEachLexicalRef(0xe12e20, 0xc0003c6690, 0xe232a0, 0xc0000bc370, 0xe25460, 0xc00007f860, 0xc000095780, 0xc000311601)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/rename_check.go:335 +0x17d
golang.org/x/tools/internal/lsp/source.(*renamer).checkInLexicalScope(0xc0001c0960, 0xe25460, 0xc00007f860, 0xe232a0, 0xc0000bc370)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/rename_check.go:214 +0xe8
golang.org/x/tools/internal/lsp/source.(*renamer).checkInLocalScope(0xc0001c0960, 0xe25460, 0xc00007f860)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/rename_check.go:144 +0x95
golang.org/x/tools/internal/lsp/source.(*renamer).check(0xc0001c0960, 0xe25460, 0xc00007f860)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/rename_check.go:49 +0x1e7
golang.org/x/tools/internal/lsp/source.Rename(0xe12e20, 0xc0003c6690, 0xe24ec0, 0xc0002fc060, 0xe11520, 0xc0003894a0, 0x4008000000000000, 0x401c000000000000, 0xc000484fd8, 0x5, ...)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/source/rename.go:126 +0x5eb
golang.org/x/tools/internal/lsp.(*Server).rename(0xc0002d9700, 0xe12e20, 0xc000387ef0, 0xc000286900, 0x0, 0x0, 0xc000276580)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/rename.go:19 +0xfd
golang.org/x/tools/internal/lsp.(*Server).Rename(0xc0002d9700, 0xe12e20, 0xc000387ef0, 0xc000286900, 0xc000286900, 0x0, 0x0)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/server_gen.go:152+0x49
golang.org/x/tools/internal/lsp/protocol.serverHandler.Deliver(0xe2d300, 0xc0002d9700, 0xe12e20, 0xc000387ef0, 0xc0001d0b80, 0x0, 0x0)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/lsp/protocol/tsserver.go:532 +0x13aa
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc00028cc00, 0xc0001d0b80, 0xc0002fc180, 0xe12e20, 0xc000387ef0, 0x0, 0x0, 0xc000322360)
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/jsonrpc2/jsonrpc2.go:372 +0x160
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a/internal/jsonrpc2/jsonrpc2.go:356 +0x850

This only happens when renaming to error, I expect because it is a builtin.
It also only happens if the variable is referenced more than once.

Build info

golang.org/x/tools/gopls v0.3.4
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/sergi/go-diff@v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
    golang.org/x/mod@v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
    golang.org/x/sync@v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
    golang.org/x/tools@v0.0.0-20200316194252-fafb6e2e8a4a => ../
    golang.org/x/xerrors@v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
    honnef.co/go/tools@v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U=
    mvdan.cc/xurls/v2@v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=

Go info

go version go1.14 linux/amd64

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jesse/.cache/go-build"
GOENV="/home/jesse/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jesse/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/tmp/hello/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build857529350=/tmp/go-build -gno-record-gcc-switches"
@gopherbot gopherbot added this to the Unreleased milestone Mar 20, 2020
@gopherbot
Copy link

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 Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Mar 20, 2020
@Jesse-Bakker Jesse-Bakker changed the title x/tools/gopls Segfault when renaming variable to error x/tools/gopls: Segfault when renaming variable to error Mar 20, 2020
@stamblerre stamblerre modified the milestones: Unreleased, gopls/v0.4.0 Mar 20, 2020
@gopherbot
Copy link

Change https://golang.org/cl/224477 mentions this issue: internal/lsp: fix nil pointer in renaming to "error"

@stamblerre
Copy link
Contributor

Thanks for the report - I never realized it was valid to name a variable error! The above change should fix the issue.

@stamblerre stamblerre changed the title x/tools/gopls: Segfault when renaming variable to error x/tools/gopls: segfault when renaming variable to error Mar 20, 2020
@golang golang locked and limited conversation to collaborators Mar 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants