Skip to content

Commit ab255d7

Browse files
committed
Go: Fix semver-related logic bugs
1 parent 86bf4fb commit ab255d7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

go/extractor/toolchain/toolchain.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var goVersions = map[string]struct{}{}
2323

2424
// Adds an entry to the set of installed Go versions for the normalised `version` number.
2525
func addGoVersion(version string) {
26-
goVersions[semver.Canonical(version)] = struct{}{}
26+
goVersions[semver.Canonical("v"+version)] = struct{}{}
2727
}
2828

2929
// Returns the current Go version as returned by 'go version', e.g. go1.14.4
@@ -42,14 +42,14 @@ func GetEnvGoVersion() string {
4242
}
4343

4444
goVersion = parseGoVersion(string(out))
45-
addGoVersion(goVersion)
45+
addGoVersion(goVersion[2:])
4646
}
4747
return goVersion
4848
}
4949

5050
// Determines whether, to our knowledge, `version` is available on the current system.
5151
func HasGoVersion(version string) bool {
52-
_, found := goVersions[semver.Canonical(version)]
52+
_, found := goVersions[semver.Canonical("v"+version)]
5353
return found
5454
}
5555

@@ -63,7 +63,7 @@ func InstallVersion(workingDir string, version string) bool {
6363
// Construct a command to invoke `go version` with `GOTOOLCHAIN=go1.N.0` to give
6464
// Go a valid toolchain version to download the toolchain we need; subsequent commands
6565
// should then work even with an invalid version that's still in `go.mod`
66-
toolchainArg := "GOTOOLCHAIN=go" + semver.Canonical(version)
66+
toolchainArg := "GOTOOLCHAIN=go" + semver.Canonical("v" + version)[1:]
6767
versionCmd := Version()
6868
versionCmd.Dir = workingDir
6969
versionCmd.Env = append(os.Environ(), toolchainArg)

0 commit comments

Comments
 (0)