mirror of
https://github.com/golang/go
synced 2024-11-25 05:57:57 -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:
parent
2bfc2d7772
commit
48ccf8247e
@ -1105,9 +1105,11 @@ func (p *parser) parseCompositeLit(typ ast.Expr) ast.Expr {
|
|||||||
|
|
||||||
lbrace := p.expect(token.LBRACE)
|
lbrace := p.expect(token.LBRACE)
|
||||||
var elts []ast.Expr
|
var elts []ast.Expr
|
||||||
|
p.exprLev++
|
||||||
if p.tok != token.RBRACE {
|
if p.tok != token.RBRACE {
|
||||||
elts = p.parseElementList()
|
elts = p.parseElementList()
|
||||||
}
|
}
|
||||||
|
p.exprLev--
|
||||||
rbrace := p.expect(token.RBRACE)
|
rbrace := p.expect(token.RBRACE)
|
||||||
return &ast.CompositeLit{typ, lbrace, elts, 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(func() func() func())` + "\n",
|
||||||
`package main; func f(...)` + "\n",
|
`package main; func f(...)` + "\n",
|
||||||
`package main; func f(float, ...int)` + "\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",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user