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 <bcmills@google.com>
Run-TryBot: Sam Thanawalla <samthanawalla@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
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 @@
 
 // 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 @@
 			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 @@
 			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 @@
 			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
 		}