heap-aliasing-late-alias-loop.ts 563 B

1234567891011
  1. // Late alias: the aliasing assignment `wrap.box = box` sits AFTER the write in
  2. // source order; the loop makes the write hit the alias at runtime (iteration 2
  3. // writes through wrap.box === box). Flow-insensitivity must make order irrelevant.
  4. // Expected: ask#1 -> ask#2 data; ask#2 -> sink.
  5. const box: { f: string } = { f: "" };
  6. const wrap: { box?: { f: string } } = {};
  7. for (let i = 0; i < 2; i++) {
  8. if (wrap.box !== undefined) wrap.box.f = await agent("writer").ask<string>("secret");
  9. wrap.box = box;
  10. }
  11. return agent("reader").ask<string>(`use ${box.f}`);