functions-summaries-mutual-recursion.ts 594 B

1234567891011121314
  1. // Mutual recursion: taint enters even(), threads through odd() and back, and exits
  2. // via the base-case ask. The summary fixpoint must carry seed across the cycle.
  3. // Expected: ask#2 (seed) -> ask#1 (final) data; ask#1 -> sink data.
  4. const judge = agent("judge");
  5. async function even(s: string, n: number): Promise<string> {
  6. if (n <= 0) return await judge.ask<string>(`final ${s}`);
  7. return odd(s, n - 1);
  8. }
  9. async function odd(s: string, n: number): Promise<string> {
  10. return even(s, n - 1);
  11. }
  12. const seed = await agent("s").ask<string>("seed");
  13. const out = await even(seed, 4);
  14. return out;