# 恐慌：向只接收通道发送数据

- **ID:** `go/channel-direction-mismatch`
- **领域:** go
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试向声明为只接收（<-chan）的通道发送数据，或在只发送（chan<-）通道上接收。这是编译时错误，但如果类型断言使用不当，可能在运行时发生。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.19 | active | — | — |

## 解决方案

1. **** (98% 成功率)
   ```
   func producer(ch chan<- int) {
    ch <- 1
}

func consumer(ch <-chan int) {
    v := <-ch
    fmt.Println(v)
}

ch := make(chan int)
go producer(ch)
consumer(ch)
   ```
2. **** (95% 成功率)
   ```
   ch := make(chan int)

go func(ch chan<- int) {
    ch <- 42
}(ch)

v := <-ch
fmt.Println(v)
   ```

## 无效尝试

- **** — Type assertions cannot change channel direction; it's a static property. (100% 失败率)
- **** — The program will panic or fail to compile. (100% 失败率)
