{"record":{"id":"2dc32d988cd40471","repo":"go-delve/delve","slug":"invalid-argument-1-s-type-s-to-complex","errorCode":null,"errorMessage":"invalid argument 1 %s (type %s) to complex","messagePattern":"invalid argument 1 (.+?) \\(type (.+?)\\) to complex","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":1987,"sourceCode":"\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())\n\t}\n\n\tif imagev.Value == nil || ((imagev.Value.Kind() != constant.Int) && (imagev.Value.Kind() != constant.Float)) {\n\t\treturn nil, fmt.Errorf(\"invalid argument 2 %s (type %s) to complex\", astutil.ExprToString(nodeargs[1]), imagev.TypeString())\n\t}\n\n\tsz := int64(0)\n\tif realev.RealType != nil {\n\t\tsz = realev.RealType.(*godwarf.FloatType).Size()\n\t}\n\tif imagev.RealType != nil {\n\t\tisz := imagev.RealType.(*godwarf.FloatType).Size()\n\t\tif isz > sz {\n\t\t\tsz = isz\n\t\t}\n\t}\n\n\tif sz == 0 {","sourceCodeStart":1969,"sourceCodeEnd":2005,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L1969-L2005","documentation":"Delve's `complex()` builtin requires its first argument (the real part) to evaluate to an integer or float constant. This error fires when the argument is unreadable, nil, or of another constant kind (bool, string, complex, etc.), naming the offending expression and its type.","triggerScenarios":"Evaluating `complex(s, i)` where the first argument is a string, bool, complex value, or a variable whose value could not be loaded (realev.Value == nil) (eval.go:1987, complexBuiltin).","commonSituations":"Passing a string where a float was intended, passing an already-complex value to complex(), or evaluating on a variable whose memory could not be read (Value nil).","solutions":["Ensure the real argument is an int or float typed expression: `complex(floatVar, imagVar)`.","Convert explicitly, e.g. wrap or use a numeric field: `complex(x.real, x.imag)`.","Check the variable is readable (not optimized out) — inspect it alone first.","If the value is already complex, use it directly instead of calling complex()."],"exampleFix":"// before\ncomplex(name, imagPart)   // name is a string\n// after\ncomplex(realPart, imagPart)","handlingStrategy":"type-guard","validationCode":"// before evaluating complex(re, im): real part must be int/float\nre, err := evalLoad(re)\nif err != nil || re.Value == nil ||\n    (re.Value.Kind() != constant.Int && re.Value.Kind() != constant.Float) {\n    return fmt.Errorf(\"real part must be numeric, got %s\", re.TypeString())\n}","typeGuard":"func isNumericConst(v *proc.Variable) bool {\n    return v.Unreadable == nil && v.Value != nil &&\n        (v.Value.Kind() == constant.Int || v.Value.Kind() == constant.Float)\n}","tryCatchPattern":"val, err := evalComplex(reExpr, imExpr)\nif err != nil && strings.Contains(err.Error(), \"invalid argument 1\") {\n    // inspect/fix the real-part expression before retrying\n}","preventionTips":["Print each operand alone first to confirm it is a readable int/float.","Do not pass strings or bools into complex().","Do not re-wrap complex values with complex().","Beware optimized-out variables: their Value can be nil."],"tags":["debugger","go","expression-evaluation","complex-numbers","type-mismatch"],"backgroundTag":"invalid-builtin-argument","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}