1
0
mirror of https://github.com/golang/go synced 2024-11-25 06:07:58 -07:00

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
This commit is contained in:
Robert Griesemer 2010-04-27 11:57:17 -07:00
parent 2bfc2d7772
commit 48ccf8247e
2 changed files with 5 additions and 0 deletions

View File

@ -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}
}

View File

@ -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",
}