Skip to content

x/tools/gopls: nil pointer on rename #32974

Closed
@mykter

Description

@mykter

What version of Go are you using (go version)?

$ go version
go version go1.12.6 linux/amd64

$ gopls version
golang.org/x/tools/gopls v0.1.1
    golang.org/x/tools/gopls@v0.1.2-0.20190706070813-72ffa07ba3db h1:jEzcdhR4g/qmRjnefU4bjKYInYeXwZRsQqqcnUrVSxk=

Does this issue reproduce with the latest release?

Of gopls, yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mmacnair/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mmacnair/go"
GOPROXY=""
GORACE=""
GOROOT="/snap/go/3947"
GOTMPDIR=""
GOTOOLDIR="/snap/go/3947/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mmacnair/pkg/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build501054748=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Tried to rename a type defined at package level

What did you expect to see?

The type and all references to it be renamed

What did you see instead?

No changes, and a crash:

[Error - 11:44:32 AM] Request textDocument/rename failed.
  Message: method "textDocument/rename" did not reply
  Code: -32603 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x8d92b9]

goroutine 3907 [running]:
golang.org/x/tools/internal/lsp/source.(*renamer).checkInPackageBlock(0xc0005acc60, 0xb9a8a0, 0xc005fe2af0)
	/home/mmacnair/go/pkg/mod/golang.org/x/tools@v0.0.0-20190706070813-72ffa07ba3db/internal/lsp/source/rename_check.go:116 +0xf9
golang.org/x/tools/internal/lsp/source.(*renamer).check(0xc0005acc60, 0xb9a8a0, 0xc005fe2af0)
	/home/mmacnair/go/pkg/mod/golang.org/x/tools@v0.0.0-20190706070813-72ffa07ba3db/internal/lsp/source/rename_check.go:42 +0x39c
golang.org/x/tools/internal/lsp/source.(*IdentifierInfo).Rename(0xc004182410, 0xb8f900, 0xc0061f8de0, 0xc0057928a4, 0x4, 0x0, 0x0, 0x0)
	/home/mmacnair/go/pkg/mod/golang.org/x/tools@v0.0.0-20190706070813-72ffa07ba3db/internal/lsp/source/rename.go:76 +0x70b
golang.org/x/tools/internal/lsp.(*Server).rename(0xc000136d20, 0xb8f900, 0xc0061f8de0, 0xc0061f8e10, 0x0, 0x0, 0xc000542140)
	/home/mmacnair/go/pkg/mod/golang.org/x/tools@v0.0.0-20190706070813-72ffa07ba3db/internal/lsp/rename.go:34 +0x295
golang.org/x/tools/internal/lsp.(*Server).Rename(0xc000136d20, 0xb8f900, 0xc0061f8de0, 0xc0061f8e10, 0xc0061f8e10, 0x0, 0x0)
	/home/mmacnair/go/pkg/mod/golang.org/x/tools@v0.0.0-20190706070813-72ffa07ba3db/internal/lsp/server.go:244 +0x49
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0xb8f900, 0xc0061f8de0, 0xc0060bd5c0)
	/home/mmacnair/go/pkg/mod/golang.org/x/tools@v0.0.0-20190706070813-72ffa07ba3db/internal/lsp/protocol/tsserver.go:415 +0x1291
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc00002acc0, 0xc0060bd5c0, 0xc00016e3f0, 0xb8f900, 0xc0061f8de0, 0xc00600a960, 0xc000b029f0)
	/home/mmacnair/go/pkg/mod/golang.org/x/tools@v0.0.0-20190706070813-72ffa07ba3db/internal/jsonrpc2/jsonrpc2.go:441 +0x117
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	/home/mmacnair/go/pkg/mod/golang.org/x/tools@v0.0.0-20190706070813-72ffa07ba3db/internal/jsonrpc2/jsonrpc2.go:428 +0x6fc

Unfortunately the code isn't public and I don't have a minimal reproducer. I did do a quick test of adding a new package level type and variable definition, that weren't used anywhere else, and got the same result for each of them - the stack trace ends on the same line.

If this isn't enough info to diagnose, feel free to close it. I'm sure someone else will hit this at some point with an open source project!

Activity

added this to the Unreleased milestone on Jul 8, 2019
added
goplsIssues related to the Go language server, gopls.
on Jul 8, 2019
self-assigned this
on Jul 8, 2019
suzmue

