go-delve/delve · error
wrong number of arguments to imag: %d
Error message
wrong number of arguments to imag: %d
What it means
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.
Source
Thrown at pkg/proc/eval.go:2018
if isz > sz {
sz = isz
}
}
if sz == 0 {
sz = 128
}
typ := godwarf.FakeBasicType("complex", int(sz))
r := realev.newVariable("", 0, typ, nil)
r.Value = constant.BinaryOp(realev.Value, token.ADD, constant.MakeImag(imagev.Value))
return r, nil
}
func imagBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {
if len(args) != 1 {
return nil, fmt.Errorf("wrong number of arguments to imag: %d", len(args))
}
arg := args[0]
arg.loadValue(loadSingleValue)
if arg.Unreadable != nil {
return nil, arg.Unreadable
}
if arg.Kind != reflect.Complex64 && arg.Kind != reflect.Complex128 {
return nil, fmt.Errorf("invalid argument %s (type %s) to imag", astutil.ExprToString(nodeargs[0]), arg.TypeString())
}
return newConstant(constant.Imag(arg.Value), arg.bi, arg.mem), nil
}
func realBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {
if len(args) != 1 {View on GitHub (pinned to a23773e6c3)
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.
Example fix
// before imag(re, im) // after complex(re, im) imag(c)
Defensive patterns
Strategy: validation
Validate before calling
args, err := parseCallArgs(expr)
if err != nil || len(args) != 1 {
return fmt.Errorf("imag takes exactly 1 argument, got %d", len(args))
} Try / catch
val, err := eval(expr)
if err != nil && strings.Contains(err.Error(), "wrong number of arguments to imag") {
// fix the call arity and retry
} Prevention
- 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.
When it happens
Trigger: Evaluating `imag()` with zero arguments or `imag(c, extra)` with two or more in the debugger console or eval API (eval.go:2018, imagBuiltin).
Common situations: Typos like `imag(re, im)` (confusing imag with complex), or programmatic expression builders supplying the wrong number of args.
Related errors
- wrong number of arguments to complex: %d
- wrong number of arguments to len: %d
- invalid argument 1 %s (type %s) to complex
- invalid argument 2 %s (type %s) to complex
- invalid argument %s (type %s) to imag
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/c9b4814dc7c07b5b.
Report an issue: GitHub.