From 46d8801acaa44374403e04f08710eb59ec809aaa Mon Sep 17 00:00:00 2001 From: Kevin Xiao Date: Wed, 19 Jul 2023 16:18:58 -0400 Subject: [PATCH] Move recursion check up --- kalk/src/interpreter.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kalk/src/interpreter.rs b/kalk/src/interpreter.rs index 5d7a115..ef14b22 100644 --- a/kalk/src/interpreter.rs +++ b/kalk/src/interpreter.rs @@ -342,6 +342,10 @@ pub(crate) fn eval_fn_call_expr( expressions: &[Expr], unit: Option<&String>, ) -> Result { + if context.recursion_depth > context.max_recursion_depth { + return Err(KalkError::StackOverflow); + } + if identifier.prime_count > 0 { context.is_approximation = true; } @@ -515,11 +519,6 @@ pub(crate) fn eval_fn_call_expr( match stmt_definition { Some(Stmt::FnDecl(_, arguments, fn_body)) => { - if context.recursion_depth > context.max_recursion_depth { - return Err(KalkError::StackOverflow); - } - - if arguments.len() != expressions.len() { return Err(KalkError::IncorrectAmountOfArguments( arguments.len(),