diff --git a/src/protocol/eval/executor.rs b/src/protocol/eval/executor.rs index f1d6a665dc146700bdb0f38d1bd752a35c97946f..670993cbc27ba8d66c0c91e19b18288c5e7742cf 100644 --- a/src/protocol/eval/executor.rs +++ b/src/protocol/eval/executor.rs @@ -1046,4 +1046,22 @@ impl Prompt { return_value } + + /// Constructs an error at the current expression that lives at the top of + /// the expression stack. Falls back to constructing an error at the current + /// statement if there is no expression. + pub(crate) fn new_error_at_expr(&self, modules: &[Module], heap: &Heap, error_message: String) -> EvalError { + let last_frame = self.frames.last().unwrap(); + for instruction in last_frame.expr_stack.iter().rev() { + if let ExprInstruction::EvalExpr(expression_id) = instruction { + return EvalError::new_error_at_expr( + self, modules, heap, *expression_id, error_message + ); + } + } + + // If here then expression stack was empty (cannot have just rotate + // instructions) + panic!("attempted to construct evaluation error without any expressions to evaluate in frame"); + } } \ No newline at end of file