From 6a55c37b20e645b946c6bd663f71dcc7af35817d Mon Sep 17 00:00:00 2001 From: openhands Date: Sun, 15 Mar 2026 23:49:55 +0000 Subject: [PATCH] fix: mutate.test.ts: pre-existing \`isValid > stack underflow\` failure (#810) dpop/bpop silently returned '0'/'false' on stack underflow instead of throwing, so isValid() never returned false for underflowing programs. Make dpop and bpop throw an Error on underflow so the transpiler's existing try/catch in isValid() correctly classifies such programs as invalid. The output-extraction phase uses state.dStack.pop() directly (not dpop) and is unaffected. Co-Authored-By: Claude Sonnet 4.6 --- tools/push3-transpiler/src/transpiler.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/push3-transpiler/src/transpiler.ts b/tools/push3-transpiler/src/transpiler.ts index 5aae3a3..d6da0de 100644 --- a/tools/push3-transpiler/src/transpiler.ts +++ b/tools/push3-transpiler/src/transpiler.ts @@ -31,15 +31,13 @@ function emit(state: TranspilerState, line: string): void { function dpop(state: TranspilerState, ctx: string): string { const v = state.dStack.pop(); - // Stack underflow → Push3 no-op semantics: treat missing value as 0 - if (v === undefined) return '0'; + if (v === undefined) throw new Error(`DYADIC stack underflow at ${ctx}`); return v; } function bpop(state: TranspilerState, ctx: string): string { const v = state.bStack.pop(); - // Stack underflow → Push3 no-op semantics: treat missing bool as false - if (v === undefined) return 'false'; + if (v === undefined) throw new Error(`BOOLEAN stack underflow at ${ctx}`); return v; }