go-delve/delve · error

wrong number of arguments to complex: %d

Error message

wrong number of arguments to complex: %d

What it means

The `complex()` builtin in Delve's evaluator builds a complex constant from two numeric arguments and therefore requires exactly two. Any other argument count returns this arity error before evaluation.

Source

Thrown at pkg/proc/eval.go:1969

		}
		return newConstant(arg.Children[0].Value, arg.bi, arg.mem), nil
	case reflect.Map:
		it := arg.mapIterator(0)
		if arg.Unreadable != nil {
			return nil, arg.Unreadable
		}
		if it == nil {
			return newConstant(constant.MakeInt64(0), arg.bi, arg.mem), nil
		}
		return newConstant(constant.MakeInt64(arg.Len), arg.bi, arg.mem), nil
	default:
		return nil, invalidArgErr
	}
}

func complexBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {
	if len(args) != 2 {
		return nil, fmt.Errorf("wrong number of arguments to complex: %d", len(args))
	}

	realev := args[0]
	imagev := args[1]

	realev.loadValue(loadSingleValue)
	imagev.loadValue(loadSingleValue)

	if realev.Unreadable != nil {
		return nil, realev.Unreadable
	}

	if imagev.Unreadable != nil {
		return nil, imagev.Unreadable
	}

	if realev.Value == nil || ((realev.Value.Kind() != constant.Int) && (realev.Value.Kind() != constant.Float)) {
		return nil, fmt.Errorf("invalid argument 1 %s (type %s) to complex", astutil.ExprToString(nodeargs[0]), realev.TypeString())

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Supply both real and imaginary parts: `complex(re, im)`.
  2. If the imaginary part is zero, pass an explicit `complex(re, 0)`.
  3. Validate the args slice length before invoking the evaluator programmatically.

Example fix

// before
complex(f)
// after
complex(f, 0)
Defensive patterns

Strategy: validation

Validate before calling

args, err := parseCallArgs(expr)
if err != nil || len(args) != 2 {
    return fmt.Errorf("complex takes exactly 2 arguments, got %d", len(args))
}

Try / catch

val, err := eval(expr)
if err != nil && strings.Contains(err.Error(), "wrong number of arguments to complex") {
    // supply both real and imaginary parts and retry
}

Prevention

When it happens

Trigger: Evaluating `complex(x)` with one argument or `complex(re, im, extra)` with three or more in the debugger console or eval API (eval.go:1969, complexBuiltin).

Common situations: Missing the imaginary part (`complex(f)`), typos, or programmatic expression construction supplying a wrong-sized args slice.

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/7bcd1a5c0439c176. Report an issue: GitHub.