{"record":{"id":"01f1be8f17844b67","repo":"go-delve/delve","slug":"can-not-convert-constant-s-to-uint","errorCode":null,"errorMessage":"can not convert constant %s to uint","messagePattern":"can not convert constant (.+?) to uint","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2741,"sourceCode":"\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())\n\t\t}\n\t}\n\tn, _ := constant.Uint64Val(v.Value)\n\treturn n, nil\n}\n\ntype typeConvErr struct {\n\tsrcType, dstType godwarf.Type\n}\n","sourceCodeStart":2723,"sourceCodeEnd":2759,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2723-L2759","documentation":"This error comes from Variable.asUint() in eval.go. When the variable has no DWARF type (it is a constant), the constant's exact value must be of kind constant.Int (an integer literal) to be converted to uint. If the constant is a float, string, bool, or complex literal, Delve returns this error naming the constant text.","triggerScenarios":"Variable.asUint() is called when v.DwarfType == nil and v.Value.Kind() != constant.Int — i.e., evaluating expressions like uint(3.14), uint(\"abc\"), or uint(true) on untyped constants in breakpoint conditions or the debugger console.","commonSituations":"Typing uint(1.5) or uint(-0.5) in an expression; using a string constant where an unsigned value is expected in a watch expression or condition; macros/scripts generating casts from literals.","solutions":["Use an integer literal in the cast: uint(42) instead of uint(1.5)","Truncate explicitly: uint(int64(1.5)) if lossy truncation is intended","Verify the constant is non-negative if it should fit in an unsigned type","If a variable was expected (not a constant), ensure the expression resolves to a real variable with DWARF type info"],"exampleFix":"// before\ncond: x == uint(3.14)\n// after\ncond: x == uint(3)  // or uint(int64(3.14))","handlingStrategy":"validation","validationCode":"// constants must be integer literals for uint conversion\n// OK: uint(42)   BAD: uint(3.14), uint(\"7\"), uint(true)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass integer literals into uint(...) casts","Use uint(int64(x)) for explicit truncation","Avoid string/bool constants in numeric casts"],"tags":["go","debugger","type-conversion","constant"],"backgroundTag":"invalid-type-conversion","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}