From fcd61eb07e11f856e62de3f24383f51627f25009 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 30 Dec 2014 14:44:41 -0500 Subject: [PATCH] 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 --- src/go/parser/parser.go | 2 +- src/go/parser/short_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go index 4a005d8ffa3..c9dbd06ad24 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 05e44de28a7..7d12170c0e4 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) {