Add arity check to Obj.__call__/Obj::do_call

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2024-10-07 17:21:29 -07:00
parent 40a10fa00e
commit 6143437626

View File

@@ -474,6 +474,23 @@ impl Obj {
.get_vtable_attr(obj_ptr.clone(), "__init__") .get_vtable_attr(obj_ptr.clone(), "__init__")
.expect("no __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(obj_ptr);
vm.push(init.clone()); vm.push(init.clone());
// duplicate arguments that were pushed to the frame // duplicate arguments that were pushed to the frame