{"record":{"id":"7bcd1a5c0439c176","repo":"go-delve/delve","slug":"wrong-number-of-arguments-to-complex-d","errorCode":null,"errorMessage":"wrong number of arguments to complex: %d","messagePattern":"wrong number of arguments to complex: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":1969,"sourceCode":"\t\t}\n\t\treturn newConstant(arg.Children[0].Value, arg.bi, arg.mem), nil\n\tcase reflect.Map:\n\t\tit := arg.mapIterator(0)\n\t\tif arg.Unreadable != nil {\n\t\t\treturn nil, arg.Unreadable\n\t\t}\n\t\tif it == nil {\n\t\t\treturn newConstant(constant.MakeInt64(0), arg.bi, arg.mem), nil\n\t\t}\n\t\treturn newConstant(constant.MakeInt64(arg.Len), arg.bi, arg.mem), nil\n\tdefault:\n\t\treturn nil, invalidArgErr\n\t}\n}\n\nfunc complexBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {\n\tif len(args) != 2 {\n\t\treturn nil, fmt.Errorf(\"wrong number of arguments to complex: %d\", len(args))\n\t}\n\n\trealev := args[0]\n\timagev := args[1]\n\n\trealev.loadValue(loadSingleValue)\n\timagev.loadValue(loadSingleValue)\n\n\tif realev.Unreadable != nil {\n\t\treturn nil, realev.Unreadable\n\t}\n\n\tif imagev.Unreadable != nil {\n\t\treturn nil, imagev.Unreadable\n\t}\n\n\tif realev.Value == nil || ((realev.Value.Kind() != constant.Int) && (realev.Value.Kind() != constant.Float)) {\n\t\treturn nil, fmt.Errorf(\"invalid argument 1 %s (type %s) to complex\", astutil.ExprToString(nodeargs[0]), realev.TypeString())","sourceCodeStart":1951,"sourceCodeEnd":1987,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L1951-L1987","documentation":"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.","triggerScenarios":"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).","commonSituations":"Missing the imaginary part (`complex(f)`), typos, or programmatic expression construction supplying a wrong-sized args slice.","solutions":["Supply both real and imaginary parts: `complex(re, im)`.","If the imaginary part is zero, pass an explicit `complex(re, 0)`.","Validate the args slice length before invoking the evaluator programmatically."],"exampleFix":"// before\ncomplex(f)\n// after\ncomplex(f, 0)","handlingStrategy":"validation","validationCode":"args, err := parseCallArgs(expr)\nif err != nil || len(args) != 2 {\n    return fmt.Errorf(\"complex takes exactly 2 arguments, got %d\", len(args))\n}","typeGuard":null,"tryCatchPattern":"val, err := eval(expr)\nif err != nil && strings.Contains(err.Error(), \"wrong number of arguments to complex\") {\n    // supply both real and imaginary parts and retry\n}","preventionTips":["Always pass both parts: complex(re, im).","Use complex(x, 0) when the imaginary part is zero.","Assert argument count when constructing calls programmatically."],"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"}