return &ast.CallExpr{Fun: fun, Lparen: lparen, Args: list, Ellipsis: ellipsis, Rparen: rparen}
}
-func (p *parser) parseElement(keyOk bool) ast.Expr {
+func (p *parser) parseValue(keyOk bool) ast.Expr {
if p.trace {
defer un(trace(p, "Element"))
}
x := p.checkExpr(p.parseExpr(keyOk))
if keyOk {
if p.tok == token.COLON {
- colon := p.pos
- p.next()
// Try to resolve the key but don't collect it
// as unresolved identifier if it fails so that
// we don't get (possibly false) errors about
// undeclared names.
p.tryResolve(x, false)
- return &ast.KeyValueExpr{Key: x, Colon: colon, Value: p.parseElement(false)}
+ } else {
+ // not a key
+ p.resolve(x)
}
- p.resolve(x) // not a key
+ }
+
+ return x
+}
+
+func (p *parser) parseElement() ast.Expr {
+ if p.trace {
+ defer un(trace(p, "Element"))
+ }
+
+ x := p.parseValue(true)
+ if p.tok == token.COLON {
+ colon := p.pos
+ p.next()
+ x = &ast.KeyValueExpr{Key: x, Colon: colon, Value: p.parseValue(false)}
}
return x
}
for p.tok != token.RBRACE && p.tok != token.EOF {
- list = append(list, p.parseElement(true))
+ list = append(list, p.parseElement())
if !p.atComma("composite literal") {
break
}
`package p; func _(x interface{f()}) { interface{f()}(x).f() }`,
`package p; func _(x chan int) { chan int(x) <- 0 }`,
`package p; const (x = 0; y; z)`, // issue 9639
+ `package p; var _ = map[P]int{P{}:0, {}:1}`,
+ `package p; var _ = map[*P]int{&P{}:0, {}:1}`,
}
func TestValid(t *testing.T) {