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: rename fails on struct method that references bad struct field #32882

Closed
suzmue opened this issue Jul 1, 2019 · 2 comments
Closed
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Milestone

Comments

@suzmue
Copy link
Contributor

suzmue commented Jul 1, 2019

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

$ go version
go version go1.12.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/suzmue/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/suzmue/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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=/var/folders/q0/0bxb5hrs08l_vhzptkl5gd2400fkl_/T/go-build271696857=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go.mod:

module github.com/suzmue/gopkg

go 1.12

gopkg.go

package gopkg

type myStruct struct {
}

func (s *myStruct) myBadFunc() bool { //@rename("myBadFunc", "hello")
	return s.Bad // is not a field of myStruct
}

What did you expect to see?

The identifier being renamed to Hello

What did you see instead?

Log of gopls crashing:

[Trace - 5:32:06 PM] Sending request 'textDocument/rename - (19)'.
Params: {"textDocument":{"uri":"file:///Users/suzmue/go/src/golang.org/x/tools/internal/imports/fix.go"},"position":{"line":413,"character":20},"newName":"hello"}

[Error - 5:32:06 PM] send textDocument/rename#19 method "textDocument/rename" did not reply

[Error - 5:32:06 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=0x50 pc=0x14babdb]

goroutine 1703 [running]:
golang.org/x/tools/refactor/satisfy.(*Finder).expr(0xc0048b2a20, 0x1784700, 0xc0002753e0, 0x177d000, 0xc0054e0720)
/Users/suzmue/go/src/golang.org/x/tools/refactor/satisfy/find.go:406 +0xf9b
golang.org/x/tools/refactor/satisfy.(*Finder).stmt(0xc0048b2a20, 0x1784680, 0xc000275440)
/Users/suzmue/go/src/golang.org/x/tools/refactor/satisfy/find.go:557 +0x11fb
golang.org/x/tools/refactor/satisfy.(*Finder).stmt(0xc0048b2a20, 0x1783f40, 0xc00023ac90)
/Users/suzmue/go/src/golang.org/x/tools/refactor/satisfy/find.go:572 +0x1939
golang.org/x/tools/refactor/satisfy.(*Finder).stmt(0xc0048b2a20, 0x1784400, 0xc0002cc800)
/Users/suzmue/go/src/golang.org/x/tools/refactor/satisfy/find.go:580 +0x1a66
golang.org/x/tools/refactor/satisfy.(*Finder).stmt(0xc0048b2a20, 0x1783f40, 0xc00023b080)
/Users/suzmue/go/src/golang.org/x/tools/refactor/satisfy/find.go:572 +0x1939
golang.org/x/tools/refactor/satisfy.(*Finder).Find(0xc0048b2a20, 0xc0054bd400, 0xc004873300, 0x5, 0x8)
/Users/suzmue/go/src/golang.org/x/tools/refactor/satisfy/find.go:111 +0x193
golang.org/x/tools/internal/lsp/source.(*renamer).satisfy(0xc0004f46e0, 0xc00288b950)
/Users/suzmue/go/src/golang.org/x/tools/internal/lsp/source/rename_check.go:792 +0x125
golang.org/x/tools/internal/lsp/source.(*renamer).checkMethod(0xc0004f46e0, 0xc0054bda90)
/Users/suzmue/go/src/golang.org/x/tools/internal/lsp/source/rename_check.go:723 +0x11a
golang.org/x/tools/internal/lsp/source.(*renamer).check(0xc0004f46e0, 0x17906a0, 0xc0054bda90)
/Users/suzmue/go/src/golang.org/x/tools/internal/lsp/source/rename_check.go:46 +0x343
golang.org/x/tools/internal/lsp/source.(*IdentifierInfo).Rename(0xc003f1e750, 0x1785c80, 0xc004ab5380, 0xc005bc2466, 0x5, 0xc00030e640, 0x5789, 0xc003f1e750)
/Users/suzmue/go/src/golang.org/x/tools/internal/lsp/source/rename.go:76 +0x5d5
golang.org/x/tools/internal/lsp.(*Server).rename(0xc0001daf80, 0x1785c80, 0xc004ab5380, 0xc0048b28a0, 0x0, 0x0, 0xc004866a00)
/Users/suzmue/go/src/golang.org/x/tools/internal/lsp/rename.go:34 +0x292
golang.org/x/tools/internal/lsp.(*Server).Rename(0xc0001daf80, 0x1785c80, 0xc004ab5380, 0xc0048b28a0, 0xc0048b28a0, 0x0, 0x0)
/Users/suzmue/go/src/golang.org/x/tools/internal/lsp/server.go:241 +0x49
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0x1785c80, 0xc004ab5380, 0xc002a1f3e0)
/Users/suzmue/go/src/golang.org/x/tools/internal/lsp/protocol/tsserver.go:415 +0x1291
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc0046e2480, 0xc002a1f3e0, 0xc00021a000, 0x1785c80, 0xc004ab5380, 0xc004a59400, 0xc001b03680)
/Users/suzmue/go/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:441 +0x117
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
/Users/suzmue/go/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:428 +0x6fc
[Info - 5:32:06 PM] Connection to server got closed. Server will restart.

@gopherbot gopherbot added this to the Unreleased milestone Jul 1, 2019
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Jul 1, 2019
@suzmue suzmue self-assigned this Jul 1, 2019
@SteelPhase
Copy link

Not sure if any additional information is required to figure this one out, but I am experiencing the same issue.

@stamblerre stamblerre changed the title x/tools/internal/lsp: rename fails on struct method that references bad struct field x/tools/lsp: rename fails on struct method that references bad struct field Jul 2, 2019
@stamblerre stamblerre changed the title x/tools/lsp: rename fails on struct method that references bad struct field x/tools/gopls: rename fails on struct method that references bad struct field Jul 2, 2019
@gopherbot
Copy link

Change https://golang.org/cl/184857 mentions this issue: internal/lsp: check no errs for assignability rename

movie-travel-code pushed a commit to movie-travel-code/tools that referenced this issue Jul 11, 2019
The satisfy package has a precondition for Finder.Find that requires
that the package has no type errors. If this is a check that we would
perform, give an error and do not rename.

Fixes golang/go#32882

Change-Id: Id44b451bf86ff883fd78a6306f2b2565ad3bdeb9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184857
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
@golang golang locked and limited conversation to collaborators Jul 7, 2020
@rsc rsc unassigned suzmue Jun 23, 2022
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.
Projects
None yet
Development

No branches or pull requests

3 participants