Interpreter - Check arity before calling

This commit is contained in:
Emmanuel BENOîT 2023-01-02 17:47:53 +01:00
parent d47adab0f8
commit 3750b5226b

View file

@ -398,8 +398,20 @@ impl ast::ExprNode {
}
v
};
if let Value::Callable(callable) = &callee {
Ok(callable.borrow().call(environment, arg_values)?.into())
if let Value::Callable(callable_ref) = &callee {
let callable = callable_ref.borrow();
if callable.arity() != arg_values.len() {
Err(InterpreterError::new(
right_paren,
&format!(
"expected {} arguments, found {}",
arg_values.len(),
callable.arity()
),
))
} else {
Ok(callable.call(environment, arg_values)?.into())
}
} else {
Err(InterpreterError::new(
right_paren,