-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: issues errors for range-over-func (InvalidRangeExpr) in go1.23rc1 projects #68248
Comments
Setting I'll leave this open because it isn't clear to me if this is expected behavior for 1.23rc1 projects. |
Did you build gopls with go1.23rc1? What is the output of |
If it helps, I have the same problem, and |
EDIT TLDR: yes, building gopls with go1.23rc1 fixes the issue. I installed gopls v0.16 with
EDIT I was wrong. Looks like a gopls built with go1.23rc1 works with range-over-func. (I got confused by NeoVim using a version of gopls that it installed itself) Anyway, for the first attempt I get the symptoms I report in #68248 (comment), namely that % go version -m $(which gopls)
/home/matt/go/bin/gopls: go1.22.3 X:rangefunc
path golang.org/x/tools/gopls
mod golang.org/x/tools/gopls v0.16.0 h1:JOYR1NabC699+pLFI02CxlD9xaPXdaVmPp7f01k0/hE=
dep github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
dep github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
dep golang.org/x/exp/typeparams v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
dep golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
dep golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
dep golang.org/x/telemetry v0.0.0-20240607193123-221703e18637 h1:3Wt8mZlbFwG8llny+t18kh7AXxyWePFycXMuVdHxnyM=
dep golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
dep golang.org/x/tools v0.22.1-0.20240620150659-cb3016b76f3e h1:Cht5EwNRmW9EgQ7ihPmgIswaQW4jR1cPbmzGCNl2++8=
dep golang.org/x/vuln v1.0.4 h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
dep honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
dep mvdan.cc/gofumpt v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
dep mvdan.cc/xurls/v2 v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
build -buildmode=exe
build -compiler=gc
build DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=amd64
build GOEXPERIMENT=rangefunc
build GOOS=linux
build GOAMD64=v1 After this I ran
EDIT: that fixes things. |
FWIW, I reported a similar issue in staticcheck. There, the fix to build with go1.23rc1 worked as well. @dominikh also added code to staticcheck that will report an error if the tool is used on a go module requiring versions of go newer than what the tool was built with. gopls could consider a similar check. |
Thanks, that's a good idea. I'll repurpose this issue for that. (EDIT: opted for a new issue) |
Closing as I believe the issue is now understood. |
Go version
go version go1.23rc1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
$ gopls version
golang.org/x/tools/gopls v0.16.0
$ mkdir -p ~/scratch/maps-all
$ go1.23rc1 mod init example.com/m
Verify go.mod contains this:
$ vi mapsall.go
Write this code:
$ go run mapsall.go
<verify it prints the expected thing, which it does, without reporting warnings>
Now edit mapsall.go in any editor using gopls. Witness errors like:
What did you see happen?
gopls seems to issue errors for code using the new range-over-func stuff, even when
go build
works in the same module.What did you expect to see?
No errors.
https://github.com/golang/tools/releases/tag/gopls%2Fv0.16.0 mentions
It doesn't mention any special configuration steps, so I assume this should work out of the box and is keyed off the go version in go.mod?
The text was updated successfully, but these errors were encountered: