{"record":{"id":"95d5c2ed44de9118","repo":"go-delve/delve","slug":"can-not-convert-value-of-type-s-to-int","errorCode":null,"errorMessage":"can not convert value of type %s to int","messagePattern":"can not convert value of type (.+?) to int","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2731,"sourceCode":"\t\tif !r && shortcircuit {\n\t\t\treturn false, nil\n\t\t}\n\t}\n\treturn r, nil\n}\n\nfunc (v *Variable) asInt() (int64, error) {\n\tif v.DwarfType == nil {\n\t\tif v.Value.Kind() != constant.Int {\n\t\t\treturn 0, fmt.Errorf(\"can not convert constant %s to int\", v.Value)\n\t\t}\n\t} else {\n\t\tv.loadValue(loadSingleValue)\n\t\tif v.Unreadable != nil {\n\t\t\treturn 0, v.Unreadable\n\t\t}\n\t\tif _, ok := v.DwarfType.(*godwarf.IntType); !ok {\n\t\t\treturn 0, fmt.Errorf(\"can not convert value of type %s to int\", v.DwarfType.String())\n\t\t}\n\t}\n\tn, _ := constant.Int64Val(v.Value)\n\treturn n, nil\n}\n\nfunc (v *Variable) asUint() (uint64, error) {\n\tif v.DwarfType == nil {\n\t\tif v.Value.Kind() != constant.Int {\n\t\t\treturn 0, fmt.Errorf(\"can not convert constant %s to uint\", v.Value)\n\t\t}\n\t} else {\n\t\tv.loadValue(loadSingleValue)\n\t\tif v.Unreadable != nil {\n\t\t\treturn 0, v.Unreadable\n\t\t}\n\t\tif _, ok := v.DwarfType.(*godwarf.UintType); !ok {\n\t\t\treturn 0, fmt.Errorf(\"can not convert value of type %s to uint\", v.DwarfType.String())","sourceCodeStart":2713,"sourceCodeEnd":2749,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2713-L2749","documentation":"This error comes from Variable.asInt() in Delve's expression evaluator. When a debugger expression is converted to an integer, the variable's DWARF type must be an *godwarf.IntType (a signed integer). If the value is any other DWARF type (unsigned int, float, string, pointer, struct, etc.), Delve refuses the conversion and returns this error instead of producing a wrong number.","triggerScenarios":"Calling APIs that coerce a Variable to an integer: Variable.asInt() invoked by evaluating expressions like int(x), or internal uses such as array index computation and constant conversion in eval.go, when v.DwarfType is non-nil but not *godwarf.IntType.","commonSituations":"Evaluating int(myUintVar) or int(myFloat) in the debugger console; casting a pointer or string to int in a breakpoint condition; scripts/plugins calling eval APIs expecting a numeric result from an unsigned-typed variable.","solutions":["Use the correct cast: convert to uint64(...) or float64(...) matching the variable's actual DWARF type, or cast the source variable to a signed integer type in your program first","Check the variable's type with the 'whatis' command before applying an int cast","If the value is constant (v.DwarfType == nil path is fine), ensure the constant literal itself is integral; rewrite the literal without a fractional or string form","If this happens on a variable you believe is signed int, verify DWARF debug info is complete (compile with the same Go version, no stripped symbols)"],"exampleFix":"// before (debugger expression)\nprint(int(uintVal))\n// after\nprint(int64(uintVal))   // or print(uintVal) directly","handlingStrategy":"validation","validationCode":"// Delve debugger expression pre-check\n// whatis myVar  -> confirm DwarfType is a signed int before casting\nprint(int64(myVar)) // use int64/float64 casts matching the actual type","typeGuard":"// conceptual: only cast when type is a signed integer\n// if strings.HasPrefix(whatisOutput, \"int\") { cast } else { use native type }","tryCatchPattern":null,"preventionTips":["Run 'whatis <expr>' before numeric casts in conditions","Prefer int64/uint64/float64 casts that mirror Go conversion rules","Rebuild with full DWARF info if variable types look wrong"],"tags":["go","debugger","type-conversion","eval"],"backgroundTag":"invalid-type-conversion","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}