From ba69716b674bd6a760c88d6b799a90e5ce8d7fc4 Mon Sep 17 00:00:00 2001 From: Alexandre MAI Date: Fri, 13 Mar 2026 08:58:58 +0100 Subject: [PATCH] core: propagate stack underflow error in continuation instead of masking with undefined --- crates/zapcode-core/src/vm/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/zapcode-core/src/vm/mod.rs b/crates/zapcode-core/src/vm/mod.rs index a204b64..29d00d1 100644 --- a/crates/zapcode-core/src/vm/mod.rs +++ b/crates/zapcode-core/src/vm/mod.rs @@ -421,8 +421,10 @@ impl Vm { return Ok(false); } - // The callback just returned — collect its result from the stack - let callback_result = self.pop().unwrap_or(Value::Undefined); + // The callback just returned — collect its result from the stack. + // The compiler always emits PushUndefined+Return for implicit returns, + // so an empty stack here indicates a VM bug. + let callback_result = self.pop()?; // Unwrap internal promise values: async callbacks return // {__promise__: true, status: "resolved", value: X} or {status: "rejected", ...}.