{"record":{"id":"c9b4814dc7c07b5b","repo":"go-delve/delve","slug":"wrong-number-of-arguments-to-imag-d","errorCode":null,"errorMessage":"wrong number of arguments to imag: %d","messagePattern":"wrong number of arguments to imag: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2018,"sourceCode":"\t\tif isz > sz {\n\t\t\tsz = isz\n\t\t}\n\t}\n\n\tif sz == 0 {\n\t\tsz = 128\n\t}\n\n\ttyp := godwarf.FakeBasicType(\"complex\", int(sz))\n\n\tr := realev.newVariable(\"\", 0, typ, nil)\n\tr.Value = constant.BinaryOp(realev.Value, token.ADD, constant.MakeImag(imagev.Value))\n\treturn r, nil\n}\n\nfunc imagBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {\n\tif len(args) != 1 {\n\t\treturn nil, fmt.Errorf(\"wrong number of arguments to imag: %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.Kind != reflect.Complex64 && arg.Kind != reflect.Complex128 {\n\t\treturn nil, fmt.Errorf(\"invalid argument %s (type %s) to imag\", astutil.ExprToString(nodeargs[0]), arg.TypeString())\n\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 {","sourceCodeStart":2000,"sourceCodeEnd":2036,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2000-L2036","documentation":"The `imag()` builtin in Delve's evaluator extracts the imaginary part of a complex value and requires exactly one argument. Any other count returns this arity error before type checking.","triggerScenarios":"Evaluating `imag()` with zero arguments or `imag(c, extra)` with two or more in the debugger console or eval API (eval.go:2018, imagBuiltin).","commonSituations":"Typos like `imag(re, im)` (confusing imag with complex), or programmatic expression builders supplying the wrong number of args.","solutions":["Pass exactly one complex-typed argument: `imag(c)`.","To build a complex value use `complex(re, im)` instead.","Validate argument count programmatically before calling the evaluator."],"exampleFix":"// before\nimag(re, im)\n// after\ncomplex(re, im)\nimag(c)","handlingStrategy":"validation","validationCode":"args, err := parseCallArgs(expr)\nif err != nil || len(args) != 1 {\n    return fmt.Errorf(\"imag takes exactly 1 argument, got %d\", len(args))\n}","typeGuard":null,"tryCatchPattern":"val, err := eval(expr)\nif err != nil && strings.Contains(err.Error(), \"wrong number of arguments to imag\") {\n    // fix the call arity and retry\n}","preventionTips":["imag(c) takes one complex argument; use complex(re, im) to build values.","Watch for stray commas adding phantom arguments.","Validate argument count in generated expressions."],"tags":["debugger","go","expression-evaluation","arity","complex-numbers"],"backgroundTag":"wrong-builtin-arg-count","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}