Skip to content

Commit 6052711

Browse files
committed
go/loader: handle experimental features in version detection
Closes: gh-1586 (cherry picked from commit 94a1600)
1 parent 516152d commit 6052711

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

go/loader/loader.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"go/version"
1313
"os"
1414
"runtime"
15+
"strings"
1516
"time"
1617

1718
"honnef.co/go/tools/config"
@@ -311,11 +312,24 @@ func (prog *program) loadFromSource(spec *PackageSpec) (*Package, error) {
311312
if prog.options.GoVersion == "module" {
312313
if spec.Module != nil && spec.Module.GoVersion != "" {
313314
var our string
314-
if version.IsValid(runtime.Version()) {
315+
rversion := runtime.Version()
316+
if fields := strings.Fields(rversion); len(fields) > 0 {
317+
// When using GOEXPERIMENT, the version returned by
318+
// runtime.Version might look something like "go1.23.0
319+
// X:boringcrypto", which wouldn't be accepted by
320+
// version.IsValid even though it's a proper release.
321+
//
322+
// When using a development build, the version looks like "devel
323+
// go1.24-206df8e7ad Tue Aug 13 16:44:16 2024 +0000", and taking
324+
// the first field of that won't change whether it's accepted as
325+
// valid or not.
326+
rversion = fields[0]
327+
}
328+
if version.IsValid(rversion) {
315329
// Staticcheck was built with a released version of Go.
316330
// runtime.Version() returns something like "go1.22.4" or
317331
// "go1.23rc1".
318-
our = runtime.Version()
332+
our = rversion
319333
} else {
320334
// Staticcheck was built with a development version of Go.
321335
// runtime.Version() returns something like "devel go1.23-e8ee1dc4f9

0 commit comments

Comments
 (0)