Skip to content

go/version: does not support the X: suffix from go env GOVERSION #75953

@mvdan

Description

@mvdan

go env GOVERSION says it prints runtime.Version, and that API is documented as:

// buildVersion is the Go tree's version string at build time.
//
// If any GOEXPERIMENTs are set to non-default values, it will include
// "X:<GOEXPERIMENT>".
//
// This is set by the linker.
//
// This is accessed by "go version <binary>".
var buildVersion string

// Version returns the Go tree's version string.
// It is either the commit hash and date at the time of the build or,
// when possible, a release tag like "go1.3".
func Version() string {
	return buildVersion
}

So, for example, GOEXPERIMENT=nodwarf5 ./make.bash leads to something like:

$ go env GOVERSION
go1.25.3 X:nodwarf5

Similarly, when running tip, one can end up with a "devel" version like:

$ go env GOVERSION
go1.26-devel_36863d6194 2025-10-17 01:07:59 -0700

However, the X: suffix form is not supported by go/version; as of 36863d6, the program

package main

import "go/version"

func main() {
	println(version.IsValid("go1.25.3"))
	println(version.IsValid("go1.26-devel_36863d6194 2025-10-17 01:07:59 -0700"))
	println(version.IsValid("go1.25.3 X:nodwarf5"))
}

prints

true
true
false

My understanding is that go env GOVERSION should be parseable by go/version at all times, as long as Go was built in the usual way without a custom version string in a VERSION file at build time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions