-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: go1.22.2 warning loop variable v captured by func literal loopclosure #66876
Comments
I tried on go1.22.2 darwin/amd64 and the issue was not reproducible. |
Looks like the GoVersion is < 1.22.0 for the file. This value is derived from the go.mod file for the module, the build tags for the file, and the compiler version used to build gopls (and the -lang flag in some rare cases). The compiler version used to build gopls is >= 1.22 so that is not the issue. What does the "go 1.XY" line say in the go.mod file? (Or is there no go.mod file?) |
go.mod: go 1.22.2 |
try this command go clean -cache -modcache then Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Install/Update Tools command and select all options I use vscode remote-ssh extension to connect a linux server |
I'm seeing the same issue. Looks like a possible regression -> #65910. Following the same steps from that issue: gopls version
go env
What did you do?With the following main.go: package main
import (
"fmt"
)
func main() {
for i := range 10 {
go func() { fmt.Println(i) }()
}
} and module example.com/loopclosure
go 1.22.2 I ran
What did you see happen?
What did you expect to see?No error message |
Thanks, yes this is a regression in [email protected], specifically this CL: https://go.dev/cl/576678 That code should be comparing language versions, not toolchain versions :( Fix incoming. To disable this analysis in the meantime: |
Aha, we didn't catch this because it isn't broken at master. |
Closing as this has been cherry-picked to the release branch, and we are preparing the v0.15.4 release. |
@synhi suggestion worked for me. I am using nvim:
I did everything apart from Hope it helps |
Thanks @0xBradock. For what it's worth, steps (2) and (3) should not be necessary. Simply updating gopls to the latest version and restarting should fix the problem. |
[Gopls](golang/go#66876) had a recent update which fixed my text editor from complaining about the "loop variable being captured by func literal". Fixes #7454
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
go version
to get version of Go from the VS Code integrated terminal.gopls -v version
to get version of Gopls from the VS Code integrated terminal.golang.org/x/tools/[email protected] h1:zbdOidFrPTc8Bx0YrN5QKgJ0zCjyGi0L27sKQ/bDG5o=
github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/[email protected] h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/[email protected] h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/[email protected] h1:vcVnuftN4J4UKLRcgetjzfU9FjjgXUUYUc3JhFplgV4=
golang.org/x/[email protected] h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/[email protected] h1:uH9jJYgeLCvblH0S+03kFO0qUDxRkbLRLFiKVVDl7ak=
golang.org/x/[email protected] h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
honnef.co/go/[email protected] h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=
mvdan.cc/[email protected] h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.22.2
code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders.Go: Locate Configured Go Tools
command.Environment
GOBIN: undefined
toolsGopath:
gopath: /root/go
GOROOT: /usr/local/go
PATH: /root/.vscode-server/bin/e170252f762678dec6ca2cc69aba1570769a5d39/bin/remote-cli:/usr/local/go/bin:/root/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.local/bin:/root/.local/bin
Tools
Go env
Workspace Folder (server):
Workspace Folder (web):
Describe the bug
go 1.22 alredy fix the loop vairable issue, why waring "loop variable v captured by func literal loopclosure" (go.mod go version 1.22.2)
waring link https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/loopclosure
Steps to reproduce the behavior:
Screenshots or recordings
The text was updated successfully, but these errors were encountered: