File tree 1 file changed +16
-2
lines changed 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
12
12
"go/version"
13
13
"os"
14
14
"runtime"
15
+ "strings"
15
16
"time"
16
17
17
18
"honnef.co/go/tools/config"
@@ -311,11 +312,24 @@ func (prog *program) loadFromSource(spec *PackageSpec) (*Package, error) {
311
312
if prog .options .GoVersion == "module" {
312
313
if spec .Module != nil && spec .Module .GoVersion != "" {
313
314
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 ) {
315
329
// Staticcheck was built with a released version of Go.
316
330
// runtime.Version() returns something like "go1.22.4" or
317
331
// "go1.23rc1".
318
- our = runtime . Version ()
332
+ our = rversion
319
333
} else {
320
334
// Staticcheck was built with a development version of Go.
321
335
// runtime.Version() returns something like "devel go1.23-e8ee1dc4f9
You can’t perform that action at this time.
0 commit comments