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/gopls: InvalidRangeExpr when using GOEXPERIMENT=rangefunc on iter.Seq #65667

Closed
stephenafamo opened this issue Feb 12, 2024 · 8 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@stephenafamo
Copy link

stephenafamo commented Feb 12, 2024

gopls version

golang.org/x/tools/gopls v0.15.0-pre.2
golang.org/x/tools/gopls@v0.15.0-pre.2 h1:A48ndEGf3pvzJ0k22HneSU7msCaggzcpg56ELTEuapQ=
github.com/BurntSushi/toml@v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/google/go-cmp@v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/exp/typeparams@v0.0.0-20221212164502-fae10dda9338 h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
golang.org/x/mod@v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/sync@v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/telemetry@v0.0.0-20240201224847-0a1d30dda509 h1:Nr7eTQpQZ/ytesxDJpQgaf0t4sdLnnDtAbmtViTrSUo=
golang.org/x/text@v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/tools@v0.17.1-0.20240206204217-56dc8684fb5a h1:WL/PnseOKWuDtRbgfYKDpuAmMpy3OrX84rv7uQFZJK4=
golang.org/x/vuln@v1.0.1 h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
honnef.co/go/tools@v0.4.6 h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8=
mvdan.cc/gofumpt@v0.6.0 h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
mvdan.cc/xurls/v2@v2.5.0 h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.22.0

go env

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/stephen/Library/Caches/go-build'
GOENV='/Users/stephen/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/stephen/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/stephen/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/stephen/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.0.darwin-arm64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='go1.22.0+auto'
GOTOOLDIR='/Users/stephen/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.0.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/9d/1smj789x4r5bdjccy3tqss0c0000gn/T/go-build1153037537=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

https://go.dev/play/p/rMbWTBEtveQ

What did you see happen?

gopls indicates an error even if it should be considered valid when GOEXPERIMENT=rangefunc is set

What did you expect to see?

No error shown

Editor and settings

Neovim with the following gopls configuration

            lspconfig.gopls.setup({
                capabilities = addCmpCapabilities(lspconfig.gopls.capabilities),
                settings = {
                    gopls = {
                        allowModfileModifications = false,
                        gofumpt = true,
                        codelenses = {
                            generate = true,
                            tidy = true,
                            upgrade_dependency = true,
                            vendor = true,
                        },
                        buildFlags = { "-tags", "goexperiment.rangefunc" },
                        directoryFilters = { "-**/node_modules", "-**/.git" },
                    },
                },
            })

Logs

No response

@stephenafamo stephenafamo added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Feb 12, 2024
@gopherbot gopherbot added this to the Unreleased milestone Feb 12, 2024
@findleyr
Copy link
Contributor

It works for me.

In your go env output, I see GOEXPERIMENT=''. Are you sure you set GOEXPERIMENT in your environment?

I just did:

export GOEXPERIMENT=rangefunc
nvim main.go

I'm using coc.nvim, but wouldn't expect neovim native LSP to behave differently.

@findleyr findleyr added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Feb 15, 2024
@stephenafamo
Copy link
Author

When I try to set it as environment variables, I get

go: unknown GOEXPERIMENT rangefunc

I had previously tried to use the environment variable to add the configuration of gopls and got the same error, but I thought that was an issue with how I was setting up the configuration.

I have tried it again, but I run into the same error:

            lspconfig.gopls.setup({
                capabilities = addCmpCapabilities(lspconfig.gopls.capabilities),
                settings = {
                    gopls = {
                        allowModfileModifications = false,
                        gofumpt = true,
                        codelenses = {
                            generate = true,
                            tidy = true,
                            upgrade_dependency = true,
                            vendor = true,
                        },
                        buildFlags = { "-tags", "goexperiment.rangefunc" },
                        directoryFilters = { "-**/node_modules", "-**/.git" },
                        env = {
                            GOEXPERIMENT = "rangefunc",
                        },
                    },
                },
            })

@findleyr
Copy link
Contributor

findleyr commented Feb 15, 2024

go: unknown GOEXPERIMENT rangefunc

Hmm, do you have multiple versions of go installed? Is it possible that the go your neovim sees is not go 1.22?

@stephenafamo
Copy link
Author

So I updated my go binary (not just the toolchain) to go1.22 and got rid of the error:

go: unknown GOEXPERIMENT rangefunc

However, the InvalidRangeExpr error is still reported despite adding GOEXPERIMENT=rangefunc to everywhere I could:

  • go env with go env -w GOEXPERIMENT=rangefunc
  • The local project env with .envrc
  • The gopls configuration as outlined above.

@findleyr
Copy link
Contributor

Could you share gopls logs from a short session that demonstrates the problem? That would help us investigate why it isn't working in your session.
https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md#capture-logs

@stephenafamo
Copy link
Author

My bad. I was using Mason on Neovim, which installs its own gopls which is at v14.2, when I force it to use my installed gopls v15.0-pre.3, I was able to get it to work, but only with a local env variable

  • Setting go env with go env -w GOEXPERIMENT=rangefunc did not work
  • Setting the go pls configurations (both env and buildFlags also did not work.

@RunThem
Copy link

RunThem commented Apr 16, 2024

@stephenafamo hi, did you solve this problem?

@alassek
Copy link

alassek commented Apr 24, 2024

@RunThem The solution is to update gopls in Mason:

:MasonInstall gopls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants