Robert Griesemer 0775730180 cmd/compile/internal/syntax: better errors for syntax errors in lists
For syntax errors in various (syntactic) lists, instead of reporting
a set of "expected" tokens (which may be incomplete), provide context
and mention "possibly missing" tokens. The result is a friendlier and
more accurate error message.

Fixes #49205.

Change-Id: I38ae7bf62febfe790075e62deb33ec8c17d64476
Reviewed-on: https://go-review.googlesource.com/c/go/+/396914
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-31 00:26:58 +00:00

28 lines
932 B
Go

// Copyright 2022 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
// test case from issue
type _ interface{
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
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 }
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)
}