Files
scriptc/tests
Malte UblandClaude Opus 5.5 3328ed2aa7 Lower union member reads the checker narrowed away
Reading a member off a union-typed value is what most pi refusals at
`SC1090` came down to: `credential.type` on `ApiKeyCredential |
OAuthCredential`, `session.role`, `entry.timestamp`, `tool.operations`,
`arms.length`, `renderer.hasOverlayEntries`.

Three read shapes reach the same dispatch and now answer:

- A checker-NARROWED receiver keeps the wider union it stores, because
  lowering erases flow narrowing (`stored?.type` after the earlier arm
  returned, `(entry as { role: string }).role`). The dispatcher now reads
  the member off whichever arm the value holds — an arm that does not
  declare it answers undefined, exactly Node's get — and narrows the
  answer to the checker's type, which traps on an arm the narrowing
  ruled out (types do not lie). This fallback sits after every existing
  lowering, so only refusals gain one.

- A member the arms answer through an ACCESSOR (a getter inherited from
  a shared base class, `renderer.hasOverlayEntries`) has no field slot
  `unionDisc` could read, so the read dispatches on the tag and calls
  each arm's own getter. Data-field unions keep their `unionDisc`
  lowering.

- `.length` on a union of arrays and strings (`Model[] | ModelRef[]`,
  `string[] | Buffer[]`) dispatches on the tag and answers each arm's
  own length.

The member read moves out of `lowerUnionProperty` into
`lowerUnionValueRead`, which both entry points share, and
`missingFieldAsUndefined` threads the narrowed-receiver get semantics
through the keyed read.

Corpus 8520/8521/8522 pin the three shapes differentially.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 05:38:11 -07:00
..
…