Closed matta closed 4 months ago
Related issues:
Note that when you do go install honnef.co/go/tools/cmd/staticcheck@dec278f
, it is not upgrading Go to the version in your module. You're actually compiling Staticcheck with go1.22.3 X:rangefunc
.
I don't yet know why this panics, and it shouldn't, but it works fine when you build Staticcheck with Go 1.23.
The crash was the symptom of a missing error check, fixed in 5950450ad4273d602a7f404fe5d80b8851c1336b. f4ee291f27bd904ad3669ffe8bda35cb72e134a0 improves Staticcheck to print a more useful error message when the version of Go Staticcheck was built with is older than the version required by the module under analysis.
That go install
is not using your module's Go version is documented in go help install
:
If the arguments have version suffixes (like
@latest
or@v1.0.0
), "go install" builds packages in module-aware mode, ignoring the go.mod file in the current directory or any parent directory, if there is one. This is useful for installing executables without affecting the dependencies of the main module.
That this makes the combination of go version
+ go install
confusing is being discussed at https://github.com/golang/go/issues/66518.
Note that when you do go install honnef.co/go/tools/cmd/staticcheck@dec278f, it is not upgrading Go to the version in your module. You're actually compiling Staticcheck with go1.22.3 X:rangefunc.
Ahh, I did not realize that these tools needed to be built with a version of go at least as recent as the go module they are analyzing. Makes sense, given that they are probably using huge portions of the compiler infrastructure.
https://github.com/dominikh/go-tools/commit/f4ee291f27bd904ad3669ffe8bda35cb72e134a0 improves Staticcheck to print a more useful error message when the version of Go Staticcheck was built with is older than the version required by the module under analysis.
Nice idea.
Basic issue
The second issue is a problem because currently gopls v0.16 says it supports rangefunc, but appears to require GOEXPERIMENT=rangefunc in 1.23rc1 projects before it stops reporting errors for them. See https://github.com/golang/go/issues/68248
Steps and more information:
Create a project with go.mod
and main.go:
Then install statichceck HEAD:
Then see two different kinds of failures. The first is with an empty GOEXPERIMENT.
Notice with the above: it is complaining about iter.go in the standard library, not the use of rangefunc in main.go.
Additional info