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 v
}; };
if let Value::Callable(callable) = &callee { if let Value::Callable(callable_ref) = &callee {
Ok(callable.borrow().call(environment, arg_values)?.into()) 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 { } else {
Err(InterpreterError::new( Err(InterpreterError::new(
right_paren, right_paren,