]> Cypherpunks repositories - gostls13.git/commitdiff
Clarify parsing of channel types.
authorRobert Griesemer <gri@golang.org>
Wed, 27 Jan 2010 17:35:39 +0000 (09:35 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 27 Jan 2010 17:35:39 +0000 (09:35 -0800)
R=r, rsc
CC=golang-dev
https://golang.org/cl/194091

doc/go_spec.html

index b5931c110e1d0cc8344d55c8cb72785f6796f7a6..3823876457fa746f82784b9bcb6485fcd78b2015 100644 (file)
@@ -1107,6 +1107,19 @@ SendChannel   = "chan" "&lt;-" ElementType .
 RecvChannel   = "&lt;-" "chan" ElementType .
 </pre>
 
+<p>
+To avoid a parsing ambiguity in cases such as <code>chan&lt;- chan int</code>,
+the Channel production's ElementType cannot be a RecvChannel.
+To construct such a type, parenthesize the RecvChannel first.
+</p>
+
+<pre>
+chan&lt;- chan int     // same as chan&lt;- (chan int)
+chan&lt;- &lt;-chan int   // same as chan&lt;- (&lt;-chan int)
+&lt;-chan &lt;-chan int   // same as &lt;-chan (&lt;-chan int)
+chan (&lt;-chan int)
+</pre>
+
 <p>
 Upon creation, a channel can be used both to send and to receive values.
 By conversion or assignment, a channel may be constrained only to send or
@@ -1126,7 +1139,6 @@ value can be made using the built-in function <code>make</code>,
 which takes the channel type and an optional capacity as arguments:
 </p>
 
-
 <pre>
 make(chan int, 100)
 </pre>