# cannot compare struct containing a slice

- **ID:** `go/struct-comparing-with-unsupported-field`
- **Domain:** go
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 84%

## Root Cause

Go does not support direct equality comparison (==) for structs that contain slice, map, or function fields because these types are not comparable.

## Version Compatibility

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

## Workarounds

1. **Implement a custom Equal method that compares each field, including slices using reflect.DeepEqual or a loop** (92% success)
   ```
   Implement a custom Equal method that compares each field, including slices using reflect.DeepEqual or a loop
   ```
2. **Use a pointer to the struct and compare pointers, or use a map key that doesn't include the slice** (80% success)
   ```
   Use a pointer to the struct and compare pointers, or use a map key that doesn't include the slice
   ```

## Dead Ends

- **Using reflect.DeepEqual for the comparison but ignoring performance** — DeepEqual works but is slow and may panic on unexported fields; it also doesn't solve the compile-time error. (70% fail)
- **Converting the slice to a string and comparing strings** — Workable for simple cases but brittle; slice order and content must match exactly, and it's not idiomatic. (60% fail)
- **Removing the slice field from the struct temporarily** — Changes the data model and may break other logic that depends on the slice. (90% fail)
