]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: better error message for unexpected ',' in struct type
authorRobert Griesemer <gri@golang.org>
Mon, 14 Sep 2015 19:01:04 +0000 (12:01 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 14 Sep 2015 23:37:18 +0000 (23:37 +0000)
Fixes #12437.

Change-Id: I5463970a6259527003eb0e12903a338cc78e0683
Reviewed-on: https://go-review.googlesource.com/14564
Reviewed-by: Chris Manghane <cmang@golang.org>
src/go/parser/parser.go
src/go/parser/short_test.go

index e82c0bd12231e6763d1627774d0390dc34514942..855caa3daa4a96e7700c90208cc613fcfe78f8ed 100644 (file)
@@ -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)
                }
index ef2ffadbd981c09400d5bd4c2e92fcdbf4164b18..7cbdaf2e24ba876bff774a7c99a34e07c86435a3 100644 (file)
@@ -101,11 +101,13 @@ var invalids = []string{
        `package p; func f() { defer func() {} /* ERROR HERE "function must be invoked" */ }`,
        `package p; func f() { go func() { func() { f(x func /* ERROR "missing ','" */ (){}) } } }`,
        `package p; func f(x func(), u v func /* ERROR "missing ','" */ ()){}`,
-       `package p; func f() (a b string /* ERROR "missing ','" */ , ok bool)`,           // issue 8656
-       `package p; var x /* ERROR "missing variable type or initialization" */ , y, z;`, // issue 9639
-       `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; func f() (a b string /* ERROR "missing ','" */ , ok bool)`,                 // issue 8656
+       `package p; var x /* ERROR "missing variable type or initialization" */ , y, z;`,       // issue 9639
+       `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) {