array-spread-shared.ts 643 B

1234567891011
  1. // Sole-element array spread `[...arr1]` shallow-copies: `arr2[0] === arr1[0]` (shared
  2. // reference), so writing secret through arr2[0] is visible through arr1[0] at runtime. A
  3. // spread mixed with other elements is a documented residual (folds by value); this pins
  4. // the sole-spread sharing the spec models soundly.
  5. // Expected: source -> ask#1, ask#1 -> ask#2 (secret through the shared element), ask#2 -> sink.
  6. const arr1: { g: string }[] = [{ g: "" }];
  7. const arr2 = [...arr1];
  8. const secret = await agent("writer").ask<string>("secret");
  9. arr2[0]!.g = secret;
  10. const out = await agent("reader").ask<string>(`use ${arr1[0]!.g}`);
  11. return out;