{"record":{"id":"ff41f06fd6459015","repo":"neon-bindings/neon","slug":"unexpected-second-receiver-argument","errorCode":null,"errorMessage":"Unexpected second receiver argument.","messagePattern":"Unexpected second receiver argument\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/neon-macros/src/class/mod.rs","lineNumber":493,"sourceCode":"    // Extract the second argument (skip &self)\n    let arg = match sig.inputs.iter().nth(1) {\n        Some(arg) => arg,\n\n        // If context was forced, error to let the user know the mistake\n        None if opts.context => {\n            return Err(syn::Error::new(\n                sig.inputs.span(),\n                \"Expected a context argument after `&self` when using `#[neon(context)]`. Add a parameter like `cx: &mut FunctionContext` or remove the `context` attribute.\",\n            ))\n        }\n\n        None => return Ok(None),\n    };\n\n    // Expect a typed pattern; self receivers are not supported (but shouldn't appear here)\n    match arg {\n        syn::FnArg::Typed(ty) => Ok(Some(ty)),\n        syn::FnArg::Receiver(arg) => Err(syn::Error::new(\n            arg.span(),\n            \"Unexpected second receiver argument.\",\n        )),\n    }\n}\n\nfn is_context_type(ty: &syn::Type) -> bool {\n    let ident = match type_path_ident(ty) {\n        Some(ident) => ident,\n        None => return false,\n    };\n\n    ident == \"FunctionContext\" || ident == \"Cx\"\n}\n\nfn is_channel_type(ty: &syn::Type) -> bool {\n    let ident = match type_path_ident(ty) {\n        Some(ident) => ident,","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/neon-bindings/neon/blob/38960e4381d9ad13b551cdf2d261f609167c9bc2/crates/neon-macros/src/class/mod.rs#L475-L511","documentation":"Compile-time error from Neon's `#[neon]` class macro, raised by `first_arg` when the second entry in a method's inputs (after `&self`) is another receiver (`self`-style argument, `syn::FnArg::Receiver`) rather than a normally typed parameter. Rust does not normally allow two receivers, so the macro treats this as an unexpected signature shape and fails with \"Unexpected second receiver argument.\"","triggerScenarios":"Declaring an exported class method with two self-like receivers, e.g. `fn foo(&self, &mut self)` or another receiver form appearing as the second input of the method signature processed by the macro.","commonSituations":"Hand-written or macro-generated signatures that mistakenly include a second `self`/`&mut self` parameter; typos where an intended typed parameter was written as `&mut self`; code generated by refactoring tools that duplicated the receiver.","solutions":["Remove the second receiver; a method can only have one `self` receiver.","Replace the second receiver with a properly typed context parameter, e.g. `cx: &mut FunctionContext`.","If generated by another macro or tool, fix the generator to emit a typed second argument."],"exampleFix":"// before\nfn update(&self, &mut self) -> JsResult<JsUndefined> {\n    ...\n}\n\n// after\nfn update(&self, cx: &mut FunctionContext) -> JsResult<JsUndefined> {\n    ...\n}","handlingStrategy":"validation","validationCode":"// A method signature may contain at most one receiver and it must be first.\nfn validate_single_receiver(inputs: &[String]) -> Result<(), String> {\n    if inputs.iter().skip(1).any(|t| t.contains(\"self\")) {\n        return Err(\"method has a second receiver argument; replace it with a typed parameter\".into());\n    }\n    Ok(())\n}","typeGuard":"fn second_arg_is_typed(inputs: &[String]) -> bool {\n    inputs.get(1).map(|t| !t.contains(\"self\")).unwrap_or(true)\n}","tryCatchPattern":null,"preventionTips":["Never write `self` twice in a method signature; Rust itself only permits one receiver.","When generating signatures programmatically, always emit typed parameters after the receiver.","Treat `&mut self` appearing after the first parameter as a typo for a context argument like `cx: &mut FunctionContext`."],"tags":["rust","proc-macro","neon","signature","compile-time"],"backgroundTag":"invalid-argument-format","analyzedSha":"38960e4381d9ad13b551cdf2d261f609167c9bc2","analyzedAt":"2026-09-13T09:05:33.640Z","contentChangedAt":"2026-09-13T09:05:33.640Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}