{
  "id": "go/cannot-range-over-function",
  "signature": "cannot range over func() (value of type func())",
  "signature_zh": "无法对 func()（类型为 func() 的值）进行 range 迭代",
  "regex": "cannot range over func\\(\\) \\(value of type func\\(\\)\\)",
  "domain": "go",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Trying to use range on a function type instead of a slice, map, string, channel, or array.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试对函数类型使用 range 迭代，而不是对切片、映射、字符串、通道或数组使用。",
  "versions": [
    {
      "version": "Go 1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Go 1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "If the function returns a single value that is not iterable, the same error occurs on the return type.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Go does not allow range on interface{} either; it must be a concrete iterable type.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the function returns a slice or another iterable type, then range over the return value",
      "success_rate": 0.95,
      "how": "Ensure the function returns a slice or another iterable type, then range over the return value",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a channel if you want to iterate over values produced by a function (goroutine + channel pattern)",
      "success_rate": 0.85,
      "how": "Use a channel if you want to iterate over values produced by a function (goroutine + channel pattern)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "确保函数返回一个切片或其他可迭代类型，然后对返回值进行 range 迭代",
    "如果想迭代函数产生的值，使用通道（goroutine + 通道模式）"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/ref/spec#For_range",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-06-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}