From: Alan Donovan Date: Tue, 30 Dec 2014 19:44:41 +0000 (-0500) Subject: go/parser: add {map,chan,interface} to expression lookahead tokens X-Git-Tag: go1.5beta1~2494 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fcd61eb07e11f856e62de3f24383f51627f25009;p=gostls13.git go/parser: add {map,chan,interface} to expression lookahead tokens + 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 --- diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go index 4a005d8ffa..c9dbd06ad2 100644 --- a/src/go/parser/parser.go +++ b/src/go/parser/parser.go @@ -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 diff --git a/src/go/parser/short_test.go b/src/go/parser/short_test.go index 05e44de28a..7d12170c0e 100644 --- a/src/go/parser/short_test.go +++ b/src/go/parser/short_test.go @@ -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) {