suzmue commented on Jul 8, 2019

@suzmue
Contributor

@mykter Are both the use and the type definition in the same package? Could you also post the line declaring the package level type and a variable definition? Thanks!

suzmue

suzmue commented on Jul 9, 2019

@suzmue
Contributor

Do you have any test files? If so, https://go-review.googlesource.com/c/tools/+/185277 should fix it.

The following produces a similar trace:

Rename x
hello.go

package hello

var x int

hello_test.go

package hello

error:

[Error - 7:45:50 PM] Request textDocument/rename failed.
  Message: method "textDocument/rename" did not reply
  Code: -32603 
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x14d8f69]

goroutine 1823 [running]:
golang.org/x/tools/internal/lsp/source.(*renamer).checkInPackageBlock(0xc001f60840, 0x179acc0, 0xc001d15270)
	/Users/suzmue/go/pkg/mod/golang.org/x/tools@v0.0.0-20190708203411-c8855242db9c/internal/lsp/source/rename_check.go:116 +0xf9
golang.org/x/tools/internal/lsp/source.(*renamer).check(0xc001f60840, 0x179acc0, 0xc001d15270)
	/Users/suzmue/go/pkg/mod/golang.org/x/tools@v0.0.0-20190708203411-c8855242db9c/internal/lsp/source/rename_check.go:42 +0x39c
golang.org/x/tools/internal/lsp/source.(*IdentifierInfo).Rename(0xc0015eb1e0, 0x178fb80, 0xc001ac4d20, 0xc003e5b1c8, 0x2, 0x0, 0x0, 0x0)
	/Users/suzmue/go/pkg/mod/golang.org/x/tools@v0.0.0-20190708203411-c8855242db9c/internal/lsp/source/rename.go:76 +0x70b
golang.org/x/tools/internal/lsp.(*Server).rename(0xc00022a000, 0x178fb80, 0xc001ac4d20, 0xc0018d14a0, 0x0, 0x0, 0xc001eebb80)
	/Users/suzmue/go/pkg/mod/golang.org/x/tools@v0.0.0-20190708203411-c8855242db9c/internal/lsp/rename.go:34 +0x295
golang.org/x/tools/internal/lsp.(*Server).Rename(0xc00022a000, 0x178fb80, 0xc001ac4d20, 0xc0018d14a0, 0xc0018d14a0, 0x0, 0x0)
	/Users/suzmue/go/pkg/mod/golang.org/x/tools@v0.0.0-20190708203411-c8855242db9c/internal/lsp/server.go:244 +0x49
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0x178fb80, 0xc001ac4d20, 0xc002593f20)
	/Users/suzmue/go/pkg/mod/golang.org/x/tools@v0.0.0-20190708203411-c8855242db9c/internal/lsp/protocol/tsserver.go:415 +0x1291
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc003e4a7e0, 0xc002593f20, 0xc00022c000, 0x178fb80, 0xc001ac4d20, 0xc001d15b80, 0xc000e21da0)
	/Users/suzmue/go/pkg/mod/golang.org/x/tools@v0.0.0-20190708203411-c8855242db9c/internal/jsonrpc2/jsonrpc2.go:441 +0x117
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	/Users/suzmue/go/pkg/mod/golang.org/x/tools@v0.0.0-20190708203411-c8855242db9c/internal/jsonrpc2/jsonrpc2.go:428 +0x6fc
mykter

mykter commented on Jul 9, 2019

@mykter
Author

I do have tests for that package, yes - looks like you've found it!
Thanks.

changed the title [-]x/tools/cmd/gopls: Crash on rename[/-] [+]x/tools/cmd/gopls: nil pointer on rename[/+] on Jul 9, 2019
changed the title [-]x/tools/cmd/gopls: nil pointer on rename[/-] [+]x/tools/gopls: nil pointer on rename[/+] on Jul 9, 2019
gopherbot

gopherbot commented on Jul 9, 2019

@gopherbot
Contributor

Change https://golang.org/cl/185277 mentions this issue: internal/lsp: rename identifiers in test packages

added a commit that references this issue on Jul 11, 2019
4fc3618
locked and limited conversation to collaborators on Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgegoplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mykter@suzmue@gopherbot

        Issue actions

          x/tools/gopls: nil pointer on rename · Issue #32974 · golang/go