// len()/cap() on a channel must report the ring, not zero. // // stage4's len/cap lowering had no *TCChan arm, so it fell through to the // "return zero" default while legacy called runtime.chanLen/chanCap. Every // len(chan)/cap(chan) therefore read 0 under stage4 and disagreed with // legacy. The channel needs both a sender and a listener or the compiler // rejects it, so the body sends and receives. package main func main() { ch := chan int32{4} if cap(ch) != 4 { panic("cap(chan) is not the ring capacity") } if len(ch) != 0 { panic("len(chan) of a new channel is not 0") } ch <- 7 if len(ch) != 1 { panic("len(chan) after one send is not 1") } if <-ch != 7 { panic("receive returned the wrong value") } if len(ch) != 0 { panic("len(chan) after receive is not 0") } println("ok") }