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 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-15 23:49:55 +00:00
parent 3584c03261
commit 6a55c37b20

View file

@ -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;
}