{
  "id": "go/mismatched-types-in-append",
  "signature": "cannot use x (variable of type []T) as type []U in append",
  "signature_zh": "无法将类型为 []T 的变量 x 用作类型 []U 进行追加",
  "regex": "cannot use .+ \\(variable of type \\[\\]\\w+\\) as type \\[\\]\\w+ in append",
  "domain": "go",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Go's type system enforces strict slice type compatibility; appending a slice of one concrete type to another requires explicit conversion or type assertion even if underlying types are similar.",
  "root_cause_type": "generic",
  "root_cause_zh": "Go 的类型系统强制执行严格的切片类型兼容性；即使底层类型相似，将一个具体类型的切片追加到另一个类型也需要显式转换或类型断言。",
  "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": "Attempting to use a direct type assertion like x.([]U)",
      "why_fails": "Type assertion only works for interfaces, not for concrete slice types; it will cause a compile error.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using reflect to convert slices at runtime",
      "why_fails": "Reflection is slow and error-prone for slice conversion; it doesn't solve the compile-time type mismatch.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignoring the error and forcing the append with unsafe.Pointer",
      "why_fails": "Using unsafe bypasses type safety, leading to potential memory corruption or undefined behavior.",
      "fail_rate": 0.99,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Convert each element individually in a loop: for _, v := range x { y = append(y, U(v)) }",
      "success_rate": 0.9,
      "how": "Convert each element individually in a loop: for _, v := range x { y = append(y, U(v)) }",
      "condition": "",
      "sources": []
    },
    {
      "action": "If T and U are identical underlying types, use a simple copy: y = append(y, x...) after converting via unsafe or generics",
      "success_rate": 0.85,
      "how": "If T and U are identical underlying types, use a simple copy: y = append(y, x...) after converting via unsafe or generics",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Convert each element individually in a loop: for _, v := range x { y = append(y, U(v)) }",
    "If T and U are identical underlying types, use a simple copy: y = append(y, x...) after converting via unsafe or generics"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/doc/faq#convert_slice_of_slice",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.82,
  "resolvable": "true",
  "first_seen": "2023-08-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}