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/internal/lsp: Bad access caused by the GetToken()'s returning nil. #30562

Closed
movie-travel-code opened this issue Mar 4, 2019 · 4 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls.
Milestone

Comments

@movie-travel-code
Copy link

movie-travel-code commented Mar 4, 2019

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

$ go version
go version go1.12 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/henrywong/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/henrywong/workspace/gopath"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/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/fm/bk0wqlkj523gdp9pbtnyvxmm0000gn/T/go-build967651890=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Running the gopls to receive the LSP request from the client.

By the way, the essential reason why the GetToken() return nil is that the go source file the LSP client editing is not located in the $GOPATH. As a result, when the LSP try to load the package will fail.

What did you expect to see?

Whatever the cause is, for the function who will return nil, we should provide the nil check before we access its return value.

What did you see instead?

The nil return value of GetToken() flows along the execute path until trigger the null pointer dereference.

@gopherbot gopherbot added this to the Unreleased milestone Mar 4, 2019
@movie-travel-code
Copy link
Author

cc @stamblerre

@stamblerre
Copy link
Contributor

@movie-travel-code: are you using modules?

@stamblerre stamblerre added gopls Issues related to the Go language server, gopls. and removed gopls Issues related to the Go language server, gopls. labels Mar 12, 2019
@movie-travel-code
Copy link
Author

movie-travel-code commented Mar 14, 2019

@movie-travel-code: are you using modules?

Sorry for the long delay!

No, I am not using modules. The essential reason is that go list command, which called by packages.Load(), doesn't support the projects located out $GOPATH/src. It will emit an error cannot import absolute path.

In contrast, the module can fix my problem. The go list command works fine if I generate the go.mod for the project. Only this command must be executed in the directory where go.mod is located.

Anyway, it is not gopls issue :). Seems you've kindly fixed the nil pointer issue, thanks!

Btw, I wonder if gopls can work for the projects outside $GOPATH?

@bcmills
Copy link
Contributor

bcmills commented Apr 12, 2019

Anyway, it is not gopls issue :). Seems you've kindly fixed the nil pointer issue, thanks!

Sounds like this is resolved then; closing. (Please reply or reopen if I'm mistaken.)

@bcmills bcmills closed this as completed Apr 12, 2019
@golang golang locked and limited conversation to collaborators Apr 11, 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

4 participants