Skip to content

cmd/go: Go modules initialised by go1.21.1 cannot be built using go1.20.8 #63279

@soh-ew

Description

@soh-ew

What version of Go are you using (go version)?

$ go version 1.21.1

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/enwei.soh/Library/Caches/go-build'
GOENV='/Users/enwei.soh/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/enwei.soh/gopath/pkg/mod'
GONOPROXY='none'
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/enwei.soh/gopath'
GOPRIVATE=''
GOPROXY='proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.1/libexec' 
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/40/90j35z011n14czs8pbg736rr0000gn/T/go-build3498449936=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

We are attempting to make builds for both current and previous Go language versions (1.21 and 1.20). However, this does not work for Go modules initialised by go1.21.1, or any go directive set to 1.21.1 in the go.mod file, as go1.20.8 does not recognise the go directive with a X.Y.Z format.

  1. Run go mod init in an empty folder
  2. add a dummy main file (e.g. https://go.dev/play/p/UPxh4-pRY1V)
  3. Run GOTOOLCHAIN=go1.20.8 go build main.go

What did you expect to see?

main binary created.

What did you see instead?

go: errors parsing go.mod:
/Users/enwei.soh/gopath/src/testgo21/go.mod:3: invalid go version '1.21.1': must match format 1.23

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions