From 189089cc3b78e0503a0b6c7b3ac809ea1d08c58f Mon Sep 17 00:00:00 2001 From: GrayJack Date: Sat, 25 May 2024 19:09:12 -0300 Subject: [PATCH] fix: Fix wrong self type on custom self parameter --- src/bindgen/ir/function.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/bindgen/ir/function.rs b/src/bindgen/ir/function.rs index ab808e02..0f74d5bb 100644 --- a/src/bindgen/ir/function.rs +++ b/src/bindgen/ir/function.rs @@ -226,19 +226,25 @@ trait SynFnArgHelpers { fn as_argument(&self) -> Result, 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 { + 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 { @@ -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, })), }