classes-2-super-method-arg.ts 711 B

123456789101112131415161718192021
  1. // A derived method (different name from the base method) forwards its argument to
  2. // super.store(x), which writes this.v on the shared instance. At runtime
  3. // d.put(secret) => super.store(secret) => this.v = secret => d.v feeds ask#2.
  4. // Probe: does the argument of a `super.m(arg)` call reach the base method's parameter?
  5. // Expected: source -> ask#1, ask#1 -> ask#2 (via this.v), ask#2 -> sink.
  6. const secret = await agent("writer").ask<string>("secret");
  7. class Base {
  8. v = "";
  9. store(x: string) {
  10. this.v = x;
  11. }
  12. }
  13. class Derived extends Base {
  14. put(x: string) {
  15. super.store(x);
  16. }
  17. }
  18. const d = new Derived();
  19. d.put(secret);
  20. const out = await agent("reader").ask<string>(`use ${d.v}`);
  21. return out;