@@ -198,7 +198,7 @@ var toolchainVersionRe *regexp.Regexp = regexp.MustCompile(`(?m)^([0-9]+\.[0-9]+
198
198
// Returns true if the `go.mod` file specifies a Go language version which is not of the format that
199
199
// is expected by the Go 1.21 and Go 1.22 toolchains for toolchain versions, and there is no
200
200
// explicit toolchain version declared.
201
- func hasInvalidToolchainVersion (modFile * modfile.File ) bool {
201
+ func hasInvalidToolchainVersion (installedToolchainVersion util. SemVer , modFile * modfile.File ) bool {
202
202
if modFile .Toolchain != nil {
203
203
// There is an explicit toolchain directive, so it doesn't matter what format the
204
204
// Go language version is in, since it will not be used as a fallback toolchain version.
@@ -208,8 +208,7 @@ func hasInvalidToolchainVersion(modFile *modfile.File) bool {
208
208
// does not match the toolchain version format in Go 1.21 and Go 1.22.
209
209
// This is a problem if the installed Go toolchain is within that version range
210
210
// as it will try to use the language version as the toolchain version.
211
- installed := util .NewSemVer (toolchain .GetEnvGoVersion ())
212
- return installed .IsAtLeast (toolchain .V1_21 ) && installed .IsOlderThan (toolchain .V1_23 )
211
+ return installedToolchainVersion .IsAtLeast (toolchain .V1_21 ) && installedToolchainVersion .IsOlderThan (toolchain .V1_23 )
213
212
}
214
213
return false
215
214
}
@@ -244,7 +243,7 @@ func LoadGoModules(emitDiagnostics bool, goModFilePaths []string) []*GoModule {
244
243
// there is no `toolchain` directive, check that it is a valid Go toolchain version. Otherwise,
245
244
// `go` commands which try to download the right version of the Go toolchain will fail. We detect
246
245
// this situation and emit a diagnostic.
247
- if hasInvalidToolchainVersion (modFile ) {
246
+ if hasInvalidToolchainVersion (util . NewSemVer ( toolchain . GetEnvGoVersion ()), modFile ) {
248
247
diagnostics .EmitInvalidToolchainVersion (goModFilePath , modFile .Go .Version )
249
248
}
250
249
}
0 commit comments