{"record":{"id":"2eae6e6d316379d2","repo":"FuelLabs/sway","slug":"too-many-arguments-cannot-handle","errorCode":null,"errorMessage":"Too many arguments, cannot handle.","messagePattern":"Too many arguments, cannot handle\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sway-core/src/asm_generation/fuel/functions.rs","lineNumber":175,"sourceCode":"                    let stack_offset_bytes = self.locals_size_bytes() + (stack_offset * 8);\n                    assert!(\n                        stack_offset_bytes\n                            < self.locals_size_bytes() + (self.max_num_extra_args() * 8)\n                    );\n                    self.cur_bytecode.push(Op {\n                        opcode: Either::Left(VirtualOp::SW(\n                            VirtualRegister::Constant(\n                                ConstantRegister::ARG_REGS\n                                    [compiler_constants::NUM_ARG_REGISTERS as usize - 1],\n                            ),\n                            arg_reg,\n                            VirtualImmediate12::try_new(\n                                stack_offset,\n                                self.md_mgr\n                                    .val_to_span(self.context, *arg_val)\n                                    .unwrap_or(Span::dummy()),\n                            )\n                            .expect(\"Too many arguments, cannot handle.\"),\n                        )),\n                        comment: format!(\n                            \"[call: {fn_name}]: pass argument {idx} via its stack slot\"\n                        ),\n                        owning_span: self.md_mgr.val_to_span(self.context, *arg_val),\n                    });\n                }\n            }\n        }\n\n        // Jump to function and insert return label.\n        let (fn_label, _) = self.func_to_labels(function);\n        self.cur_bytecode.push(Op {\n            opcode: Either::Right(OrganizationalOp::Jump {\n                to: fn_label,\n                type_: JumpType::Call,\n            }),\n            comment: format!(\"[call: {fn_name}]: call function\"),","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/sway-core/src/asm_generation/fuel/functions.rs#L157-L193","documentation":"For call arguments beyond the argument registers, codegen writes each value to its stack slot with SW using a 12-bit immediate offset (byte offset from the saved stack-args base). When cumulative stack-argument bytes exceed 4095 (many and/or large by-value arguments), VirtualImmediate12::try_new fails and this expect panics — a compiler limitation reported with a misleading 'Too many arguments' message. It crashes on the caller side, at the call site.","triggerScenarios":"Calling a function whose stack-passed arguments total more than 4095 bytes: dozens of u64 arguments, several large structs passed by value, or wide generated/test signatures where args spill well past the argument registers.","commonSituations":"Generated bindings or tests calling contract-style entry points with wide signatures; refactoring an API to take 'one more' large struct by value; copying a Solidity-style wide function signature into Sway.","solutions":["Bundle arguments into one struct passed by reference: `fn transfer(&transfer_args: TransferArgs)` instead of many by-value params.","Reduce argument count/size (split the call, pass hashes/ids instead of full structs).","Re-check the call after changes with `forc build`; if a modest signature still panics, report upstream with a reproducer."],"exampleFix":"// before\nfn configure(a: Config, b: Config, c: Config, ... /* many by-value structs */)\n// after\nstruct Configs { a: Config, b: Config, c: Config }\nfn configure(configs: &Configs)","handlingStrategy":"fallback","validationCode":"# crude guard for wide signatures before compiling\n# (stack bytes ~= 8 per word beyond register args; flag calls with very many/large args)\ngrep -RnoE 'fn [a-z_]+\\([^)]{300,}\\)' --include='*.sw' . && echo 'suspiciously wide signature — pass a struct by reference'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to one input struct by reference instead of many by-value parameters.","Enable a local lint/code-review rule against functions with dozens of parameters.","After any signature change, run `forc build` — the panic names the fn in the comment ([call: <fn_name>])."],"tags":["sway","sway-core","compiler","internal-compiler-error","arguments","stack","asm-generation"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}