# 无法对 func()（类型为 func() 的值）进行 range 迭代

- **ID:** `go/cannot-range-over-function`
- **领域:** go
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

尝试对函数类型使用 range 迭代，而不是对切片、映射、字符串、通道或数组使用。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Go 1.18 | active | — | — |
| Go 1.19 | active | — | — |
| Go 1.20 | active | — | — |
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |

## 解决方案

1. ```
   确保函数返回一个切片或其他可迭代类型，然后对返回值进行 range 迭代
   ```
2. ```
   如果想迭代函数产生的值，使用通道（goroutine + 通道模式）
   ```

## 无效尝试

- **** — If the function returns a single value that is not iterable, the same error occurs on the return type. (70% 失败率)
- **** — Go does not allow range on interface{} either; it must be a concrete iterable type. (95% 失败率)
