Skip to content

Commit

Permalink
fix: Fix wrong self type on custom self parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
GrayJack committed May 25, 2024
1 parent ab6d13d commit 189089c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/bindgen/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,25 @@ trait SynFnArgHelpers {
fn as_argument(&self) -> Result<Option<FunctionArgument>, String>;
}

fn gen_self_type(receiver: &syn::Receiver) -> Type {
let self_ty = Type::Path(GenericPath::self_path());
fn gen_self_type(receiver: &syn::Receiver) -> Result<Type, String> {
let mut self_ty = Type::Path(GenericPath::self_path());

// Custom self type
if receiver.colon_token.is_some() {
self_ty = Type::load(receiver.ty.as_ref())?.unwrap_or(self_ty);
}

if receiver.reference.is_none() {
return self_ty;
return Ok(self_ty);
}

let is_const = receiver.mutability.is_none();
Type::Ptr {
Ok(Type::Ptr {
ty: Box::new(self_ty),
is_const,
is_nullable: false,
is_ref: false,
}
})
}

impl SynFnArgHelpers for syn::FnArg {
Expand Down Expand Up @@ -274,7 +280,7 @@ impl SynFnArgHelpers for syn::FnArg {
}
syn::FnArg::Receiver(ref receiver) => Ok(Some(FunctionArgument {
name: Some("self".to_string()),
ty: gen_self_type(receiver),
ty: gen_self_type(receiver)?,
array_length: None,
})),
}
Expand Down

0 comments on commit 189089c

Please sign in to comment.