compiler: better error for unexpected digit
A digit character is not invalid in general, but it's not permitted
at the start of an identifier. Report a better error message.
The test case is issue11359.go in the source repo.
Change-Id: If8c55aba710419715a7932067023102f61efc742
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/278174
Trust: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/go/lex.cc b/go/lex.cc
index 156a90c..e71b8cd 100644
--- a/go/lex.cc
+++ b/go/lex.cc
@@ -743,6 +743,13 @@
if (Lex::is_unicode_letter(ci))
return this->gather_identifier();
+ if (!issued_error && Lex::is_unicode_digit(ci))
+ {
+ go_error_at(this->location(),
+ "identifier cannot begin with digit");
+ issued_error = true;
+ }
+
if (!issued_error)
go_error_at(this->location(),
"invalid character 0x%x in input file",