go-delve/delve · error
can not compare %s variables
Error message
can not compare %s variables
What it means
For equality comparisons of composite kinds — slice, map, func and chan — Delve refuses to compare variables since Go itself only allows comparing those to nil. Because == on these kinds cannot be evaluated structurally, compareOp returns this error instead of guessing.
Source
Thrown at pkg/proc/eval.go:2676
switch xv.Kind {
case reflect.Ptr:
eql = xv.Children[0].Addr == yv.Children[0].Addr
case reflect.Array:
if int64(len(xv.Children)) != xv.Len || int64(len(yv.Children)) != yv.Len {
return false, errors.New("array too long for comparison")
}
eql, err = equalChildren(xv, yv, true)
case reflect.Struct:
if len(xv.Children) != len(yv.Children) {
return false, nil
}
if int64(len(xv.Children)) != xv.Len || int64(len(yv.Children)) != yv.Len {
return false, errors.New("structure too deep for comparison")
}
eql, err = equalChildren(xv, yv, false)
case reflect.Slice, reflect.Map, reflect.Func, reflect.Chan:
return false, fmt.Errorf("can not compare %s variables", xv.Kind.String())
case reflect.Interface:
if xv.Children[0].RealType.String() != yv.Children[0].RealType.String() {
eql = false
} else {
eql, err = compareOp(token.EQL, &xv.Children[0], &yv.Children[0])
}
default:
return false, fmt.Errorf("unimplemented comparison of %s variables", xv.Kind.String())
}
if op == token.NEQ {
return !eql, err
}
return eql, err
}
func (v *Variable) isNil() bool {
switch v.Kind {View on GitHub (pinned to a23773e6c3)
Solutions
- Compare element-wise: `p s1[0] == s2[0] && s1[1] == s2[1]`.
- Compare lengths then elements: `p len(s1) == len(s2)` before element checks.
- Compare maps by iterating keys, or compare a hash/serialized form if available.
Example fix
// before p s1 == s2 // after p len(s1) == len(s2) && s1[0] == s2[0]
Defensive patterns
Strategy: validation
Validate before calling
// slices/maps/funcs/chans are only comparable to nil in Go
switch v.Kind {
case reflect.Slice, reflect.Map, reflect.Func, reflect.Chan:
// compare len and elements instead of v1 == v2
} Type guard
func nonComparableKind(k reflect.Kind) bool {
switch k {
case reflect.Slice, reflect.Map, reflect.Func, reflect.Chan:
return true
}
return false
} Prevention
- Never use == between two slices/maps/funcs; only against nil.
- Compare lengths first, then element-by-element.
- Use reflect.DeepEqual semantics manually via element comparisons in Delve.
When it happens
Trigger: Evaluating `p s1 == s2` where s1/s2 are slices, `p m1 == m2` for maps, `p f1 == f2` for funcs, or `p c1 == c2` for channels (all non-nil comparisons).
Common situations: Users expecting the debugger to deep-compare slices or maps the way a testing framework (reflect.DeepEqual) would; the debugger follows Go language rules instead.
Related errors
- shift count must not be negative
- invalid argument %s (type %s) for cap
- wrong number of arguments to len: %d
- invalid argument %s (type %s) for len
- wrong number of arguments to complex: %d
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/1a432f43cf236307.
Report an issue: GitHub.