# append(s, x) 已求值但未使用

- **ID:** `go/append-to-slice-without-assignment`
- **领域:** go
- **类别:** compile_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

append() 函数返回一个新切片；忽略返回值会丢弃结果，原始切片保持不变，导致编译时错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Go 1.20 | active | — | — |
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |

## 解决方案

1. ```
   Assign the result of append back to the slice: s = append(s, x). Ensure s is used later in the code.
   ```
2. ```
   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.
   ```
3. ```
   Use a pointer to the slice if you need to modify it inside a function: func foo(s *[]int) { *s = append(*s, x) }
   ```

## 无效尝试

- **** — The error 'evaluated but not used' will still occur because s is not used after assignment. (70% 失败率)
- **** — The same compile-time error occurs regardless of goroutine; append still returns an unused value. (90% 失败率)
- **** — This compiles but discards the result, which is likely a logic bug; the original slice s remains unchanged. (50% 失败率)
