{
  "id": "go/append-to-slice-without-assignment",
  "signature": "append(s, x) evaluated but not used",
  "signature_zh": "append(s, x) 已求值但未使用",
  "regex": "append\\(.*\\) evaluated but not used",
  "domain": "go",
  "category": "compile_error",
  "subcategory": null,
  "root_cause": "The append() function returns a new slice; ignoring the return value discards the result and the original slice remains unchanged, leading to a compile-time error.",
  "root_cause_type": "generic",
  "root_cause_zh": "append() 函数返回一个新切片；忽略返回值会丢弃结果，原始切片保持不变，导致编译时错误。",
  "versions": [
    {
      "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": "The error 'evaluated but not used' will still occur because s is not used after assignment.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The same compile-time error occurs regardless of goroutine; append still returns an unused value.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This compiles but discards the result, which is likely a logic bug; the original slice s remains unchanged.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Assign the result of append back to the slice: s = append(s, x). Ensure s is used later in the code.",
      "success_rate": 0.95,
      "how": "Assign the result of append back to the slice: s = append(s, x). Ensure s is used later in the code.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If you want to modify the slice in place, use copy or index assignment instead: s = append(s[:len(s):len(s)], x) to extend capacity.",
      "success_rate": 0.85,
      "how": "If you want to modify the slice in place, use copy or index assignment instead: s = append(s[:len(s):len(s)], x) to extend capacity.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a pointer to the slice if you need to modify it inside a function: func foo(s *[]int) { *s = append(*s, x) }",
      "success_rate": 0.9,
      "how": "Use a pointer to the slice if you need to modify it inside a function: func foo(s *[]int) { *s = append(*s, x) }",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Assign the result of append back to the slice: s = append(s, x). Ensure s is used later in the code.",
    "If you want to modify the slice in place, use copy or index assignment instead: s = append(s[:len(s):len(s)], x) to extend capacity.",
    "Use a pointer to the slice if you need to modify it inside a function: func foo(s *[]int) { *s = append(*s, x) }"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/ref/spec#Appending_and_copying_slices",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-02-28",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}