ReviewOS

home-lang/home

fix(ts): join positive instanceof assignment flow

#738
Closed glennmichael123 opened this 8 days ago ·
8 days ago

Problem

Home narrows value inside a positive instanceof branch, but when that branch assigns a replacement value and falls through, it does not join the false path with the assigned true path.

Canonical example:

let result: Payload | Promise<Payload> = load();
if (result instanceof Promise) result = await result;
result.issues.map((issue) => issue);

Both reachable paths leave result as Payload. TypeScript 6.0.3 and native tsgo 7.0.2 therefore contextually type issue from Payload.issues. This was discovered while reducing #688, but it is a standalone control-flow rule rather than an imported-schema workaround.

Required behavior

  • Recognize a positive x instanceof T guard whose then-branch assigns back to x.
  • Subtract T from the false path and join it with the assigned true-path type.
  • Coalesce structurally identical types rather than retaining a redundant union.
  • Preserve existing negated-guard and terminating-branch behavior.
  • Add no project- or library-specific cases.

Verification

  • Focused oracle: Home, TypeScript 6.0.3, and native tsgo 7.0.2 agree exactly on the diagnostic code/location multiset (TS2322 at 13:11 and TS2339 at 14:11; no TS7006).
  • Full ts_checker suite passes.
  • Zod 4.5.2 src/v4/core/**/*.ts remains exactly diagnostic-identical to origin/main: 150 diagnostics, zero additions/removals.
  • ReleaseSafe home-tsc build passes.
  • Every heavy command was serialized under the repository guard with a fixed 3840 MB maximum.

Follow-up

This closes only the assignment-flow portion found during #688. The qualified imported issue-array projection remains open there; rejected broad projection attempts caused either a candidate-only bus error or extra Zod diagnostics and must not be landed.

8 days ago

Landed on main in f29b2a0dc.

Verification:

  • Home, TypeScript 6.0.3, and native tsgo 7.0.2 agree exactly on the strict oracle: TS2322 at 13:11 and TS2339 at 14:11, with no TS7006.
  • Full ts_checker suite passes (guarded peak 2,055 MB).
  • Stripped ReleaseSafe and ReleaseFast home-tsc builds pass (3,149 MB and 3,039 MB guarded peaks).
  • Zod 4.5.2 src/v4/core/**/*.ts is diagnostic-identical to the independent origin/main baseline: 150 diagnostics, zero additions/removals (candidate peak 2,595 MB).
  • zig fmt --check, git diff --check, and targeted Pickier for the edited Markdown pass.

The implementation is a general control-flow join with no library/source-name special case. Documentation is linked from the README.

Sign in to comment on this issue.