{"record":{"id":"52b469b974e30c33","repo":"go-delve/delve","slug":"invalid-argument-2-s-type-s-to-complex","errorCode":null,"errorMessage":"invalid argument 2 %s (type %s) to complex","messagePattern":"invalid argument 2 (.+?) \\(type (.+?)\\) to complex","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":1991,"sourceCode":"\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 {\n\t\tsz = 128\n\t}\n\n\ttyp := godwarf.FakeBasicType(\"complex\", int(sz))","sourceCodeStart":1973,"sourceCodeEnd":2009,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L1973-L2009","documentation":"Delve's `complex()` builtin requires its second argument (the imaginary part) to evaluate to an integer or float constant. This error fires when the imaginary argument is unreadable, nil, or of another constant kind, naming the expression and its type.","triggerScenarios":"Evaluating `complex(re, bad)` where the second argument is a string, bool, struct, or whose value failed to load (imagev.Value == nil) (eval.go:1991, complexBuiltin).","commonSituations":"Swapping arguments so a complex value lands in the imaginary slot, passing a string literal as the imaginary part, or evaluating a variable whose memory read failed.","solutions":["Ensure the imaginary argument is an int or float typed expression.","If the value is already complex, extract its part or use it directly rather than wrapping.","Verify the second variable is readable (print it by itself first).","Check argument order: complex(real, imag)."],"exampleFix":"// before\ncomplex(re, \"0.5\")\n// after\ncomplex(re, 0.5)","handlingStrategy":"type-guard","validationCode":"// before evaluating complex(re, im): imaginary part must be int/float\nim, err := evalLoad(im)\nif err != nil || im.Value == nil ||\n    (im.Value.Kind() != constant.Int && im.Value.Kind() != constant.Float) {\n    return fmt.Errorf(\"imaginary part must be numeric, got %s\", im.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 2\") {\n    // inspect/fix the imaginary-part expression before retrying\n}","preventionTips":["Keep argument order (real, imag) — swapped args can put a complex value in slot 2.","Quote-free numeric literals only: complex(re, 0.5), not complex(re, \"0.5\").","Confirm the imaginary operand is readable before combining."],"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"}