From 614343762697000f04c4e225d53c18ae1f801ce1 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Mon, 7 Oct 2024 17:21:29 -0700 Subject: [PATCH] Add arity check to Obj.__call__/Obj::do_call Signed-off-by: Alek Ratzloff --- src/obj.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/obj.rs b/src/obj.rs index 446257d..4c41e34 100644 --- a/src/obj.rs +++ b/src/obj.rs @@ -474,6 +474,23 @@ impl Obj { .get_vtable_attr(obj_ptr.clone(), "__init__") .expect("no __init__"); + // check arity against __init__ function + // TODO Obj::do_call - need to throw an exception when __init__ arity does not + // match what was passed to __call__ + // Also need to throw an exception when __init__ is not a + // function or doesn't have an arity + // BLOCKED-ON: exceptions + if let Some(arity) = init.borrow().arity() { + if argc != arity as usize { + todo!( + "TODO - throw an exception when {}.__call__ argc does not match the __init__ arity", + obj_ptr.borrow().ty_name() + ); + } + } else { + todo!("TODO - throw an exception when __init__ member does not have an arity or is not a function"); + } + vm.push(obj_ptr); vm.push(init.clone()); // duplicate arguments that were pushed to the frame