{"record":{"id":"f518914be8d7ccf6","repo":"go-delve/delve","slug":"invalid-argument-s-type-s-to-real","errorCode":null,"errorMessage":"invalid argument %s (type %s) to real","messagePattern":"invalid argument (.+?) \\(type (.+?)\\) to real","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2048,"sourceCode":"\t}\n\n\treturn newConstant(constant.Imag(arg.Value), arg.bi, arg.mem), nil\n}\n\nfunc realBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {\n\tif len(args) != 1 {\n\t\treturn nil, fmt.Errorf(\"wrong number of arguments to real: %d\", len(args))\n\t}\n\n\targ := args[0]\n\targ.loadValue(loadSingleValue)\n\n\tif arg.Unreadable != nil {\n\t\treturn nil, arg.Unreadable\n\t}\n\n\tif arg.Value == nil || ((arg.Value.Kind() != constant.Int) && (arg.Value.Kind() != constant.Float) && (arg.Value.Kind() != constant.Complex)) {\n\t\treturn nil, fmt.Errorf(\"invalid argument %s (type %s) to real\", astutil.ExprToString(nodeargs[0]), arg.TypeString())\n\t}\n\n\treturn newConstant(constant.Real(arg.Value), arg.bi, arg.mem), nil\n}\n\nfunc minBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {\n\treturn minmaxBuiltin(\"min\", token.LSS, args, nodeargs)\n}\n\nfunc maxBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {\n\treturn minmaxBuiltin(\"max\", token.GTR, args, nodeargs)\n}\n\nfunc minmaxBuiltin(name string, op token.Token, args []*Variable, nodeargs []ast.Expr) (*Variable, error) {\n\tvar best *Variable\n\n\tfor i := range args {\n\t\tif args[i].Kind == reflect.String {","sourceCodeStart":2030,"sourceCodeEnd":2066,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2030-L2066","documentation":"Delve's `real()` builtin accepts only values that evaluate to integer, float or complex constants. This error fires when the argument's loaded value is nil (unreadable) or of another constant kind (string, bool), including the argument's source text and type in the message.","triggerScenarios":"Evaluating `real(x)` where x's constant value is a string or bool, or where arg.Value == nil because the memory read / value load failed (eval.go:2048, realBuiltin).","commonSituations":"Calling real on a string or boolean variable, on a variable that was optimized out and could not be loaded, or on an interface value that resolved to a non-numeric concrete type.","solutions":["Pass a numeric (int/float/complex) typed expression; check with `ptype <expr>`.","Print the variable by itself first to confirm its value is readable, not optimized out.","For strings/bools, real() is meaningless — drop the call or fix the variable.","If the value is an interface, evaluate the concrete numeric field or assert its type first."],"exampleFix":"// before\nreal(flag)       // flag is bool\n// after\nreal(c)          // c is complex128/float/int","handlingStrategy":"type-guard","validationCode":"// before evaluating real(x)\nv, err := evalLoad(x)\nif err != nil || v.Value == nil ||\n    (v.Value.Kind() != constant.Int && v.Value.Kind() != constant.Float && v.Value.Kind() != constant.Complex) {\n    return fmt.Errorf(\"real requires int/float/complex, got %s\", v.TypeString())\n}","typeGuard":"func isRealable(v *proc.Variable) bool {\n    if v.Unreadable != nil || v.Value == nil {\n        return false\n    }\n    k := v.Value.Kind()\n    return k == constant.Int || k == constant.Float || k == constant.Complex\n}","tryCatchPattern":"val, err := evalReal(expr)\nif err != nil && strings.Contains(err.Error(), \"invalid argument\") {\n    // print the variable directly and check its type/value before retrying\n}","preventionTips":["Print the variable alone first to catch optimized-out (unreadable) values.","Only apply real() to int, float or complex typed expressions.","Use ptype to confirm the expression's type.","Resolve interface values to concrete numeric types before calling real()."],"tags":["debugger","go","expression-evaluation","type-mismatch"],"backgroundTag":"invalid-builtin-argument","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}