From 766dc5df63e3e3e5cd6b1682f522a01c99723beb Mon Sep 17 00:00:00 2001 From: Sam Thanawalla Date: Fri, 2 Feb 2024 20:14:19 +0000 Subject: [PATCH] modfile: use new go version string format in WorkFile.add error For golang/go#61888 Tested: Ran go test ./modfile Change-Id: I254fe559f25ac643e842a935954d18744ae87b0b Reviewed-on: https://go-review.googlesource.com/c/mod/+/560875 Reviewed-by: Bryan Mills Run-TryBot: Sam Thanawalla TryBot-Result: Gopher Robot --- modfile/rule.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modfile/rule.go b/modfile/rule.go index 35fd1f5..26acaa5 100644 --- a/modfile/rule.go +++ b/modfile/rule.go @@ -308,6 +308,7 @@ var laxGoVersionRE = lazyregexp.New(`^v?(([1-9][0-9]*)\.(0|[1-9][0-9]*))([^0-9]. // Toolchains must be named beginning with `go1`, // like "go1.20.3" or "go1.20.3-gccgo". As a special case, "default" is also permitted. +// TODO(samthanawalla): Replace regex with https://pkg.go.dev/go/version#IsValid in 1.23+ var ToolchainRE = lazyregexp.New(`^default$|^go1($|\.)`) func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, args []string, fix VersionFixer, strict bool) { @@ -384,7 +385,7 @@ func (f *File) add(errs *ErrorList, block *LineBlock, line *Line, verb string, a errorf("toolchain directive expects exactly one argument") return } else if strict && !ToolchainRE.MatchString(args[0]) { - errorf("invalid toolchain version '%s': must match format go1.23.0 or local", args[0]) + errorf("invalid toolchain version '%s': must match format go1.23.0 or default", args[0]) return } f.Toolchain = &Toolchain{Syntax: line} @@ -630,7 +631,7 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string, errorf("go directive expects exactly one argument") return } else if !GoVersionRE.MatchString(args[0]) { - errorf("invalid go version '%s': must match format 1.23", args[0]) + errorf("invalid go version '%s': must match format 1.23.0", args[0]) return } @@ -646,7 +647,7 @@ func (f *WorkFile) add(errs *ErrorList, line *Line, verb string, args []string, errorf("toolchain directive expects exactly one argument") return } else if !ToolchainRE.MatchString(args[0]) { - errorf("invalid toolchain version '%s': must match format go1.23 or local", args[0]) + errorf("invalid toolchain version '%s': must match format go1.23.0 or default", args[0]) return }