vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

staticcheck and other tools aren't compiled correctly when auto-downloading Go 1.22

Open printfn opened this issue 1 year ago • 1 comments

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.20.0 linux/amd64 when inside the project directory, otherwise go version go1.21.7 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
Build info
----------
golang.org/x/tools/gopls v0.14.2
    golang.org/x/tools/[email protected] h1:sIw6vjZiuQ9S7s0auUUkHlWgsCkKZFWDHmrge8LYsnc=
    github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/[email protected] h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/[email protected] h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
    golang.org/x/[email protected] h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
    golang.org/x/[email protected] h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
    golang.org/x/[email protected] h1:brbkEFfGwNGAEkykUOcryE/JiHUMMJouzE0fWWmz/QU=
    golang.org/x/[email protected] h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
    golang.org/x/[email protected] h1:Oku7E+OCrXHyst1dG1z10etCTxewCHXNFLRlyMPbh3w=
    golang.org/x/[email protected] h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
    honnef.co/go/[email protected] h1:YGD4H+SuIOOqsyoLOpZDWcieM28W47/zRO7f+9V3nvo=
    mvdan.cc/[email protected] h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.21.7
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
1.86.1
31c37ee8f63491495ac49e43b8544550fbae4533
x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.40.3
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: /home/user/go
GOROOT: /home/user/go/pkg/mod/golang.org/[email protected]
PATH: /home/user/.vscode-server/bin/31c37ee8f63491495ac49e43b8544550fbae4533/bin/remote-cli:/home/user/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Users/print/.cargo/bin:/mnt/c/Users/print/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/print/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Windows/system32/config/systemprofile/AppData/Local/Microsoft/WindowsApps:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Calibre2/:/mnt/c/Program Files/fend/bin/:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Users/print/scoop/apps/mpv/current:/mnt/c/Users/print/scoop/shims:/mnt/c/Users/print/.cargo/bin:/mnt/c/Users/print/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/print/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/print/AppData/Local/Programs/VSCodium/bin:/home/user/path:/home/user/.local/bin:/usr/local/opt/ruby/bin:/usr/local/go/bin:/home/user/go/bin:/opt/homebrew/bin:/snap/bin:/home/user/Library/Python/3.9/bin:/home/linuxbrew/.linuxbrew/bin

	go:	/home/linuxbrew/.linuxbrew/bin/go: go version go1.22.0 linux/amd64

	gopls:	/home/user/go/bin/gopls	(version: v0.14.2 built with go: go1.21.7)
	gotests:	/home/user/go/bin/gotests	(version: v1.6.0 built with go: go1.21.7)
	gomodifytags:	/home/user/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.21.7)
	impl:	/home/user/go/bin/impl	(version: v1.1.0 built with go: go1.21.7)
	goplay:	/home/user/go/bin/goplay	(version: v1.0.0 built with go: go1.21.7)
	dlv:	/home/user/go/bin/dlv	(version: v1.22.0 built with go: go1.21.7)
	staticcheck:	/home/user/go/bin/staticcheck	(version: v0.4.6 built with go: go1.21.7)

go env
Workspace Folder (go-test-testing): /home/user/go-test-testing
	GO111MODULE=''
	GOARCH='amd64'
	GOBIN=''
	GOCACHE='/home/user/.cache/go-build'
	GOENV='/home/user/.config/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='amd64'
	GOHOSTOS='linux'
	GOINSECURE=''
	GOMODCACHE='/home/user/go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='linux'
	GOPATH='/home/user/go'
	GOPRIVATE=''
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/home/user/go/pkg/mod/golang.org/[email protected]'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/home/user/go/pkg/mod/golang.org/[email protected]/pkg/tool/linux_amd64'
	GOVCS=''
	GOVERSION='go1.22.0'
	GCCGO='gccgo'
	GOAMD64='v1'
	AR='ar'
	CC='gcc'
	CXX='g++'
	CGO_ENABLED='1'
	GOMOD='/home/user/go-test-testing/go.mod'
	GOWORK=''
	CGO_CFLAGS='-O2 -g'
	CGO_CPPFLAGS=''
	CGO_CXXFLAGS='-O2 -g'
	CGO_FFLAGS='-O2 -g'
	CGO_LDFLAGS='-O2 -g'
	PKG_CONFIG='pkg-config'
	GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1853365452=/tmp/go-build -gno-record-gcc-switches'

Share the Go related settings you have added/edited

I don't have any Go settings set in settings.json.

Describe the bug

I have Go 1.21.7 installed via Hombrew, and opened a project with a go.mod that declares go 1.22.0. This caused Go to automatically download the newer toolchain and use it when running the program. But when I run staticcheck I get an immediate crash because it hasn't been recompiled for Go 1.22. The VS code extension shows the prompt "Tools (gopls, gotests, gomodifytags, impl, goplay, dlv, staticcheck) need recompiling to work with go version go1.22.0 linux/amd64", but clicking on the "Update tools" button just recompiles them with Go 1.21.7 and not 1.22.0, so it still doesn't work. Ideally the VS code extension should be able to recompile the tools using the right version of Go, i.e. /home/user/go/pkg/mod/golang.org/[email protected]/bin/go instead of the version that's on the PATH.

