classes-2-extracted-method-bare-call.ts 828 B

123456789101112131415161718
  1. // A method extracted off an instance and called BARE (const m = r.run; m("go")). The
  2. // call loses runtime `this` binding semantics, but the analysis resolves `this`
  3. // lexically to the shared instance, so the this-dependent flow (this.base = ask#1's
  4. // artifact) must survive into ask#2. (Runtime: bare `this` is undefined and would
  5. // throw, but under the analysis's conflated-instance model the flow is the may-flow
  6. // of the .call/.bind family — the graph must keep it.)
  7. // Expected: source -> ask#1, ask#1 -> ask#2 (via this.base), ask#2 -> sink.
  8. const prompt = await agent("writer").ask<string>("prompt");
  9. class Runner {
  10. base = prompt;
  11. run(x: string): Node<string> {
  12. return agent("reader").ask<string>(`${this.base}: ${x}`);
  13. }
  14. }
  15. const r = new Runner();
  16. const m = r.run;
  17. const out = await m("go");
  18. return out;