mirror of
https://github.com/golang/go
synced 2024-11-25 04:57:56 -07:00
A <- token in an expression may introduce a channel type.
Fixes #530. R=rsc CC=golang-dev https://golang.org/cl/193091
This commit is contained in:
parent
fcf4517423
commit
6d8829e931
@ -1221,14 +1221,27 @@ func (p *parser) parseUnaryExpr() ast.Expr {
|
||||
}
|
||||
|
||||
switch p.tok {
|
||||
case token.ADD, token.SUB, token.NOT, token.XOR, token.ARROW, token.AND, token.RANGE:
|
||||
case token.ADD, token.SUB, token.NOT, token.XOR, token.AND, token.RANGE:
|
||||
pos, op := p.pos, p.tok
|
||||
p.next()
|
||||
x := p.parseUnaryExpr()
|
||||
return &ast.UnaryExpr{pos, op, p.checkExpr(x)}
|
||||
|
||||
case token.ARROW:
|
||||
// channel type or receive expression
|
||||
pos := p.pos
|
||||
p.next()
|
||||
if p.tok == token.CHAN {
|
||||
p.next()
|
||||
value := p.parseType()
|
||||
return &ast.ChanType{pos, ast.RECV, value}
|
||||
}
|
||||
|
||||
x := p.parseUnaryExpr()
|
||||
return &ast.UnaryExpr{pos, token.ARROW, p.checkExpr(x)}
|
||||
|
||||
case token.MUL:
|
||||
// unary "*" expression or pointer type
|
||||
// pointer type or unary "*" expression
|
||||
pos := p.pos
|
||||
p.next()
|
||||
x := p.parseUnaryExpr()
|
||||
|
@ -32,6 +32,8 @@ var validPrograms = []interface{}{
|
||||
`package main;`,
|
||||
`package main; import "fmt"; func main() { fmt.Println("Hello, World!") }` + "\n",
|
||||
`package main; func main() { if f(T{}) {} }` + "\n",
|
||||
`package main; func main() { _ = (<-chan int)(x) }` + "\n",
|
||||
`package main; func main() { _ = (<-chan <-chan int)(x) }` + "\n",
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user