go-delve/delve · error
mismatched types %q and %q
Error message
mismatched types %q and %q
What it means
When both operands of a binary operation have DWARF types and those type strings differ, Delve cannot negotiate a common type and reports mismatched types. Delve evaluates expressions with the debugged program's types, so unlike the Go compiler it cannot infer conversions; the two operands must have identical declared types.
Source
Thrown at pkg/proc/eval.go:2461
// ok
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
if constant.Sign(yv.Value) < 0 {
return nil, errors.New("shift count must not be negative")
}
default:
return nil, fmt.Errorf("shift count type %s, must be unsigned integer", yv.Kind.String())
}
return xv.DwarfType, nil
}
if xv.DwarfType == nil && yv.DwarfType == nil {
return nil, nil
}
if xv.DwarfType != nil && yv.DwarfType != nil {
if xv.DwarfType.String() != yv.DwarfType.String() {
return nil, fmt.Errorf("mismatched types %q and %q", xv.DwarfType.String(), yv.DwarfType.String())
}
return xv.DwarfType, nil
} else if xv.DwarfType != nil && yv.DwarfType == nil {
if err := yv.isType(xv.DwarfType, xv.Kind); err != nil {
return nil, err
}
return xv.DwarfType, nil
} else if xv.DwarfType == nil && yv.DwarfType != nil {
if err := xv.isType(yv.DwarfType, yv.Kind); err != nil {
return nil, err
}
return yv.DwarfType, nil
}
panic("unreachable")
}
func negotiateTypeNil(op token.Token, v *Variable) error {View on GitHub (pinned to a23773e6c3)
Solutions
- Add explicit conversions in the expression: `MyInt(x) + y` or `int(x) == int(y)`.
- Use `locals` or `print x` / `print y` to confirm the exact DWARF type names.
- Compare fields rather than whole structs if two struct types differ.
Example fix
// before p x == y // x is pkg.A, y is otherpkg.A // after p x.ID == y.ID
Defensive patterns
Strategy: validation
Validate before calling
// verify operand types match before combining
if t1 != t2 {
// insert explicit conversion: MyInt(x) + y or int(x) == int(y)
} Type guard
func sameDwarfType(x, y *proc.Variable) bool {
return x != nil && y != nil && x.DwarfType != nil && y.DwarfType != nil &&
x.DwarfType.String() == y.DwarfType.String()
} Prevention
- Insert explicit conversions when mixing named types with the same underlying type.
- Use `locals`/`print` to confirm exact type names before binary ops.
- Prefer comparing primitive fields over whole named-type values.
When it happens
Trigger: Evaluating `x + y`, `x == y`, etc. where xv.DwarfType.String() != yv.DwarfType.String(), e.g. adding a variable of type MyInt to a variable of type int, or comparing two different named struct types.
Common situations: Comparing or combining values of two distinct named types with identical underlying representation (common after refactors or when types come from different packages with same name), or mixing typed and aliased integer types.
Related errors
- invalid argument 1 %s (type %s) to complex
- invalid argument 2 %s (type %s) to complex
- invalid argument %s (type %s) to imag
- invalid argument %s (type %s) to real
- can not slice %q (type %s)
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/6d3018b944fa13ab.
Report an issue: GitHub.