diff options
| author | Zxilly <zhouxinyu1001@gmail.com> | 2024-02-22 21:09:55 +0000 |
|---|---|---|
| committer | Robert Griesemer <gri@google.com> | 2024-02-27 16:22:24 +0000 |
| commit | 856355a9133a3c96efcd35f355637d33c9fde7ea (patch) | |
| tree | 3e533cf1ffd4d2092ce5875b5ef66c6d02ea79e5 /src | |
| parent | f326b3e2b3761ae4562204a5faee41b4d5211502 (diff) | |
| download | go-856355a9133a3c96efcd35f355637d33c9fde7ea.tar.xz | |
cmd/compile: use quotes to wrap user-supplied token
Use quotes to wrap user-supplied token in the syntax error message.
Updates #65790
Change-Id: I631a63df4a6bb8615b7850a324d812190bc15f30
GitHub-Last-Rev: f291e1d5a6adee558d21bb7e0a3a17471bad7eb6
GitHub-Pull-Request: golang/go#65840
Reviewed-on: https://go-review.googlesource.com/c/go/+/565518
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src')
6 files changed, 24 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go index 1569b5e987..f75f86587a 100644 --- a/src/cmd/compile/internal/syntax/parser.go +++ b/src/cmd/compile/internal/syntax/parser.go @@ -267,7 +267,9 @@ func (p *parser) syntaxErrorAt(pos Pos, msg string) { // determine token string var tok string switch p.tok { - case _Name, _Semi: + case _Name: + tok = "`" + p.lit + "'" + case _Semi: tok = p.lit case _Literal: tok = "literal " + p.lit diff --git a/src/cmd/compile/internal/syntax/testdata/issue20789.go b/src/cmd/compile/internal/syntax/testdata/issue20789.go index 0d5988b9a6..8a6db6d2ee 100644 --- a/src/cmd/compile/internal/syntax/testdata/issue20789.go +++ b/src/cmd/compile/internal/syntax/testdata/issue20789.go @@ -6,4 +6,4 @@ // Line 9 must end in EOF for this test (no newline). package e -func([<-chan<-[func /* ERROR unexpected u */ u){go
\ No newline at end of file +func([<-chan<-[func /* ERROR unexpected `u' */ u){go
\ No newline at end of file diff --git a/src/cmd/compile/internal/syntax/testdata/issue47704.go b/src/cmd/compile/internal/syntax/testdata/issue47704.go index e4cdad148f..aab3790560 100644 --- a/src/cmd/compile/internal/syntax/testdata/issue47704.go +++ b/src/cmd/compile/internal/syntax/testdata/issue47704.go @@ -7,7 +7,7 @@ package p func _() { _ = m[] // ERROR expected operand _ = m[x,] - _ = m[x /* ERROR unexpected a */ a b c d] + _ = m[x /* ERROR unexpected `a' */ a b c d] } // test case from the issue diff --git a/src/cmd/compile/internal/syntax/testdata/issue49205.go b/src/cmd/compile/internal/syntax/testdata/issue49205.go index bbcc950c5c..9b6c769703 100644 --- a/src/cmd/compile/internal/syntax/testdata/issue49205.go +++ b/src/cmd/compile/internal/syntax/testdata/issue49205.go @@ -7,7 +7,7 @@ package p // test case from issue type _ interface{ - m /* ERROR unexpected int in interface type; possibly missing semicolon or newline or } */ int + m /* ERROR unexpected `int' in interface type; possibly missing semicolon or newline or } */ int } // other cases where the fix for this issue affects the error message @@ -16,12 +16,12 @@ const ( x int = 10 /* ERROR unexpected literal "foo" in grouped declaration; possibly missing semicolon or newline or \) */ "foo" ) -var _ = []int{1, 2, 3 /* ERROR unexpected int in composite literal; possibly missing comma or } */ int } +var _ = []int{1, 2, 3 /* ERROR unexpected `int' in composite literal; possibly missing comma or } */ int } type _ struct { x y /* ERROR syntax error: unexpected comma in struct type; possibly missing semicolon or newline or } */ , } -func f(a, b c /* ERROR unexpected d in parameter list; possibly missing comma or \) */ d) { - f(a, b, c /* ERROR unexpected d in argument list; possibly missing comma or \) */ d) +func f(a, b c /* ERROR unexpected `d' in parameter list; possibly missing comma or \) */ d) { + f(a, b, c /* ERROR unexpected `d' in argument list; possibly missing comma or \) */ d) } diff --git a/src/cmd/compile/internal/syntax/testdata/issue52391.go b/src/cmd/compile/internal/syntax/testdata/issue52391.go index f2098ceadb..42b71cc83a 100644 --- a/src/cmd/compile/internal/syntax/testdata/issue52391.go +++ b/src/cmd/compile/internal/syntax/testdata/issue52391.go @@ -13,5 +13,5 @@ type _ interface { (int) | (string) (int) | ~(string) (/* ERROR unexpected ~ */ ~int) - (int /* ERROR unexpected \| */ | /* ERROR unexpected string */ string /* ERROR unexpected \) */ ) + (int /* ERROR unexpected \| */ | /* ERROR unexpected `string' */ string /* ERROR unexpected \) */ ) } diff --git a/src/cmd/compile/internal/syntax/testdata/issue65970.go b/src/cmd/compile/internal/syntax/testdata/issue65970.go new file mode 100644 index 0000000000..07ffd12678 --- /dev/null +++ b/src/cmd/compile/internal/syntax/testdata/issue65970.go @@ -0,0 +1,14 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import ( + "fmt" +) + +func f() { + int status // ERROR syntax error: unexpected `status' at end of statement + fmt.Println(status) +} |
