{
  "id": "go/nil-map-write",
  "signature": "panic: assignment to entry in nil map",
  "signature_zh": "panic：向 nil map 赋值",
  "regex": "panic:\\ assignment\\ to\\ entry\\ in\\ nil\\ map",
  "domain": "go",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A write to a map that was declared but not initialized with make() or a literal.",
  "root_cause_type": "generic",
  "root_cause_zh": "向只声明未用 make() 或字面量初始化的 map 写入。",
  "versions": [
    {
      "version": "1.18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The map stays nil; subsequent writes panic again.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Does not address the nil map; sync.Map is a different type.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Silently drops data; the map still needs initialization.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "m := make(map[string]int)\nm[\"k\"] = 1",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.98,
      "how": "m := map[string]int{\"k\": 1}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "func set(m map[string]int, k string, v int) map[string]int {\n    if m == nil { m = make(map[string]int) }\n    m[k] = v\n    return m\n}",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-06",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}