Skip to content

Commit 2f4157c

Browse files
committed
Go: Make installed toolchain version a parameter of hasInvalidToolchainVersion
1 parent 97832b9 commit 2f4157c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

go/extractor/project/project.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)