# cannot use x (variable of type []T) as type []U in append

- **ID:** `go/mismatched-types-in-append`
- **Domain:** go
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| go1.21 | active | — | — |
| go1.22 | active | — | — |
| go1.23 | active | — | — |

## Workarounds

1. **Convert each element individually in a loop: for _, v := range x { y = append(y, U(v)) }** (90% success)
   ```
   Convert each element individually in a loop: for _, v := range x { y = append(y, U(v)) }
   ```
2. **If T and U are identical underlying types, use a simple copy: y = append(y, x...) after converting via unsafe or generics** (85% success)
   ```
   If T and U are identical underlying types, use a simple copy: y = append(y, x...) after converting via unsafe or generics
   ```

## Dead Ends

- **Attempting to use a direct type assertion like x.([]U)** — Type assertion only works for interfaces, not for concrete slice types; it will cause a compile error. (95% fail)
- **Using reflect to convert slices at runtime** — Reflection is slow and error-prone for slice conversion; it doesn't solve the compile-time type mismatch. (85% fail)
- **Ignoring the error and forcing the append with unsafe.Pointer** — Using unsafe bypasses type safety, leading to potential memory corruption or undefined behavior. (99% fail)
