macro: verify parameter count

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-01-13 14:21:45 +01:00
parent b9e50338b8
commit e199764961

View File

@ -1,6 +1,6 @@
use failure::Error; use failure::Error;
use proc_macro2::{Ident, TokenStream}; use proc_macro2::{Ident, TokenStream, Span};
use quote::quote; use quote::quote;
@ -94,6 +94,11 @@ pub fn handle_function(attr: FunctionAttrs, func: syn::ItemFn) -> Result<XSub, E
} }
} }
let too_many_args_error = syn::LitStr::new(
&format!("too many parameters for function '{}', (expected {})", name, sig.inputs.len()),
Span::call_site(),
);
let tokens = quote! { let tokens = quote! {
#func #func
@ -116,6 +121,12 @@ pub fn handle_function(attr: FunctionAttrs, func: syn::ItemFn) -> Result<XSub, E
#extract_arguments #extract_arguments
if args.next().is_some() {
return Err(::perlmod::Value::new_string(#too_many_args_error)
.into_mortal()
.into_raw());
}
drop(args); drop(args);
#deserialized_arguments #deserialized_arguments