]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: add {map,chan,interface} to expression lookahead tokens
authorAlan Donovan <adonovan@google.com>
Tue, 30 Dec 2014 19:44:41 +0000 (14:44 -0500)
committerAlan Donovan <adonovan@google.com>
Tue, 30 Dec 2014 21:49:25 +0000 (21:49 +0000)
+ tests that these parse:
  map[int]int{}[0]++
  interface{f()}(x).f()
  chan int(x) <- 0

Fixes #9474

Change-Id: If9fa57b3ab415ae7e93aa9935ec63edda8fe9d4f
Reviewed-on: https://go-review.googlesource.com/2178
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/parser/parser.go
src/go/parser/short_test.go

index 4a005d8ffa3892a88c597ad7de13903d5620a5ba..c9dbd06ad24114497ae44f06b6e4d3b4d9276169 100644 (file)
@@ -2123,7 +2123,7 @@ func (p *parser) parseStmt() (s ast.Stmt) {
        case
                // tokens that may start an expression
                token.IDENT, token.INT, token.FLOAT, token.IMAG, token.CHAR, token.STRING, token.FUNC, token.LPAREN, // operands
-               token.LBRACK, token.STRUCT, // composite types
+               token.LBRACK, token.STRUCT, token.MAP, token.CHAN, token.INTERFACE, // composite types
                token.ADD, token.SUB, token.MUL, token.AND, token.XOR, token.ARROW, token.NOT: // unary operators
                s, _ = p.parseSimpleStmt(labelOk)
                // because of the required look-ahead, labeled statements are
index 05e44de28a72dbee1f93dcfe3a730c663ff5df48..7d12170c0e43ab3b0623130c86109bad6b78c5fd 100644 (file)
@@ -40,6 +40,9 @@ var valids = []string{
        `package p; func (*(T),) m() {}`,
        `package p; func _(x []int) { for range x {} }`,
        `package p; func _() { if [T{}.n]int{} {} }`,
+       `package p; func _() { map[int]int{}[0]++; map[int]int{}[0] += 1 }`,
+       `package p; func _(x interface{f()}) { interface{f()}(x).f() }`,
+       `package p; func _(x chan int) { chan int(x) <- 0 }`,
 }
 
 func TestValid(t *testing.T) {