mirror of
https://git.proxmox.com/git/perlmod
synced 2025-10-05 11:53:58 +00:00
macro: verify parameter count
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
b9e50338b8
commit
e199764961
@ -1,6 +1,6 @@
|
||||
use failure::Error;
|
||||
|
||||
use proc_macro2::{Ident, TokenStream};
|
||||
use proc_macro2::{Ident, TokenStream, Span};
|
||||
|
||||
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! {
|
||||
#func
|
||||
|
||||
@ -116,6 +121,12 @@ pub fn handle_function(attr: FunctionAttrs, func: syn::ItemFn) -> Result<XSub, E
|
||||
|
||||
#extract_arguments
|
||||
|
||||
if args.next().is_some() {
|
||||
return Err(::perlmod::Value::new_string(#too_many_args_error)
|
||||
.into_mortal()
|
||||
.into_raw());
|
||||
}
|
||||
|
||||
drop(args);
|
||||
|
||||
#deserialized_arguments
|
||||
|
Loading…
Reference in New Issue
Block a user