ReviewOS

home-lang/home

Type checker: retain iterable collection flow after guards

#772
Closed chris opened this 8 days ago ·
8 days ago

Bun parity exposed two related checker flow defects in Zod 4.5.2:

  • instanceof Map and instanceof Set narrowed unknown to broad object, losing their iterable and collection interfaces.
  • A literal comparison against a broad property such as array.length === 0 incorrectly treated the property as a discriminant and narrowed the receiver to never on the opposite branch.

Implemented on main in 3886689:

  • resolve Map, Set, WeakMap, and WeakSet constructor guards to their structural instance types;
  • only discriminate a single object through unit-typed properties;
  • add regression coverage for collection guard iteration and array-length fallthrough.

Validation:

  • focused iterable checker tests: 27/27 passed;
  • complete ReleaseFast checker suite: 4,389/4,389 passed;
  • full JSC-enabled ReleaseFast build: 50/50 steps succeeded;
  • pinned Zod 4.5.2 diagnostics: 25 -> 21, with four primary removals, one dependent cascade removed, and zero additions.
8 days ago

Completed by 3886689 on main.

The collection guards now preserve structural iterable instance types, broad property comparisons no longer misclassify receivers as discriminated objects, all 4,389 checker tests pass in ReleaseFast, and the full JSC build passes 50/50 steps. The pinned Zod 4.5.2 run fell from 25 to 21 diagnostics with no additions.

Sign in to comment on this issue.