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>
// 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
// 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
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
// 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
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)
}
(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 \) */ )
}
--- /dev/null
+// 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)
+}
// there yet, so put it here for now. See also #20800.)
package e
-func([<-chan<-[func u){go // ERROR "unexpected u"
\ No newline at end of file
+func([<-chan<-[func u){go // ERROR "unexpected `u'"
\ No newline at end of file
package p
func f() {
- if f() true { // ERROR "unexpected true, expected {"
+ if f() true { // ERROR "unexpected `true', expected {"
}
- switch f() true { // ERROR "unexpected true, expected {"
+ switch f() true { // ERROR "unexpected `true', expected {"
}
}