Repository navigation
Description
Go version
1.24.7
Output of go env in your module/workspace:
set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\Chris\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=toolchaintrace=1
set GOENV=C:\Users\Chris\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Chris\AppData\Local\Temp\go-build2159939572=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=C:\Users\Chris\proj\continuous-music\go.mod
set GOMODCACHE=C:\Users\Chris\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Chris\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\Chris\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.24.7.windows-amd64
set GOSUMDB=sum.golang.org
set GOTELEMETRY=on
set GOTELEMETRYDIR=C:\Users\Chris\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=go1.24.7+auto
set GOTOOLDIR=C:\Users\Chris\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.24.7.windows-amd64\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.7
set GOWORK=
set PKG_CONFIG=pkg-configWhat did you do?
I want to check if the new go vet checks introduced in Go 1.25 find any problems in my code before I upgrade. I would like to perform this check without modifying any version controlled files. Ideally I could run go vet -go=1.25.0 ./... for each of my modules. Since that is not a supported feature at this time I am trying to write a tool to simulate that feature.
The tool attempts to do that by:
- Copying the
go.modfile to a temporary directory. - Running
go get go@1.25in that directory. - Running
go vet -modfile=<tempdir>\go.mod ./...
What did you see happen?
The first two steps work as expected, but the third step fails with the following output. Note I have GODEBUG=toolchaintrace=1 while trying to debug the problem.
go: default toolchain set to go1.24.7 from GOTOOLCHAIN=go1.24.7+auto
go: using go1.24.7 toolchain from cache located at C:\Users\Chris\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.24.7.windows-amd64\bin\go
go: \tmp\go.mod requires go >= 1.25.1 (running go 1.24.7; GOTOOLCHAIN=go1.24.7+auto)
What did you expect to see?
I expected the +auto suffix of the GOTOOLCHAIN setting to allow automatically switching to the go1.25.1 toolchain required by the alternate go.mod file provided to the -modfile flag and the new version of go vet to scan the module for problems.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
gabyhelp commentedon Sep 12, 2025
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
mrkfrmn commentedon Sep 15, 2025
cc @golang/command-line
matloob commentedon Oct 7, 2025
We probably want to allow a toolchain switch in the middle of the execution of the go command if -modfile is set? I'd need to think about it some more to make sure that makes sense. But I think it would be too complicated to have the toolchain selection logic look at -modfile.
adonovan commentedon Feb 9, 2026
Is the actual problem "I can't test new go vet checks before the release"? If so then we should retitle this issue more descriptively without prescribing one specific technical approach to solving it.
thepudds commentedon Feb 9, 2026
Hi @adonovan, that was one of the key topics over in #57063. E.g., see the #57063 (comment) comment by @ChrisHines there:
Plus a ~couple of other related comments there...
(Putting my cards on the table, I'd love to see some conclusion to #57063, and maybe "how do I test new go vet checks" is somewhat naturally part of that, though of course free feel to do issue management / de-dup however you think best. 😅)
adonovan commentedon Feb 9, 2026
Better testing infrastructure for analyzers (from the micro level of "did applying this fix break the build?" to "what are the population statistics of this checker on the module mirror corpus of open-source Go code?") are on our roadmap for the next year.
ChrisHines commentedon Feb 10, 2026
Maybe, or maybe that should be its own issue, which I haven't filed yet.
I explained my use cases #57063. I talked with @dmitshur about adding a
-goflag togo vetat the GopherCon 2025 contributor summit. He suggested that I write an external tool to prototype the desired behavior as a way to demonstrate the value.My idea for how to implement that tool (without forking the whole go command) as described in the top post is what led to this issue.
This issue is about the apparent discrepancy between the docs for the -modfile flag and actual behavior. That seems like an issue regardless of the decision about how to test new go vet checks before upgrading, which I think I have explained well enough in #57063.
matloob commentedon Jun 26, 2026
I've put together a CL (https://go-review.googlesource.com/c/go/+/794900), but the more I think about it, the more I think we shouldn't do this (and that we should try to remove the -modfile flag altogther). I think the CL itself is a case against making the chonge.
The modfile flag is really weird- in the case of vet we don't even parse the flags before the command is invoked because it has custom parsing logic, so it's definitely not available when we do toolchain selection.
gopherbot commentedon Jun 26, 2026
Change https://go.dev/cl/794900 mentions this issue:
cmd/go: support switching to toolchains from -modfile in vetChrisHines commentedon Jun 26, 2026
I would not object to removing the
-modfileflag. The experiment that led to this issue is the only time I've ever tried to directly use it. My understanding is that one of the original motivations for-modfilewas forgoplsto use it. I don't know if it is still needed for that purpose. I don't know what other uses exist in the ecosystem.Having said that, it is surprising that
go vetdidn't already support-modfile. Ergonomicallygo vetis just like any other subcommand of thegocommand. There is no obvious reason why it should be different fromgo buildorgo test. Furthermore, the module reference docs for-modfileare clearly part of the "Build commands" section in whichgo vetis explicitly listed. Quoted below:So the current situation is that either the documentation is wrong or
go vethas a bug.adonovan commentedon Jun 26, 2026
It is used by gopls, in two places:
go mod tidy, so that the tidied go.mod file can be read without mutating the actual source;go get, for similar reasons.Overlays work great when you only need to provide alternate go.mod files as inputs, but -modfile is currently necessary when the updated file is an output. If the two commands above were changed so that they, like gofmt, printed the updated file to stdout, then we could stop using that flag and just use overlays.
matloob commentedon Jun 26, 2026
@ChrisHines I totally agree. If we don't get the CL in, we should definitely update the documentation. Ideally we can make a decision quickly. And as @adonovan mentions, we should have a plan to provide an alternative for gopls available before we remove the modfile flag, should we choose to do so. (See #80179 which I just filed and which I should have linked to here)