Interpreter - Check arity before calling
This commit is contained in:
parent
d47adab0f8
commit
3750b5226b
1 changed files with 14 additions and 2 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue