@@ -198,7 +198,7 @@ var toolchainVersionRe *regexp.Regexp = regexp.MustCompile(`(?m)^([0-9]+\.[0-9]+
198198// Returns true if the `go.mod` file specifies a Go language version which is not of the format that
199199// is expected by the Go 1.21 and Go 1.22 toolchains for toolchain versions, and there is no
200200// explicit toolchain version declared.
201- func hasInvalidToolchainVersion (modFile * modfile.File ) bool {
201+ func hasInvalidToolchainVersion (installedToolchainVersion util. SemVer , modFile * modfile.File ) bool {
202202 if modFile .Toolchain != nil {
203203 // There is an explicit toolchain directive, so it doesn't matter what format the
204204 // 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 {
208208 // does not match the toolchain version format in Go 1.21 and Go 1.22.
209209 // This is a problem if the installed Go toolchain is within that version range
210210 // 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 )
213212 }
214213 return false
215214}
@@ -244,7 +243,7 @@ func LoadGoModules(emitDiagnostics bool, goModFilePaths []string) []*GoModule {
244243 // there is no `toolchain` directive, check that it is a valid Go toolchain version. Otherwise,
245244 // `go` commands which try to download the right version of the Go toolchain will fail. We detect
246245 // this situation and emit a diagnostic.
247- if hasInvalidToolchainVersion (modFile ) {
246+ if hasInvalidToolchainVersion (util . NewSemVer ( toolchain . GetEnvGoVersion ()), modFile ) {
248247 diagnostics .EmitInvalidToolchainVersion (goModFilePath , modFile .Go .Version )
249248 }
250249 }
0 commit comments