]> Cypherpunks repositories - gostls13.git/commitdiff
A <- token in an expression may introduce a channel type.
authorRobert Griesemer <gri@golang.org>
Mon, 25 Jan 2010 20:03:53 +0000 (12:03 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 25 Jan 2010 20:03:53 +0000 (12:03 -0800)
Fixes #530.

R=rsc
CC=golang-dev
https://golang.org/cl/193091

src/pkg/go/parser/parser.go
src/pkg/go/parser/parser_test.go

index f5e8f839eb116a5e400eac40bde90e4509f35a0f..a680d862e56c3406915a50febbd730382e5acabb 100644 (file)
@@ -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()
index 2f7bace6ffb9bd36e934cb642383629dab616ed1..9e37551623fa5f1b15c33db62afed97715b7bcc2 100644 (file)
@@ -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",
 }