go-delve/delve · error
wrong number of arguments to real: %d
Error message
wrong number of arguments to real: %d
What it means
The `real()` builtin in Delve's evaluator extracts the real part of a numeric value and requires exactly one argument. Any other argument count returns this arity error immediately.
Source
Thrown at pkg/proc/eval.go:2037
}
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 {
return nil, fmt.Errorf("wrong number of arguments to real: %d", len(args))
}
arg := args[0]
arg.loadValue(loadSingleValue)
if arg.Unreadable != nil {
return nil, arg.Unreadable
}
if arg.Value == nil || ((arg.Value.Kind() != constant.Int) && (arg.Value.Kind() != constant.Float) && (arg.Value.Kind() != constant.Complex)) {
return nil, fmt.Errorf("invalid argument %s (type %s) to real", astutil.ExprToString(nodeargs[0]), arg.TypeString())
}
return newConstant(constant.Real(arg.Value), arg.bi, arg.mem), nil
}
func minBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {
return minmaxBuiltin("min", token.LSS, args, nodeargs)View on GitHub (pinned to a23773e6c3)
Solutions
- Pass exactly one argument: `real(<expr>)`.
- To combine values use `complex(re, im)` instead.
- Validate the args slice length before invoking the evaluator programmatically.
Example fix
// before real(re, im) // after complex(re, im) real(c)
Defensive patterns
Strategy: validation
Validate before calling
args, err := parseCallArgs(expr)
if err != nil || len(args) != 1 {
return fmt.Errorf("real 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 real") {
// fix the call arity and retry
} Prevention
- real(x) takes one argument; use complex(re, im) to build values.
- Double-check parentheses when nesting calls like real(complex(a, b)).
- Validate argument count in generated expressions.
When it happens
Trigger: Evaluating `real()` with zero arguments or `real(a, b)` with two or more (eval.go:2037, realBuiltin).
Common situations: Typos like `real(re, im)` (confusing real with complex), or programmatic expression construction with miscounted args.
Related errors
- wrong number of arguments to len: %d
- wrong number of arguments to complex: %d
- wrong number of arguments to imag: %d
- shift count must not be negative
- invalid argument %s (type %s) for cap
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/dd7bbc5026697e1f.
Report an issue: GitHub.