Commit 48ccf824 authored by Robert Griesemer's avatar Robert Griesemer

go/parser: don't require parens around composite literals inside a composite literal

	   within an if, for, or switch control clause

R=rsc
CC=golang-dev
https://golang.org/cl/943046
parent 2bfc2d77
......@@ -1105,9 +1105,11 @@ func (p *parser) parseCompositeLit(typ ast.Expr) ast.Expr {
lbrace := p.expect(token.LBRACE)
var elts []ast.Expr
p.exprLev++
if p.tok != token.RBRACE {
elts = p.parseElementList()
}
p.exprLev--
rbrace := p.expect(token.RBRACE)
return &ast.CompositeLit{typ, lbrace, elts, rbrace}
}
......
......@@ -38,6 +38,9 @@ var validPrograms = []interface{}{
`package main; func f(func() func() func())` + "\n",
`package main; func f(...)` + "\n",
`package main; func f(float, ...int)` + "\n",
`package main; type T []int; var a []bool; func f() { if a[T{42}[0]] {} }` + "\n",
`package main; type T []int; func g(int) bool { return true }; func f() { if g(T{42}[0]) {} }` + "\n",
`package main; type T []int; func f() { for _ = range []int{T{42}[0]} {} }` + "\n",
}
......
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