mirror of
https://github.com/golang/go
synced 2024-11-21 19:34:46 -07:00
Clarify parsing of channel types.
R=r, rsc CC=golang-dev https://golang.org/cl/194091
This commit is contained in:
parent
2a01d72878
commit
1c369bd55f
@ -1107,6 +1107,19 @@ SendChannel = "chan" "<-" ElementType .
|
|||||||
RecvChannel = "<-" "chan" ElementType .
|
RecvChannel = "<-" "chan" ElementType .
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
To avoid a parsing ambiguity in cases such as <code>chan<- chan int</code>,
|
||||||
|
the Channel production's ElementType cannot be a RecvChannel.
|
||||||
|
To construct such a type, parenthesize the RecvChannel first.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
chan<- chan int // same as chan<- (chan int)
|
||||||
|
chan<- <-chan int // same as chan<- (<-chan int)
|
||||||
|
<-chan <-chan int // same as <-chan (<-chan int)
|
||||||
|
chan (<-chan int)
|
||||||
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Upon creation, a channel can be used both to send and to receive values.
|
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
|
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:
|
which takes the channel type and an optional capacity as arguments:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
make(chan int, 100)
|
make(chan int, 100)
|
||||||
</pre>
|
</pre>
|
||||||
|
Loading…
Reference in New Issue
Block a user