Skip to content

x/tools/gopls: nil pointer error in gopls/internal/lsp/cache.toSourceDiagnostic #60909

Closed
@ccbhj

Description

@ccbhj

nil pointer error in toSourceDiagnostic

gopls version

golang.org/x/tools/gopls@master: 85554d6


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.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
    golang.org/x/sync@v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
    golang.org/x/sys@v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
    golang.org/x/text@v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
    golang.org/x/tools@v0.6.0 => ../
    golang.org/x/vuln@v0.0.0-20230110180137-6ad3e3d07815 h1:A9kONVi4+AnuOr1dopsibH6hLi1Huy54cbeJxnq4vmU=
    honnef.co/go/tools@v0.4.2 h1:6qXr+R5w+ktL5UkwEbPp+fEvfyoMPche6GkOpGHZcLc=
    mvdan.cc/gofumpt@v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.19.9

go env

GO111MODULE="on"
GOARCH="amd64"
GOBIN="/Users/bingjia.chen/go/bin"
GOCACHE="/Users/bingjia.chen/Library/Caches/go-build"
GOENV="/Users/bingjia.chen/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/bingjia.chen/go/pkg/mod"
GOOS="darwin"
GOPATH="/Users/bingjia.chen/go"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.19.9"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cn/yf347khx1k1fh7ctyx6sdjgm0000gy/T/go-build2061136138=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

simplely trigger the error or warn disagnostic

What did you expect to see?

lsp work correctly

What did you see instead?

gopls got detech and killed

Editor and settings

Editor: nvim v0.9.1
Pluigins:ray-x/go.nvim
Lsp Config:

lsp_cfg = {
capabilities = require('cmp_nvim_lsp').default_capabilities(),
handlers = handlers,
settings = {
gopls = {
directoryFilters = {
"-**/protobuf/go/",
"-protobuf/go",
},
analyses = {
shadow = false,
}
}
}
},

Logs

[ERROR][2023-06-21 11:00:35] .../vim/lsp/rpc.lua:734	"rpc"	"/Users/bingjia.chen/go/bin/gopls"	"stderr"	"panic: runtime error: invalid memory address or nil pointer dereference\n[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x100801ebd]\n\ngoroutine 19035 [running]:\ngolang.org/x/tools/gopls/internal/lsp/cache.toSourceDiagnostic(0x0, 0xc021867ab0)\n\t/tmp/tools/gopls/internal/lsp/cache/errors.go:316 +0x7d\ngolang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).Analyze(0x0, {0x100d6f920, 0xc0208a8d20}, 0xc0208a8390, {0xc020880800, 0xc6, 0x0?})\n\t/tmp/tools/gopls/internal/lsp/cache/analysis.go:351 +0xee5\ngolang.org/x/tools/gopls/internal/lsp/source.Analyze({0x100d6f920, 0xc0208a8d20}, {0x100d7c238, 0xc01d867680}, 0xc00098e300?, 0x0)\n\t/tmp/tools/gopls/internal/lsp/source/diagnostics.go:48 +0x255\ngolang.org/x/tools/gopls/internal/lsp.(*Server).diagnosePkgs.func2()\n\t/tmp/tools/gopls/internal/lsp/diagnostics.go:452 +0xc7\ncreated by golang.org/x/tools/gopls/internal/lsp.(*Server).diagnosePkgs\n\t/tmp/tools/gopls/internal/lsp/diagnostics.go:450 +0x31d\n"

image

Activity

added
ToolsThis label describes issues relating to any tools in the x/tools repository.
goplsIssues related to the Go language server, gopls.
on Jun 21, 2023
added this to the Unreleased milestone on Jun 21, 2023
adonovan

adonovan commented on Jun 21, 2023

@adonovan
Member

This seems very closely related to #60551, though I still don't have a good hypothesis for that one.

adonovan

adonovan commented on Jun 21, 2023

@adonovan
Member

Actually the explanation for this one is very simple: the enabled set of analyzers is expanded to include all "required" analyzer dependencies, to ensure that the root analyzer set is a superset of the facty set, allowing us to analyze each package with exactly one set. But the expanded set should not be used for the final loop.

Thanks for the prompt and very clear bug report!

gopherbot

gopherbot commented on Jun 21, 2023

@gopherbot
Contributor

Change https://go.dev/cl/504818 mentions this issue: gopls/internal/lsp/cache: fix nil panic in analysis toSourceDiagnostic

self-assigned this
on Jun 21, 2023
ccbhj

ccbhj commented on Jun 23, 2023

@ccbhj
Author

Thank you for the fix and reply in such a short time! Great work on gopls btw.

added a commit that references this issue on Feb 16, 2024
0ca9d30
locked and limited conversation to collaborators on Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @adonovan@gopherbot@ccbhj

      Issue actions

        x/tools/gopls: nil pointer error in gopls/internal/lsp/cache.toSourceDiagnostic · Issue #60909 · golang/go