2012-02-16 21:48:57 -07:00
|
|
|
// errorcheck
|
2009-05-22 10:53:25 -06: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-18 23:44:02 -07:00
|
|
|
// Test various correct and incorrect permutations of send-only,
|
|
|
|
// receive-only, and bidirectional channels.
|
|
|
|
// Does not compile.
|
|
|
|
|
2009-05-22 10:53:25 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
var (
|
2010-09-03 18:36:13 -06:00
|
|
|
cr <-chan int
|
|
|
|
cs chan<- int
|
2011-01-31 16:36:28 -07:00
|
|
|
c chan int
|
2009-05-22 10:53:25 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2011-01-31 16:36:28 -07: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 12:47:44 -07:00
|
|
|
x, ok := <-c // ok
|
|
|
|
_, _ = x, ok
|
2011-01-31 16:36:28 -07:00
|
|
|
|
|
|
|
cr <- 0 // ERROR "send"
|
|
|
|
<-cr // ok
|
2011-03-11 12:47:44 -07:00
|
|
|
x, ok = <-cr // ok
|
|
|
|
_, _ = x, ok
|
2011-01-31 16:36:28 -07:00
|
|
|
|
|
|
|
cs <- 0 // ok
|
|
|
|
<-cs // ERROR "receive"
|
2011-03-11 12:47:44 -07:00
|
|
|
x, ok = <-cs // ERROR "receive"
|
|
|
|
_, _ = x, ok
|
2009-05-22 10:53:25 -06:00
|
|
|
|
|
|
|
select {
|
2011-01-31 16:36:28 -07:00
|
|
|
case c <- 0: // ok
|
|
|
|
case x := <-c: // ok
|
2010-09-03 18:36:13 -06:00
|
|
|
_ = x
|
2009-05-22 10:53:25 -06:00
|
|
|
|
2011-01-31 16:36:28 -07:00
|
|
|
case cr <- 0: // ERROR "send"
|
|
|
|
case x := <-cr: // ok
|
2010-09-03 18:36:13 -06:00
|
|
|
_ = x
|
2009-05-22 10:53:25 -06:00
|
|
|
|
2011-01-31 16:36:28 -07:00
|
|
|
case cs <- 0: // ok
|
|
|
|
case x := <-cs: // ERROR "receive"
|
2010-09-03 18:36:13 -06:00
|
|
|
_ = x
|
2009-05-22 10:53:25 -06:00
|
|
|
}
|
2011-11-06 14:14:15 -07:00
|
|
|
|
|
|
|
for _ = range cs {// ERROR "receive"
|
|
|
|
}
|
|
|
|
|
2011-10-13 14:58:04 -06:00
|
|
|
close(c)
|
|
|
|
close(cs)
|
|
|
|
close(cr) // ERROR "receive"
|
2009-05-22 10:53:25 -06:00
|
|
|
}
|