heap-aliasing-chained-ternary-alias-write.ts 640 B

12345678910111213
  1. // Chained conditional alias: `d` may be `a`, and `a` may be `b` or `c`, so at runtime
  2. // `d` may BE `b`. A write through `d` must reach b.f (and c.f, e.f) — the may-alias
  3. // replay has to RECURSE into a's own may-alias targets, or b/c miss the write.
  4. // Expected: ask#1 -> ask#2 data (via b.f); ask#2 -> sink.
  5. const b: { f: string } = { f: "" };
  6. const c: { f: string } = { f: "" };
  7. const e: { f: string } = { f: "" };
  8. const flag = Math.random() > 0.5;
  9. const flag2 = Math.random() > 0.5;
  10. const a = flag ? b : c;
  11. const d = flag2 ? a : e;
  12. d.f = await agent("writer").ask<string>("secret");
  13. return agent("reader").ask<string>(`use ${b.f}`);