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/cmd/gopls: crashes with "slice bounds out of range" #31707

Closed
zippoxer opened this issue Apr 26, 2019 · 2 comments
Closed

x/tools/cmd/gopls: crashes with "slice bounds out of range" #31707

zippoxer opened this issue Apr 26, 2019 · 2 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Milestone

Comments

@zippoxer
Copy link

zippoxer commented Apr 26, 2019

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

$ go version
go version go1.12.4 windows/amd64

Does this issue reproduce with the latest release?

Yes. VSCode is up to date, and I updated gopls moments before.

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\User\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\User\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\User\projects\devout\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\User\AppData\Local\Temp\go-build351004186=/tmp/go-build -gno-record-gcc-switches

What did you do?

Edit the file below (in a sub-package of a project which has go.mod), place my caret at the position marked with [[*]], and press CTRL + Space to get suggestions.

package httpserver

import (
	"net/http"

	"github.com/go-chi/chi"
)

func (s *Server) apiRouter() chi.Router {
	r := chi.NewRouter()

	r.Post("/search", s.handleSearch)

	return r
}

func (s *Server) handleSearch(r http.[[*]])

What did you expect to see?

Suggestions.

What did you see instead?

This error, repeatedly, until VSCode tires and stops restarting gopls:

cacheAndDiagnose: file:///c:/Users/User/projects/devout/httpserver/api.go
cacheAndDiagnose: set content for file:///c:/Users/User/projects/devout/httpserver/api.go
cacheAndDiagnose: returned from diagnostics for file:///c:/Users/User/projects/devout/httpserver/api.go
cacheAndDiagnose: going to get diagnostics for file:///c:/Users/User/projects/devout/httpserver/api.go
found parse or type-checking errors for file:///c:/Users/User/projects/devout/httpserver/api.go, returning
panic: runtime error: slice bounds out of range

goroutine 19 [running]:
golang.org/x/tools/internal/span.ToUTF16Column(0x11, 0x29, 0xe0, 0xc0001c2380, 0xe0, 0xe0, 0x1, 0x0, 0x0)
	C:/Users/User/go/src/golang.org/x/tools/internal/span/utf16.go:43 +0x581
golang.org/x/tools/internal/lsp/protocol.(*ColumnMapper).Position(0xc00d2c00f0, 0x11, 0x29, 0xe0, 0x4030000000000000, 0x0, 0x0, 0x0)
	C:/Users/User/go/src/golang.org/x/tools/internal/lsp/protocol/span.go:62 +0x6a
golang.org/x/tools/internal/lsp/protocol.(*ColumnMapper).Range(0xc00d2c00f0, 0xc002b98fc0, 0x38, 0x11, 0x1, 0xb8, 0x11, 0x29, 0xe0, 0x4020000000000000, ...)
	C:/Users/User/go/src/golang.org/x/tools/internal/lsp/protocol/span.go:54 +0x4b7
golang.org/x/tools/internal/lsp.toProtocolDocumentSymbols(0xc00d2c00f0, 0xc005376900, 0x2, 0x2, 0xc005376900, 0x2, 0x2)
	C:/Users/User/go/src/golang.org/x/tools/internal/lsp/symbols.go:35 +0x267
golang.org/x/tools/internal/lsp.(*Server).documentSymbol(0xc0000aa7e0, 0x8d06c0, 0xc000068e80, 0xc00004c010, 0xc00004c010, 0x0, 0x0, 0x0, 0xc00020e000)
	C:/Users/User/go/src/golang.org/x/tools/internal/lsp/symbols.go:23 +0x17e
golang.org/x/tools/internal/lsp.(*Server).DocumentSymbol(0xc0000aa7e0, 0x8d06c0, 0xc000068e80, 0xc00004c010, 0xc00004c010, 0x0, 0x0, 0x0, 0x0)
	C:/Users/User/go/src/golang.org/x/tools/internal/lsp/server.go:198 +0x54
golang.org/x/tools/internal/lsp/protocol.serverHandler.func1(0x8d06c0, 0xc000068e80, 0xc0001443f0, 0xc000063320)
	C:/Users/User/go/src/golang.org/x/tools/internal/lsp/protocol/server.go:325 +0x42b1
golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1(0xc00009e840, 0xc0001443f0)
	C:/Users/User/go/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:276 +0xe1
created by golang.org/x/tools/internal/jsonrpc2.(*Conn).Run
	C:/Users/User/go/src/golang.org/x/tools/internal/jsonrpc2/jsonrpc2.go:270 +0xc1
[Info  - 2:41:22 AM] Connection to server got closed. Server will restart.

Hint

This bug doesn't happen when the handleSearch function has a body:

func (s *Server) handleSearch(r http.[[*]]) {}
@gopherbot gopherbot added this to the Unreleased milestone Apr 26, 2019
@gopherbot gopherbot added the gopls Issues related to the Go language server, gopls. label Apr 26, 2019
@stamblerre
Copy link
Contributor

/cc @ianthehat

@stamblerre
Copy link
Contributor

https://golang.org/cl/174357 will likely have fixed this error. Please re-open if you see it again.

@golang golang locked and limited conversation to collaborators Apr 28, 2020
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