Merge pull request #27 from fluencelabs/fix_ref_bools

Fix bool refs
This commit is contained in:
vms 2021-04-12 22:31:58 +03:00 committed by GitHub
commit 339dd4d58a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,19 +37,27 @@ impl ForeignModArgGlueCodeGenerator for ParsedType {
ParsedType::Record(..) => quote! {
#arg.__fce_generated_serialize() as _
},
ParsedType::Boolean(_) => quote! { #arg as _ },
ty => arg_for_basic_type(ty, &arg),
ty @ ParsedType::Boolean(_) => {
let deref_sign = maybe_deref(ty);
quote! { #deref_sign#arg as _ }
}
// this branch shouldn't be unite with booleans because otherwise
// conversion errors could be lost due to `as _` usage
ty => {
let deref_sign = maybe_deref(ty);
quote! { #deref_sign#arg }
}
}
}
}
fn arg_for_basic_type(ty: &ParsedType, arg: &syn::Ident) -> proc_macro2::TokenStream {
fn maybe_deref(ty: &ParsedType) -> proc_macro2::TokenStream {
use crate::parsed_type::PassingStyle;
let passing_style = crate::parsed_type::passing_style_of(ty);
match passing_style {
PassingStyle::ByValue => quote! { #arg },
_ => quote! { *#arg },
PassingStyle::ByValue => proc_macro2::TokenStream::new(),
_ => quote! { * },
}
}