2012-02-17 04:48:57 +00:00
|
|
|
// errorcheck
|
2009-05-22 16:53:25 +00:00
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2012-02-19 06:44:02 +00:00
|
|
|
// Test various correct and incorrect permutations of send-only,
|
|
|
|
// receive-only, and bidirectional channels.
|
|
|
|
// Does not compile.
|
|
|
|
|
2009-05-22 16:53:25 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
var (
|
2010-09-04 00:36:13 +00:00
|
|
|
cr <-chan int
|
|
|
|
cs chan<- int
|
2011-01-31 23:36:28 +00:00
|
|
|
c chan int
|
2009-05-22 16:53:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2011-01-31 23:36:28 +00:00
|
|
|
cr = c // ok
|
|
|
|
cs = c // ok
|
|
|
|
c = cr // ERROR "illegal types|incompatible|cannot"
|
|
|
|
c = cs // ERROR "illegal types|incompatible|cannot"
|
|
|
|
cr = cs // ERROR "illegal types|incompatible|cannot"
|
|
|
|
cs = cr // ERROR "illegal types|incompatible|cannot"
|
|
|
|
|
|
|
|
c <- 0 // ok
|
|
|
|
<-c // ok
|
2011-03-11 19:47:44 +00:00
|
|
|
x, ok := <-c // ok
|
|
|
|
_, _ = x, ok
|
2011-01-31 23:36:28 +00:00
|
|
|
|
|
|
|
cr <- 0 // ERROR "send"
|
|
|
|
<-cr // ok
|
2011-03-11 19:47:44 +00:00
|
|
|
x, ok = <-cr // ok
|
|
|
|
_, _ = x, ok
|
2011-01-31 23:36:28 +00:00
|
|
|
|
|
|
|
cs <- 0 // ok
|
|
|
|
<-cs // ERROR "receive"
|
2011-03-11 19:47:44 +00:00
|
|
|
x, ok = <-cs // ERROR "receive"
|
|
|
|
_, _ = x, ok
|
2009-05-22 16:53:25 +00:00
|
|
|
|
|
|
|
select {
|
2011-01-31 23:36:28 +00:00
|
|
|
case c <- 0: // ok
|
|
|
|
case x := <-c: // ok
|
2010-09-04 00:36:13 +00:00
|
|
|
_ = x
|
2009-05-22 16:53:25 +00:00
|
|
|
|
2011-01-31 23:36:28 +00:00
|
|
|
case cr <- 0: // ERROR "send"
|
|
|
|
case x := <-cr: // ok
|
2010-09-04 00:36:13 +00:00
|
|
|
_ = x
|
2009-05-22 16:53:25 +00:00
|
|
|
|
2011-01-31 23:36:28 +00:00
|
|
|
case cs <- 0: // ok
|
|
|
|
case x := <-cs: // ERROR "receive"
|
2010-09-04 00:36:13 +00:00
|
|
|
_ = x
|
2009-05-22 16:53:25 +00:00
|
|
|
}
|
2011-11-06 21:14:15 +00:00
|
|
|
|
|
|
|
for _ = range cs {// ERROR "receive"
|
|
|
|
}
|
|
|
|
|
2014-07-16 23:27:10 +00:00
|
|
|
for range cs {// ERROR "receive"
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:58:04 +00:00
|
|
|
close(c)
|
|
|
|
close(cs)
|
|
|
|
close(cr) // ERROR "receive"
|
2009-05-22 16:53:25 +00:00
|
|
|
}
|