@@ -773,15 +773,60 @@ func getVersionWhenGoModVersionNotFound(v versionInfo) (msg, version string) {
773
773
}
774
774
775
775
// Assuming `v.goModVersion` is above the supported range, emit a diagnostic and return the
776
- // empty string to indicate that we should not attempt to install a version of Go.
776
+ // version to install, or the empty string if we should not attempt to install a version of Go.
777
777
func getVersionWhenGoModVersionTooHigh (v versionInfo ) (msg , version string ) {
778
- // The project is intended to be built with a version of Go that is above the supported
779
- // range. We do not install a version of Go.
780
- msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
781
- ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
782
- "). Not requesting any version of Go."
783
- version = ""
784
- diagnostics .EmitGoModVersionTooHigh (msg )
778
+ if ! v .goEnvVersionFound {
779
+ // The version in the `go.mod` file is above the supported range. There is no Go version
780
+ // installed. We install the maximum supported version as a best effort.
781
+ msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
782
+ ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
783
+ "). No version of Go installed. Requesting the maximum supported version of Go (" +
784
+ maxGoVersion + ")."
785
+ version = maxGoVersion
786
+ diagnostics .EmitGoModVersionTooHighAndNoGoEnv (msg )
787
+ } else if aboveSupportedRange (v .goEnvVersion ) {
788
+ // The version in the `go.mod` file is above the supported range. The version of Go that
789
+ // is installed is above the supported range. We do not install a version of Go.
790
+ msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
791
+ ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
792
+ "). The version of Go installed in the environment (" + v .goEnvVersion +
793
+ ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
794
+ "). Not requesting any version of Go."
795
+ version = ""
796
+ diagnostics .EmitGoModVersionTooHighAndEnvVersionTooHigh (msg )
797
+ } else if belowSupportedRange (v .goEnvVersion ) {
798
+ // The version in the `go.mod` file is above the supported range. The version of Go that
799
+ // is installed is below the supported range. We install the maximum supported version as
800
+ // a best effort.
801
+ msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
802
+ ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
803
+ "). The version of Go installed in the environment (" + v .goEnvVersion +
804
+ ") is below the supported range (" + minGoVersion + "-" + maxGoVersion +
805
+ "). Requesting the maximum supported version of Go (" + maxGoVersion + ")."
806
+ version = maxGoVersion
807
+ diagnostics .EmitGoModVersionTooHighAndEnvVersionTooLow (msg )
808
+ } else if semver .Compare ("v" + maxGoVersion , "v" + v .goEnvVersion ) > 0 {
809
+ // The version in the `go.mod` file is above the supported range. The version of Go that
810
+ // is installed is supported and below the maximum supported version. We install the
811
+ // maximum supported version as a best effort.
812
+ msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
813
+ ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
814
+ "). The version of Go installed in the environment (" + v .goEnvVersion +
815
+ ") is below the maximum supported version (" + maxGoVersion +
816
+ "). Requesting the maximum supported version of Go (" + maxGoVersion + ")."
817
+ version = maxGoVersion
818
+ diagnostics .EmitGoModVersionTooHighAndEnvVersionBelowMax (msg )
819
+ } else {
820
+ // The version in the `go.mod` file is above the supported range. The version of Go that
821
+ // is installed is the maximum supported version. We do not install a version of Go.
822
+ msg = "The version of Go found in the `go.mod` file (" + v .goModVersion +
823
+ ") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
824
+ "). The version of Go installed in the environment (" + v .goEnvVersion +
825
+ ") is the maximum supported version (" + maxGoVersion +
826
+ "). Not requesting any version of Go."
827
+ version = ""
828
+ diagnostics .EmitGoModVersionTooHighAndEnvVersionMax (msg )
829
+ }
785
830
786
831
return msg , version
787
832
}
0 commit comments