{"record":{"id":"d2bd2416c61a70a2","repo":"go-delve/delve","slug":"can-not-convert-s-constant-to-s","errorCode":null,"errorMessage":"can not convert %s constant to %s","messagePattern":"can not convert (.+?) constant to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2785,"sourceCode":"\t\t\treturn &typeConvErr{v.DwarfType, typ}\n\t\t}\n\t\treturn nil\n\t}\n\n\tif typ == nil {\n\t\treturn nil\n\t}\n\n\tif v == nilVariable {\n\t\tswitch kind {\n\t\tcase reflect.Slice, reflect.Map, reflect.Func, reflect.Ptr, reflect.Chan, reflect.Interface:\n\t\t\treturn nil\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"mismatched types nil and %s\", typ.String())\n\t\t}\n\t}\n\n\tconverr := fmt.Errorf(\"can not convert %s constant to %s\", v.Value, typ.String())\n\n\tif v.Value == nil {\n\t\treturn converr\n\t}\n\n\tswitch typ.(type) {\n\tcase *godwarf.IntType:\n\t\tif v.Value.Kind() != constant.Int {\n\t\t\treturn converr\n\t\t}\n\tcase *godwarf.UintType:\n\t\tif v.Value.Kind() != constant.Int {\n\t\t\treturn converr\n\t\t}\n\tcase *godwarf.FloatType:\n\t\tif (v.Value.Kind() != constant.Int) && (v.Value.Kind() != constant.Float) {\n\t\t\treturn converr\n\t\t}","sourceCodeStart":2767,"sourceCodeEnd":2803,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2767-L2803","documentation":"converr is the fallback error in convertToType in eval.go. It is created up-front as 'can not convert <constant> to <type>' and returned whenever the constant value cannot be represented as / converted to the requested target type — including the immediate case where v.Value is nil (no constant available). It is the generic constant-conversion failure for this evaluator.","triggerScenarios":"convertToType with a constant v.Value that is nil, or whose constant kind does not match any branch the switch on typ handles (e.g. converting a float constant to a struct type, a complex constant to an int, a string to a float in an invalid way).","commonSituations":"Casting literals to incompatible types in debugger conditions (e.g. float64(\"abc\"), MyStruct(1.5)); typos in constant expressions; using complex literals where reals are expected.","solutions":["Use a literal/value convertible to the target type: int(3), float64(1.5), string-literal casts only where Go allows","Check Go's constant conversion rules — only numeric constants convert to numeric types, strings only from integer constants","Simplify the expression and evaluate the constant alone first to see its type","Rewrite the breakpoint condition to avoid the exotic cast"],"exampleFix":"// before\ncond: MyStruct(1.5) == x\n// after\ncond: x.field == 1.5   // compare fields instead of converting to struct","handlingStrategy":"validation","validationCode":"// test the constant alone first:\nprint(1.5)        // confirm its type\nprint(int(1.5))   // numeric->numeric is OK\n// avoid: MyStruct(1.5), float64(\"abc\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Follow Go constant conversion rules (numeric<->numeric only)","Don't cast constants to struct/array types","Evaluate subexpressions in the debugger to isolate failing casts"],"tags":["go","debugger","constant","type-conversion"],"backgroundTag":"invalid-type-conversion","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}