From 9452a720cc976f861f0e6769f9c7666abc8a3de4 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Tue, 15 Oct 2024 13:54:45 -0700 Subject: [PATCH] Add type to Obj instantiation, and fix mutable borrow * Objects will set their __ty__ during instantiation to the Obj type if no __ty__ has been set * In Object::get_vtable_attr we were borrowing the type as mutable, which was not necessary and causing issues when trying to borrow it mutably twice. This is probably because warnings of various types have been turned off and that will be investigated soon. Signed-off-by: Alek Ratzloff --- src/obj.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/obj.rs b/src/obj.rs index 2b34aca..bf7239c 100644 --- a/src/obj.rs +++ b/src/obj.rs @@ -147,8 +147,8 @@ pub trait Object: Debug + Display + Any + Trace { let mut ty = self.ty(); loop { let vtable_entry = - with_obj_downcast_mut(ty.clone(), |ty: &mut Ty| ty.vtable().get(name).cloned()) - .map(|vtable_entry| { + with_obj_downcast(ty.clone(), |ty: &Ty| ty.vtable().get(name).cloned()).map( + |vtable_entry| { let ptr = if obj_is_inst::(&vtable_entry) || obj_is_inst::(&vtable_entry) { @@ -161,7 +161,8 @@ pub trait Object: Debug + Display + Any + Trace { // floating around. //self.set_attr(name, ptr.clone()); ptr - }); + }, + ); if vtable_entry.is_some() { return vtable_entry; } @@ -261,6 +262,10 @@ impl Debug for Obj { impl Object for Obj { fn instantiate(&mut self) { + if self.get_attr("__ty__").is_none() { + let ty = BUILTINS.with_borrow(|builtins| builtins.get("Obj").expect("no Obj").clone()); + self.set_attr("__ty__", ty); + } self.is_instantiated = true; }