Commit 6d8829e9 authored by Robert Griesemer's avatar Robert Griesemer

A <- token in an expression may introduce a channel type.

Fixes #530.

R=rsc
CC=golang-dev
https://golang.org/cl/193091
parent fcf45174
......@@ -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",
}
......
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