Steps to reproduce the behavior:

  1. Install Go 1.21.7
  2. Open a project with a go.mod that declares go 1.22.0
  3. Run the project - it will automatically download the newer toolchain and use that to run the project
  4. Open VS code
  5. It will offer to recompile go tools, but it uses the older version and it won't work.
  6. Trying to run staticcheck ./... will produce crashes such as
    panic: interface conversion: types.Object is nil, not *types.TypeName
    
    goroutine 166 [running]:
    honnef.co/go/tools/unused.(*graph).decl(0xc0002fabf0, {0xa028f8?, 0xc0012a0a40}, {0x0, 0x0})
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/unused/unused.go:1089 +0xadb
    honnef.co/go/tools/unused.(*graph).entry(0xc0002fabf0)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/unused/unused.go:522 +0xc14
    honnef.co/go/tools/unused.run(0xc000483110)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/unused/unused.go:218 +0x225
    honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc0009f98f0, {0xa04268?, 0xc000b22fa0})
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:992 +0x6fd
    honnef.co/go/tools/lintcmd/runner.genericHandle({0xa04268?, 0xc000b22fa0}, {0xa04268?, 0xc000cf0140?}, 0x8bb800?, 0x0, 0xc0002fb078)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:817 +0x129
    honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers(0xc0001a2b90, 0xc0001b67e0, 0xc000900be0)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:1065 +0x716
    honnef.co/go/tools/lintcmd/runner.(*subrunner).doUncached(0x0?, 0xc0001b67e0)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:720 +0x189
    honnef.co/go/tools/lintcmd/runner.(*subrunner).do(0xc0001a2b90, {0xa042b0?, 0xc0001b67e0})
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:577 +0x94b
    honnef.co/go/tools/lintcmd/runner.(*Runner).Run.func2({0xa042b0?, 0xc0001b67e0?})
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:1268 +0x2a
    honnef.co/go/tools/lintcmd/runner.genericHandle({0xa042b0?, 0xc0001b67e0}, {0xa042b0?, 0xc0001b66c0?}, 0x0?, 0xc0003df2a0, 0xc000716ad0)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:817 +0x129
    created by honnef.co/go/tools/lintcmd/runner.(*Runner).Run in goroutine 1
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:1267 +0x505
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x713632]
    
    goroutine 264 [running]:
    honnef.co/go/tools/go/ir.memberFromObject(0xc000114fc0, {0x0, 0x0?}, {0x0?, 0x0})
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/go/ir/create.go:54 +0x52
    honnef.co/go/tools/go/ir.membersFromDecl(0xc000114fc0, {0xa028f8?, 0xc0012a0a40?})
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/go/ir/create.go:155 +0x297
    honnef.co/go/tools/go/ir.(*Program).CreatePackage(0xc000fd0000, 0xc0012b80c0, {0xc0012a2120, 0x1, 0x1}, 0xc000900cd0, 0x0)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/go/ir/create.go:207 +0x7a5
    honnef.co/go/tools/internal/passes/buildir.run(0xc0001201a0)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/internal/passes/buildir/buildir.go:85 +0x165
    honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc0009f98f0, {0xa04268?, 0xc000cf0500})
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:992 +0x6fd
    honnef.co/go/tools/lintcmd/runner.genericHandle({0xa04268?, 0xc000cf0500}, {0xa04268?, 0xc000cf0140?}, 0x0?, 0xc0003df2a0, 0xc0003f9090)
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:817 +0x129
    created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers in goroutine 166
            /home/user/go/pkg/mod/honnef.co/go/[email protected]/lintcmd/runner/runner.go:1061 +0x6b5
    

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

printfn avatar Feb 11 '24 00:02 printfn

This has been causing me problems all across my repo.

kfelter avatar Feb 14 '24 19:02 kfelter

The root cause for the issue in my case was I had Go installed via .dmg file and via brew at the same time. I upgraded via .dmg file.

Uninstalling Go via brew helped resolve the issue.

michal-kra avatar Feb 21 '24 14:02 michal-kra

Fix that ended up working for me was editing my go.mod file ~1.22~ 1.22.0

Then restarting vs code and allowing it to download the new toolchain

kfelter avatar Feb 21 '24 15:02 kfelter

@michal-kra thanks

For resolve this issue:

brew uninstall --ignore-dependencies go
brew install go

gus3inov avatar Feb 28 '24 11:02 gus3inov

Fix that ended up working for me was editing my go.mod file ~1.22~ 1.22.0

Then restarting vs code and allowing it to download the new toolchain

this update on go.mod @kfelter worked for me. Weirdly, in my go.mod there was 1.23 somehow.

streamerd avatar Mar 16 '24 13:03 streamerd

different golang tools want go.mod to use format 1.22.1 others demand format 1.22

this is root cause of this bug and many others surrounding go tooling

scottstensland avatar Apr 04 '24 20:04 scottstensland

Change https://go.dev/cl/577095 mentions this issue: extension/src/goInstallTools: strengthing minimum go version requirement

gopherbot avatar Apr 06 '24 17:04 gopherbot

Change https://go.dev/cl/583975 mentions this issue: extension/src/util: do not use cached go version with GOTOOLCHAIN

gopherbot avatar May 07 '24 20:05 gopherbot