ReviewOS

home-lang/home

fix(ts): enforce primitive return types for typed function bodies

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

Discovered while preparing fair async/await coverage in #473 (tracker #416). A strict ES2022/noLib project with unchanged Promise/PromiseLike/Awaited declarations from TypeScript 6.0.3 accepts async function use(): Promise<string> { const value: number = 1; return value; } in Home, while pinned TS 6.0.3 and native TS 7.0.2 both report TS2322. The return-statement checker gates primitive compatibility on special cases instead of enforcing the declared return type generally; investigate synchronous functions too. Fix the underlying typed-return validation with positive and negative regressions, preserving correct awaiting and diagnostic ownership. Do not admit or time the async workload until this and the other Promise propagation gaps found under #473 pass shared correctness controls. Publish tests and link small conventional commits.

8 days ago

The independent probe confirms this also affects all five canonical synchronous primitive return contracts (string, number, boolean, bigint, symbol): Home baseline silently accepts five invalid returns; both pinned TS versions emit five TS2322 diagnostics. The async probe has four invalid block returns (direct number, returned Promise<number>, awaited PromiseLike<string>, and a branch value) plus an expression-bodied control; both baselines emit five TS2322 diagnostics, Home only the expression-bodied one. Valid constrained/narrowed values and valid Promise/PromiseLike returns are included as positive controls. A related callback control exposed contextual return erasure: a block callback returning number passed to () => string was accepted; both TS versions report TS2345 at the callback. The working fix enforces primitive return compatibility generally, infers block-callback returns, and preserves call-level diagnostic ownership. Full checker regression testing is in progress; no performance claim or accepted async workload yet.

8 days ago

Implemented and pushed as 9e45e10 on main with configured user author and no coauthors. Five regression groups cover all canonical primitive returns, direct/returned/awaited Promise values, unknown and strict nullish values, non-strict null/any preservation, valid constrained/narrowed returns, and invalid block callback ownership. All 4,226 checker tests, 99 program tests, 173 driver tests and 16 benchmark harness/report tests pass. Release CLI cross-check against TS 6.0.3 and native TS 7.0.2 matches all expected codes across the five shared fixtures: 5 + 5 + 5 TS2322 errors, a clean non-strict fixture, and one TS2345 callback error. All existing 18 positive benchmark projects and 13 negative controls per compiler pass unchanged. Async diagnostic wording still has a separately tracked pre-existing discrepancy (#478); these checks establish rejection/code ownership, not byte-for-byte parity. Full unchanged 30-round benchmark and separately predeclared large-predicate confirmation are now running; results will be documented without filtering.

8 days ago

Completed in 9e45e10; results and shared correctness audit published in 75e02f3, both pushed to main. All 4,226 checker tests, 99 program tests, 173 driver tests and 16 harness/report tests pass. Five independently cross-checked CLI fixture groups match the expected TS 6.0.3/native TS 7.0.2 diagnostic codes, including rejecting unknown and strict nullish returns while preserving non-strict/any behavior and call-level TS2345 ownership. All existing benchmark correctness controls remain green. Full 30-round snapshot 20260827T202656Z retains 18/18 lower Home means; separate predeclared large confirmation 20260827T203044Z also records a 1.08× mean lead. All 1,710 samples, variance, and previous results are retained in README/docs. Closure is limited to primitive return validation and block callback inference; async admission stays open in #473 with #475/#476 semantic gaps and #478 diagnostic wording. This is not a full-parity or universal-performance claim.

Sign in to comment on this issue.