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: server exits if empty method receiver #57729

Closed
vikblom opened this issue Jan 10, 2023 · 4 comments
Closed

x/tools/gopls: server exits if empty method receiver #57729

vikblom opened this issue Jan 10, 2023 · 4 comments
Assignees
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

@vikblom
Copy link

vikblom commented Jan 10, 2023

Hi,

I've been trying outgopls master for a bit and noticed it crashed when editing a receiver. I could not find any open issue similar to what I saw so here is a summary.

gopls version

Current master 1e0dff28f4f920fb7a7f132f775bd68e3b1e1fff.

Build info
----------
golang.org/x/tools/gopls master
    golang.org/x/tools/gopls@(devel)
    github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/go-cmp@v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp@v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
    golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/mod@v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
    golang.org/x/sync@v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
    golang.org/x/sys@v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
    golang.org/x/text@v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
    golang.org/x/tools@(devel)
    golang.org/x/vuln@v0.0.0-20221212182831-af59454a8a0a h1:KWIh6uTTw7r3PEz1N1OIEM8pr5bf1uP1n6JL5Ml56X8=
    honnef.co/go/tools@v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=
    mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.19.4

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/viktor/.cache/go-build"
GOENV="/home/viktor/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/viktor/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/viktor/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/viktor/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/viktor/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/viktor/local/tools/go.mod"
GOWORK="/home/viktor/local/tools/go.work"
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3730210901=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Renaming the reciever for a method, removing everything between the parens. Like so

func (f Foo) Bar(baz int) int {
     ...
}
// ->
func () Bar(baz int) int {
     ...
}

What did you expect to see?

n/a

What did you see instead?

gopls: remote disconnected: failed reading header line: EOF

Process gopls stderr finished

Editor and settings

Emacs 28.2 with lsp-mode 20230107.2052.

Gopls flags -v -remote=auto -remote.logfile=/home/viktor/gopls.log

Logs

Enabling logging gives:

analysis.go:844: internal error writing shallow export data: gcimporter: unexpected method: func()

Running go run ./gopls/main.go check tmp.go on a file like:

package tmp

func () Foo() {}

reliably fails (on my machines) with

2023/01/10 22:35:02 internal error writing shallow export data: gcimporter: unexpected method: func()
exit status 1

Bisecting points at 61e2d3f4f: gopls/internal/lsp/cache: a new analysis driver. Before that the check above just prints

/home/viktor/local/tools/tmp/tmp.go:3:6-8: method is missing receiver

Maybe something has escalated this from warning to error?

@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 Jan 10, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jan 10, 2023
@findleyr
Copy link
Contributor

Thanks for the report. master is rather unstable right now (but we're making big improvements!)

CC @adonovan

@findleyr findleyr modified the milestones: Unreleased, gopls/v0.12.0 Jan 10, 2023
@adonovan adonovan self-assigned this Jan 11, 2023
@adonovan
Copy link
Member

Indeed, many thanks for this very helpful report.

@findleyr: I'll fix this one, but I think we are going to need fuzz testing of export/import of types.Packages containing type errors as this functionality has never been used in production before.

@gopherbot
Copy link

Change https://go.dev/cl/461575 mentions this issue: internal/gcimporter: fix export of invalid methods

@findleyr
Copy link
Contributor

Fuzz testing is a great idea. We can start with a valid program that exercises all aspects of the type checker, and fuzz edits to it. We might discover more go/types crashes this way as well...

There must also be prior art.

@golang golang locked and limited conversation to collaborators Jan 11, 2024
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

4 participants