Prevents panic in some strange cases. Seen in
@@ -481,6 +481,10 @@ fn reduce_term(&mut self, op_dir: &CompositeOpDir) -> bool {
return false;
}
+ if self.terms.len() < 1 + arity {
+ return false;
+ }
+
let stack_len = self.stack.len() - 2 * arity - 1;
let idx = self.terms.len() - arity;
@@ -638,6 +642,13 @@ fn reduce_list(&mut self) -> Result<bool, ParserError> {
term
};
+ if arity > self.terms.len() {
+ return Err(ParserError::IncompleteReduction(
+ self.lexer.line_num,
+ self.lexer.col_num
+ ))
+ }
+
let idx = self.terms.len() - arity;
let list = self.terms.drain(idx..).rev().fold(end_term, |acc, t| {
