Files
scriptc/tests/corpus/2899-nested-mutual-recursion.ts
Chris Tateandryoppippi 11ed6e4d1d Fix nested mutual function recursion (#342)
* Fix nested mutual function recursion

- Predeclare nested function bindings before sibling closures capture them.
- Cover two- and three-way recursive declaration cycles across native backends.

Fixes #32

Co-authored-by: ryoppippi <1560508+ryoppippi@users.noreply.github.com>

* Record nested recursion parity baseline

- Add the generated TypeScript 7 order baseline for the nested mutual-recursion corpus fixture.

Fixes #32

Co-authored-by: ryoppippi <1560508+ryoppippi@users.noreply.github.com>

---------

Co-authored-by: ryoppippi <1560508+ryoppippi@users.noreply.github.com>
2026-09-17 10:22:01 -05:00

39 lines
736 B
TypeScript

function parity(n: number): string {
const result = even(n);
function even(k: number): string {
if (k === 0) return "even";
return odd(k - 1);
}
function odd(k: number): string {
if (k === 0) return "odd";
return even(k - 1);
}
return result;
}
console.log(parity(8), parity(7));
function threeWay(n: number): string {
function first(k: number): string {
if (k === 0) return "first";
return second(k - 1);
}
function second(k: number): string {
if (k === 0) return "second";
return third(k - 1);
}
function third(k: number): string {
if (k === 0) return "third";
return first(k - 1);
}
return `${first(n)},${second(n)},${third(n)}`;
}
console.log(threeWay(5));