ReviewOS

home-lang/home

Fix post-continue typeof narrowing for for-of bindings

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

Problem

Home does not preserve a typeof exclusion after a terminating continue for a for...of binding.

type Kind = "boolean" | "number" | "object" | "string" | "array" | "null" | "integer";
declare const type: Kind | Kind[] | undefined;
declare const seen: Kind[];

for (const member of Array.isArray(type) ? type : [type]) {
  if (typeof member !== "string") continue;
  if (!seen.includes(member)) seen.push(member);
}

TypeScript 6.0.3 and native TypeScript 7.0.2 accept this with zero diagnostics. Home reports two TS2345 diagnostics because undefined remains in member after the guard.

Scope

  • Treat continue and break as terminating the current statement path for post-guard narrowing, without treating them as function exits.
  • Preserve the literal string union after narrowing.
  • Add a checker regression test.
  • Re-audit the pinned Zod 4.5.2 corpus and require no new diagnostic locations versus the 602-diagnostic baseline.

Provenance

Found while validating the cross-module inherited-member work tracked by #534 against the fair Zod benchmark tracked by #548 and umbrella #416.

8 days ago

ReleaseFast validation is complete.

  • Standalone post-continue for-of reduction: Home 0 diagnostics; TypeScript 6.0.3 0; TypeScript 7.0.2 0.
  • Added checker coverage for RHS logical narrowing, post-continue narrowing, negative discriminant member guards, and literal subtraction from broad primitive unions.
  • Full checker suite: 4,353/4,353 passed.
  • The pinned Zod 4.5.2 audit improved from 602 to 523 diagnostics, with 79 unique location/code keys removed and 0 added.

Implementation is ready to split into an issue-linked conventional commit and push to origin/main.

8 days ago

Fixed on main by 2e749f7. The pushed change preserves false-branch guards after continue, recognizes for-in/of bindings as narrowable, keeps literal subtraction precise for broad primitive unions, and uses union-aware projected member lookup. Validation: TS6.0.3/TS7.0.2-calibrated reduction clean; checker 4,353/4,353; pinned Zod exact-key audit removed 79 keys with 0 added.

Sign in to comment on this issue.