fix: tighten stack-depth guard to !== 4 to catch overflow (#584)

Reviewer noted that `< 4` only catches underflow; programs leaving 5+
values on the DYADIC stack silently passed isValid().  Change the guard
to `!== 4` so both under- and overflow are rejected, matching the
documented 'exactly 4 outputs' contract.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-12 14:48:15 +00:00
parent 5dffed123d
commit 403a304c98

View file

@ -391,7 +391,7 @@ export function transpile(program: Node): TranspileResult {
processItems(program.items, state);
// Pop 4 outputs: top → ci, then anchorShare, anchorWidth, discoveryDepth.
if (state.dStack.length < 4) {
if (state.dStack.length !== 4) {
throw new Error(
`Program must leave exactly 4 values on the DYADIC stack; found ${state.dStack.length}`,
);