ReviewOS

home-lang/home

fix(ts): preserve void returns for assertion signatures

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

Found in the retained-signature metadata tests for #488 (cross-file ownership #480/#487, tracker #416).

Home lowers TypeScript assertion predicates to boolean in both checkFnSignatureOnly and Lowerer.lower, although an asserts signature returns void. Ordinary value is T guards return boolean. This also aliases otherwise identical guard/assertion signature IDs and overwrites signature predicate metadata.

export {};
declare function isText(value: unknown): value is string;
declare function assertText(value: unknown): asserts value is string;
declare let value: unknown;
const goodGuard: boolean = isText(value);
const goodAssertion: void = assertText(value);
const badResult: boolean = assertText(value);
const badSignature: (value: unknown) => boolean = assertText;

TS 6.0.3 and native TS 7.0.2 report TS2322 for the two bad statements only. Home instead rejects goodAssertion (boolean not assignable to void) and accepts both invalid statements. Removing the two bad statements is accepted by both baselines and still rejected by Home.

Preserve void for assertions and boolean for ordinary guards in declaration and function-type lowering. Add shared positive/negative checks and metadata identity regressions without changing parameter lists to avoid the collision. Existing predicate benchmarks remain subject to their own rejection controls; this is not a reason to change frozen sources or claim a new speedup.

8 days ago

Fixed in 134a910. Assertion declarations, function types, and methods now return void; ordinary guards remain boolean. All three lowering paths are covered, and the tests retain identical guard/assertion parameter lists so the signature collision is exercised rather than avoided.

All 36 shared CLI controls pass against TS 6.0.3 and native TS 7.0.2: three families, script/module scopes, valid/invalid inputs, all three compilers. Each invalid project produces exactly two TS2322 errors (boolean result use and assignment to a boolean-returning function); removing only those statements is accepted. Low-level coverage also includes asserts value without an is target. All 4,236 checker tests and 175 driver tests pass, including retained predicate metadata after checker destruction.

All 72 previous callback controls still pass. Frozen predicate sources are unchanged, and their existing negative controls continue to pass. This is a correctness fix, not a measured speedup. Results: https://github.com/home-lang/home/blob/97ab7d4e4/docs/docs/TS_PERFORMANCE.md#checked-type-ownership-and-assertion-returns-untimed .

Sign in to comment on this issue.