classes-2-class-expr-in-field.ts 783 B

123456789101112131415161718192021
  1. // A class EXPRESSION stored in an object field and new'd through box.C. Runtime:
  2. // inst.keep(secret) stores secret in this.stored; inst.reveal() returns it into ask#2.
  3. // Probe: resolveClassNode only covers class-name identifiers and direct variable
  4. // bindings — a class value in an object field escapes it. Does the flow degrade soundly?
  5. // Expected: source -> ask#1, ask#1 -> ask#2 (keep -> this.stored -> reveal), ask#2 -> sink.
  6. const secret = await agent("writer").ask<string>("secret");
  7. const box = {
  8. C: class {
  9. stored = "";
  10. keep(x: string) {
  11. this.stored = x;
  12. }
  13. reveal(): string {
  14. return this.stored;
  15. }
  16. },
  17. };
  18. const inst = new box.C();
  19. inst.keep(secret);
  20. const out = await agent("reader").ask<string>(`use ${inst.reveal()}`);
  21. return out;