Fix get_attr_lazy

I had misunderstood/misused the ? suffix operator for the Option type.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2024-09-23 21:48:44 -07:00
parent 9c4898ff8d
commit fe586526df

View File

@@ -256,20 +256,24 @@ pub trait Obj: Debug + Display + Any + Trace {
let mut type_inst = self.type_inst(); let mut type_inst = self.type_inst();
loop { loop {
with_obj_downcast_mut(type_inst.clone(), |type_inst: &mut TypeInst| { let vtable_entry =
type_inst.vtable.get(name).cloned() with_obj_downcast_mut(type_inst.clone(), |type_inst: &mut TypeInst| {
}) type_inst.vtable.get(name).cloned()
.map(|vtable_entry| { })
let ptr = if obj_is_inst::<BuiltinFunctionInst>(&vtable_entry) .map(|vtable_entry| {
|| obj_is_inst::<UserFunctionInst>(&vtable_entry) let ptr = if obj_is_inst::<BuiltinFunctionInst>(&vtable_entry)
{ || obj_is_inst::<UserFunctionInst>(&vtable_entry)
MethodInst::create(method_ty.clone(), self_ptr.clone(), vtable_entry) {
} else { MethodInst::create(method_ty.clone(), self_ptr.clone(), vtable_entry)
vtable_entry } else {
}; vtable_entry
self.set_attr(name, ptr.clone()); };
ptr self.set_attr(name, ptr.clone());
})?; ptr
});
if vtable_entry.is_some() {
return vtable_entry;
}
let type_inst_copy = type_inst.borrow().type_inst(); let type_inst_copy = type_inst.borrow().type_inst();
if type_inst.borrow().equals(&*type_inst_copy.borrow()) { if type_inst.borrow().equals(&*type_inst_copy.borrow()) {
return None; return None;
@@ -1158,6 +1162,7 @@ fn test_obj_equals() {
assert!(obj2.borrow().equals(&*obj1.borrow())); assert!(obj2.borrow().equals(&*obj1.borrow()));
} }
#[test]
fn test_obj_vtable() { fn test_obj_vtable() {
let mut builtins = HashMap::new(); let mut builtins = HashMap::new();
init_types(&mut builtins); init_types(&mut builtins);