{
  "id": "go/panic-runtime-error-slice-bounds-out-of-range-with-capacity",
  "signature": "panic: runtime error: slice bounds out of range [:6] with capacity 4",
  "signature_zh": "恐慌：运行时错误：切片边界超出范围 [:6]，容量为4",
  "regex": "panic: runtime error: slice bounds out of range \\[:\\d+\\] with capacity \\d+",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Attempting to reslice a slice beyond its capacity, which is a compile-time check bypassed by dynamic index.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试对切片进行超出其容量的重新切片，动态索引绕过了编译时检查。",
  "versions": [
    {
      "version": "go1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding bounds check with if condition but using wrong variable",
      "why_fails": "Often developers check len(s) but then use cap(s) for slicing, missing the capacity limit.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using append to extend slice without understanding capacity growth",
      "why_fails": "append may reallocate, but the original slice's capacity remains; slicing after append on old reference still fails.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use make to pre-allocate slice with sufficient capacity: s := make([]int, 0, 10); then append or reslice within cap.",
      "success_rate": 0.9,
      "how": "Use make to pre-allocate slice with sufficient capacity: s := make([]int, 0, 10); then append or reslice within cap.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check capacity before slicing: if cap(s) >= 6 { s = s[:6] } else { /* handle error */ }",
      "success_rate": 0.85,
      "how": "Check capacity before slicing: if cap(s) >= 6 { s = s[:6] } else { /* handle error */ }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用 make 预分配足够的容量：s := make([]int, 0, 10)；然后追加或重新切片在容量范围内。",
    "在切片前检查容量：if cap(s) >= 6 { s = s[:6] } else { /* 处理错误 */ }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/ref/spec#Slice_expressions",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}