Commit fcd61eb0 authored by Alan Donovan's avatar Alan Donovan

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/2178Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent f005d6e3
......@@ -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
......
......@@ -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) {
......
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