# error：无法关闭只接收 channel ch（类型为 <-chan int 的变量）

- **ID:** `go/close-of-receive-only-channel`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

编译器拒绝对只接收 channel 类型调用 close()。常见于函数返回 <-chan T，但实现内部试图关闭该 channel。

## 版本兼容性

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

## 解决方案

1. **** (97% 成功率)
   ```
   func producer() <-chan int {
    ch := make(chan int)
    go func() {
        defer close(ch)
        // send...
    }()
    return ch
}
   ```
2. **** (93% 成功率)
   ```
   func producer(done <-chan struct{}) <-chan int {
    ch := make(chan int)
    go func() {
        defer close(ch)
        select { case <-done: return; default: }
    }()
    return ch
}
   ```

## 无效尝试

- **** — Type conversion doesn't change directionality for close; the compiler still rejects it because the static type is receive-only. (90% 失败率)
- **** — Receivers ranging over the channel will block forever waiting for a close that never comes. (70% 失败率)
