From 9b7a863f45a7e76bf3a5a6f3f98c0f8576ba399a Mon Sep 17 00:00:00 2001 From: Matt Paras Date: Wed, 30 Oct 2024 19:55:51 -0700 Subject: [PATCH] safely error within eval if compilation error --- crates/steel-core/src/steel_vm/vm.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/steel-core/src/steel_vm/vm.rs b/crates/steel-core/src/steel_vm/vm.rs index 90e9c4d1d..9d55b875f 100644 --- a/crates/steel-core/src/steel_vm/vm.rs +++ b/crates/steel-core/src/steel_vm/vm.rs @@ -4596,7 +4596,10 @@ fn eval_program(program: crate::compiler::program::Executable, ctx: &mut VmCore) for (instr, span) in instructions.into_iter().zip(spans) { new_spans.extend_from_slice(&span); bytecode.extend_from_slice(&instr); - bytecode.last_mut().unwrap().op_code = OpCode::POPSINGLE; + bytecode + .last_mut() + .ok_or_else(throw!(Generic => "Compilation error: empty expression"))? + .op_code = OpCode::POPSINGLE; } bytecode.last_mut().unwrap().op_code = OpCode::POPPURE; let function_id = crate::compiler::code_gen::fresh_function_id();