ReviewOS

home-lang/home

fix(ts): stop valid member receivers collapsing to never across flow

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

Parent

  • #783 checker-synthesized any provenance
  • Related prior narrowing fix: #672

Problem

Expanding #783 provenance to direct diagnosed member-access fallbacks exposes four existing Home-only TS2339 recoveries in the byte-pinned Zod 4.5.2 production graph. TypeScript accepts the graph, but Home narrows valid receivers to never and then substitutes an any-like result:

  • src/v4/classic/from-json-schema.ts:649 — baseSchema.default(...), where baseSchema is declared from convertBaseSchema(...): ZodType and reassigned through composition wrappers.
  • src/v4/classic/from-json-schema.ts:670 — subsequent schema.type and schema.$ref reads after schema.propertyNames !== undefined.
  • src/v4/classic/from-json-schema.ts:671 — schema.propertyNames inside the proven-defined branch.

The first site is an assignment-flow shape. The remaining three are a property-guard shape. They are distinct from #672's already-fixed impossible union constituent after truthy narrowing, although they share the false never symptom.

Evidence

  • Frozen archive: Zod 4.5.2, SHA-512 5e46170a8975d3e6daffa17f72e79657e4decd478ea975b485d789b7909d5e34d8780800420e4dd37450749f349a17c513bdbea5b96f60c5b8c32d90a7841bae.
  • Production graph: 106 TypeScript files.
  • Before direct-never provenance, the reviewed HM9002 count is 3.
  • With the truthful direct-never migration, the count is 7; all four added HM9002 warnings pair with Home-only Property ... does not exist on type 'never' TS2339 diagnostics at the positions above.

Requirements

  • Reduce both shapes to small source-independent checker regressions and compare exact diagnostics/types with the pinned TypeScript reference.
  • Fix the semantic flow/narrowing root cause; do not special-case Zod names, paths, default, propertyNames, $ref, or any source text.
  • Do not suppress TS2339, widen arbitrary never values, skip control-flow checks, or lower the HM9002 ratchet.
  • Remove exactly these four Home-only TS2339/HM9002 sites from the unchanged pinned graph without adding diagnostic identities.
  • Preserve legitimate never property diagnostics and TS18031/TS18032 intersection reduction.
  • Pass focused checker coverage, the complete checker and conformance suites, a stripped ReleaseFast build, and two pinned Zod runs.

Discovered while implementing #783; the provenance migration should land independently so this bug remains measurable.

8 days ago

Discovery checkpoint landed in 65b08af95 (Refs #835).

The #783 provenance migration now makes all four frozen Zod sites measurable:

  • classic/from-json-schema.ts:649 — baseSchema.default(...) on false never.
  • classic/from-json-schema.ts:670 — schema.type and schema.$ref on false never.
  • classic/from-json-schema.ts:671 — schema.propertyNames on false never.

Each HM9002 is paired with the existing Home-only TS2339 at the same access. Full checker, conformance, ReleaseFast, and the reviewed 7/7 Zod ratchet pass. This commit does not claim to fix #835; it establishes the stable signal the eventual semantic flow fix must remove.

8 days ago

Fixed on main in 948e7809d.

Root-cause correction: all four reported accesses are on schema (line 649's receiver is schema, not baseSchema). Home ORs constituent flags onto unions, so any | boolean carried is_any; negative predicate subtraction treated it as bare any and failed to remove boolean. Later property/discriminant guards restarted from that declared union instead of the active flow type, collapsing the valid receiver to never.

The fix is source-independent: union subtraction now reserves the bare-any fast path for non-unions, preserves catch-all any/unknown constituents while removing matching constituents, and chained discriminant narrowing starts from the active identifier flow. No diagnostic suppression, arbitrary never widening, source/name special case, or test weakening was added.

Verification under the 3,840 MB supervisor:

  • focused negative-typeof regressions: pass (1,799 MB peak)
  • broader typeof and never families: pass (1,745 MB / 1,799 MB)
  • complete checker: 4,465/4,465 (2,056 MB)
  • conformance: 16/16 smoke, 86/86 category, 586/586 baseline-aware (2,220 MB)
  • stripped ReleaseFast compiler: pass (3,030 MB)
  • frozen Zod 4.5.2 graph, two runs: 3/3 HM9002 (945 MB / 965 MB)
  • exact graph delta: only the four false TS2339 + four HM9002 lines disappeared; ordinary diagnostics 200 → 196, with no additions
  • ratchet controls, JSON, Zig format, and diff checks: pass

The checked-in HM9002 ceiling is restored from 7 to the reviewed 3.

Sign in to comment on this issue.