Commit 8fab2929 authored by Robert Griesemer's avatar Robert Griesemer

go/parser: better error message for unexpected ',' in struct type

Fixes #12437.

Change-Id: I5463970a6259527003eb0e12903a338cc78e0683
Reviewed-on: https://go-review.googlesource.com/14564Reviewed-by: default avatarChris Manghane <cmang@golang.org>
parent ffd7d317
......@@ -410,9 +410,14 @@ func (p *parser) expectClosing(tok token.Token, context string) token.Pos {
func (p *parser) expectSemi() {
// semicolon is optional before a closing ')' or '}'
if p.tok != token.RPAREN && p.tok != token.RBRACE {
if p.tok == token.SEMICOLON {
switch p.tok {
case token.COMMA:
// permit a ',' instead of a ';' but complain
p.errorExpected(p.pos, "';'")
fallthrough
case token.SEMICOLON:
p.next()
} else {
default:
p.errorExpected(p.pos, "';'")
syncStmt(p)
}
......
......@@ -106,6 +106,8 @@ var invalids = []string{
`package p; const x /* ERROR "missing constant value" */ ;`, // issue 9639
`package p; const x /* ERROR "missing constant value" */ int;`, // issue 9639
`package p; const (x = 0; y; z /* ERROR "missing constant value" */ int);`, // issue 9639
`package p; var _ = struct { x int, /* ERROR "expected ';', found ','" */ }{}`, // issue 12437
`package p; var _ = struct { x int, /* ERROR "expected ';', found ','" */ y float }{}`, // issue 12437
}
func TestInvalid(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment