# cannot compare x (variable of type struct { ... }) with y (variable of type struct { ... })

- **ID:** `go/struct-comparison-not-allowed`
- **Domain:** go
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

Structs containing fields that are not comparable (e.g., slices, maps, functions) cannot be directly compared with == or !=.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Go 1.20 | active | — | — |
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |

## Workarounds

1. **Use reflect.DeepEqual() for deep comparison: if reflect.DeepEqual(a, b) { ... }** (85% success)
   ```
   Use reflect.DeepEqual() for deep comparison: if reflect.DeepEqual(a, b) { ... }
   ```
2. **Implement a custom comparison function that manually compares each comparable field and uses reflect.DeepEqual for incomparable ones.** (80% success)
   ```
   Implement a custom comparison function that manually compares each comparable field and uses reflect.DeepEqual for incomparable ones.
   ```
3. **Redesign the struct to avoid incomparable fields (e.g., replace slices with arrays of fixed size).** (75% success)
   ```
   Redesign the struct to avoid incomparable fields (e.g., replace slices with arrays of fixed size).
   ```

## Dead Ends

- **** — Go does not support operator overloading; you cannot define a custom == method. (90% fail)
- **** — reflect.DeepEqual works but may have performance overhead and does not handle unexported fields in some cases. (40% fail)
- **** — Interface comparison still requires underlying values to be comparable; same error will occur. (70% fail)
