{"record":{"id":"6d3018b944fa13ab","repo":"go-delve/delve","slug":"mismatched-types-q-and-q","errorCode":null,"errorMessage":"mismatched types %q and %q","messagePattern":"mismatched types %q and %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2461,"sourceCode":"\t\t\t// ok\n\t\tcase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:\n\t\t\tif constant.Sign(yv.Value) < 0 {\n\t\t\t\treturn nil, errors.New(\"shift count must not be negative\")\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"shift count type %s, must be unsigned integer\", yv.Kind.String())\n\t\t}\n\n\t\treturn xv.DwarfType, nil\n\t}\n\n\tif xv.DwarfType == nil && yv.DwarfType == nil {\n\t\treturn nil, nil\n\t}\n\n\tif xv.DwarfType != nil && yv.DwarfType != nil {\n\t\tif xv.DwarfType.String() != yv.DwarfType.String() {\n\t\t\treturn nil, fmt.Errorf(\"mismatched types %q and %q\", xv.DwarfType.String(), yv.DwarfType.String())\n\t\t}\n\t\treturn xv.DwarfType, nil\n\t} else if xv.DwarfType != nil && yv.DwarfType == nil {\n\t\tif err := yv.isType(xv.DwarfType, xv.Kind); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn xv.DwarfType, nil\n\t} else if xv.DwarfType == nil && yv.DwarfType != nil {\n\t\tif err := xv.isType(yv.DwarfType, yv.Kind); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn yv.DwarfType, nil\n\t}\n\n\tpanic(\"unreachable\")\n}\n\nfunc negotiateTypeNil(op token.Token, v *Variable) error {","sourceCodeStart":2443,"sourceCodeEnd":2479,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2443-L2479","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\np x == y   // x is pkg.A, y is otherpkg.A\n// after\np x.ID == y.ID","handlingStrategy":"validation","validationCode":"// verify operand types match before combining\nif t1 != t2 {\n    // insert explicit conversion: MyInt(x) + y or int(x) == int(y)\n}","typeGuard":"func sameDwarfType(x, y *proc.Variable) bool {\n    return x != nil && y != nil && x.DwarfType != nil && y.DwarfType != nil &&\n        x.DwarfType.String() == y.DwarfType.String()\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["debugger","expression-evaluation","type-mismatch"],"backgroundTag":"mismatched-types","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}