ReviewOS

home-lang/home

fix(ts): model ReadonlyArray member surface separately from mutable Array

#960
Open glennmichael123 opened this 6 days ago ·
6 days ago

Related: #846.

Pinned TypeScript 5.7.3 oracle with an admitted checked-JavaScript owner: owner.js exports a JSDoc ReadonlyArray<number> and a mutable Array<number>; main.ts reads both, writes indices, calls push, and makes deliberately wrong assignments. Under both checkJs=true and checkJs=false, tsc reports five diagnostics in source order: TS2542 at main.ts(4,1), TS2339 at (5,16) for readonlyValues.push, TS2322 at (6,7), TS2322 at (7,1), and TS2345 at (8,13). Home reports the other four exactly but silently accepts readonlyValues.push. A local TypeScript-only control using const readonlyValues: readonly number[] likewise reports TS2339 in tsc and no error in Home, so the defect is in the general checker rather than import projection.

Code evidence: packages/ts_checker/src/check.zig lookupArrayLikePrototypeMember, arrayLikePrototypeMember, direct member-access and call-signature paths all consult lib.arrayProto regardless of typeIsReadonlyArrayLike; packages/ts_checker/src/lib.zig arrayProto includes push/pop/sort/splice and other mutators. The declared-array fallback also searches both Array and ReadonlyArray aliases without receiver mutability. A proper fix needs a readonly array member surface and consistent selection across property access, call signatures, indexed/keyof lookup and declaration/augmentation paths. Preserve genuine ReadonlyArray interface augmentations, readonly callback parameter types, and mutable Array behavior; do not suppress TS2339 by name or weaken the oracle. Keep this issue open until exact CLI, local checker, and relevant regression suites pass under the agreed memory guard.

6 days ago

Repro fixture and exact 5-line TypeScript 5.7.3 oracle are now on origin/main at 76e351d. The fixture is intentionally not registered as a passing CLI test: Home still emits only four lines. The local readonly number[] control reproduces the same missing TS2339. A full fix must select the ReadonlyArray member surface consistently across all seven lib.arrayProto call sites and the declared-member fallback; callback array parameter types and interface augmentation behavior also need oracle coverage.

6 days ago

Progress on #960 is pushed directly to origin/main as 40e284179, d78b3338b, c7b1fee3c, and ea0b609a9 (glenn author, no coauthors). Checker now selects a separate readonly-array prototype across member, call, mapped, and keyof paths; declared ReadonlyArray<T> augmentations stay separate from mutable Array<T>; callback array parameters are readonly. The CLI stream suite compares exact TypeScript 5.7.3 stdout, stderr, and exit status for imported checked-JS arrays with checkJs on/off, a local readonly control, interface augmentation, and a map callback control. Focused Program serial/parallel and checkJs on/off, full Program, full checker, and final CLI stream suite exited 0 under the 3,840 MB guard; measured peaks were 1,972 MB, 2,446 MB, 2,375 MB, and 324 MB respectively. Keep this issue open: the synthetic readonly surface still lacks some TypeScript lib members (for example toString, toLocaleString, toReversed, toSpliced, and with), and the existing synthetic array model itself has known signature limits. These passing oracles do not establish complete ReadonlyArray parity.

6 days ago

Further #960 progress is on origin/main: 82385ba57 models TypeScript 5.7.3 ES2023 toReversed, both toSpliced overload shapes, and with on mutable and readonly arrays, with a general member-call fix for the sole arity-compatible overload; 9867fbd7f pins the imported-JS exact CLI oracle. The TypeScript oracle reports TS2345 at surface.ts:13:24 and 14:32, then TS2322 at 15:7; Home now matches all three lines, positions, order, stderr, and exit 2. toString and toLocaleString already resolved before this change and remain covered as successful calls. Guarded test-tsc-streams, full ts_checker, and full ts_program exited 0; measured peak tree footprints were 2,262 / 2,260 / 2,435 MB. Keep #960 open: this verifies these methods and overload behavior, not every lib declaration or all malformed overload diagnostics.

6 days ago

Further #960/#846 progress is pushed to origin/main as ed4ab8d (glenn author, no coauthors). A TypeScript 5.7.3 oracle with an admitted checked-JS owner showed ReadonlyArray<number>.entries() and mutable Array<number>.entries() yield [number, number] pairs: assigning the index or element to string produces exactly three TS2322 diagnostics at entries.ts(6,7), (7,7), and (12,7). Before the fix Home emitted no errors because the synthetic entries iterator used any; the general array prototype now carries the [number,T] tuple for both receiver surfaces. New focused lib and exact CLI-stream tests pin the behavior. Guarded test-tsc-streams, ts_checker and ts_program exited 0 (peaks 2,197 / 2,372 / 2,302 MB; lowest host free 27%); targeted pickier passed. Keep #960 open for the remainder of the lib surface and overload semantics.

6 days ago

Pushed f1b8155 to origin/main: array-origin assignability now elaborates concat result element mismatches directly, without changing the diagnostic chain for genuine structural numeric-index interfaces. Added exact TypeScript 5.7.3 concat fixture, local-literal and structural-index controls; test-tsc-streams, formatting and targeted pickier passed. Checker-suite result remains inconclusive due an anomalous failed-command line even though the wrapper returned 0. Project .zig-cache (27 GB) pruned after the run at user request.

6 days ago

Pushed 985587a and b81d6db to origin/main. Readonly and mutable flatMap calls now infer number[] when a callback returns number or readonly number[], and the ReadonlyArray flatMap callback array parameter follows TypeScript 5.7.3 lib.es2019.array.d.ts. The imported-JS fixture pins exact TS2322 text, location, stdout and exit for checkJs true and false. Guarded exact CLI stream and focused checker gates passed; direct full checker runner passed 4,705/4,705. Zig build-server full checker invocation timed out at 900 seconds and is not claimed passing. Separate generic U declaration leakage is tracked in #962; complete ReadonlyArray surface work remains open.

5 days ago

2026-10-28 checkpoint on origin/main: 28ff826 (implementation), b2f1c39 (imported-JS fixture), and 100f70f (exact CLI streams), all authored/committed by glennmichael123 without coauthors. ReadonlyArray.filter and Array.filter now model the TypeScript 5.7.3 predicate overload ahead of the ordinary unknown-returning overload. The checker attaches predicate metadata to the synthetic callback and infers the narrowed result type through overloaded-call inference. The admitted checked-JS fixture exports readonly and mutable number|string arrays. In both checkJs modes, TypeScript and Home agree exactly: valid predicate calls return number[], an ordinary truthy-value filter retains number|string, and only deliberate TS2322 errors occur at predicate.ts(5,7), (8,7), and (11,7), with empty stderr and exit 2. Focused checker regression passed; direct full checker binary passed 4707/4707 under the 3840 MB guard; guarded Program and test-tsc-streams passed. The Zig build wrapper for full checker printed a failed-command line despite exit 0, so the authoritative full-suite claim is the direct binary run. #960 remains open for the rest of the declared ReadonlyArray surface, including optional thisArg and other predicate overloads.

5 days ago

Checkpoint 2026-10-28: 2b5b632 and 84418cd are on origin/main as glennmichael123, no coauthors. Array and ReadonlyArray now expose TypeScript 5.7.3 find/findLast type-predicate overloads returning S | undefined, and filter/find/findLast accept optional thisArg. An imported checked-JS owner plus mutable control matches seven exact TS2322 diagnostics under checkJs on/off, including the ordinary non-narrowing find and the possibility of an undefined result. The change also corrected nullable-target TS2322 display using the semantic source/target; a pre-existing nullable-union regression was rechecked. Exact CLI streams pass, direct full checker reports All 4708 tests passed, and Program passes, all in sequential runs under the 3840 MB guard. #960 stays open: this is not the complete ReadonlyArray interface or all callback methods.

5 days ago

2026-10-28 checkpoint on origin/main: e269059 and bbff6a9 (glennmichael123, no coauthors) model the optional thisArg on TypeScript 5.7.3 array callback methods map, forEach, every, some, findIndex, and findLastIndex for readonly and mutable receivers. The checker records one required callback and an optional second any argument, preserving too-few/too-many arity errors and mapped result typing. A new #846 admitted checked-JS fixture pins the exact two TS5.7.3 diagnostics under checkJs true and false: TS2322 at main.ts(17,7) and TS2554 at main.ts(18,50); the previous Home binary emitted 14 extra TS2554 errors. Guarded focused checker, exact CLI streams, Program 456/456, LSP 139/139, and fresh #846 differential audit 84/84 passed. The Zig build wrapper reported 4709/4709 but also printed an anomalous failed-command line; an independent direct guarded run of its test binary conclusively reported All 4709 tests passed. This does not implement flatMap generic This or every type-predicate overload, nor the complete ReadonlyArray surface; #960 stays open.

5 days ago

Pushed 446e7f3 and a3c534d to origin/main. Added the predicate overload of mutable and readonly Array.every and tracked the selected overload in flow analysis, so a boolean callback cannot accidentally inherit a type guard. Exact TypeScript 5.7.3 imported-JS controls pass with and without checkJs; four intentional TS2322 diagnostics are pinned in test-tsc-streams. Focused checker test passes; full checker build reports 4710/4710, Program 456/456, tsc_main 103/103. This does not close the remaining ReadonlyArray surface issue; unsupported signatures stay tracked.

5 days ago

2026-10-28: 22b5481 and 56659d0 pushed to origin/main. ReadonlyArray and Array flatMap now carry both synthetic U and defaulted This binders, infer callback this from optional thisArg, preserve explicit callback this annotations, and reject an incompatible thisArg. TypeScript 5.7.3 and fresh Home matched the two new imported-JS configs exactly in both checkJs modes; the full #846 differential auditor matched 88/88 configs and guarded stream suite passed 136/136 steps. Guarded checker 4711/4712 had only a stale binder-count expectation; focused rerun after updating that assertion passed 2/2. Full checker rerun is pending host-memory recovery. Existing U | U[] callback return is still an approximation of the upstream U | ReadonlyArray surface, so #960 stays open.

5 days ago

Verification follow-up for 22b5481/56659d0: direct guarded checker executable exited 0 with All 4712 tests passed (peak tree footprint 997 MB), resolving the wrapper's contradictory failed-command line. Guarded Program 456/456 and tsc_main 103/103 passed. Exact imported-JS oracle audit remains 88/88 and stream suite 136/136. The remaining ReadonlyArray surface, including the existing U | U[] versus upstream U | ReadonlyArray callback approximation, is not claimed complete.

5 days ago

cdeb83b is now on origin/main as glennmichael123 with no coauthors. The flatMap synthetic callback return is now U | ReadonlyArray, with readonly index metadata on that exact callback array, while flatMap still returns mutable U[]. An explicit imported checked-JS readonly-array callback with <number> is accepted by TypeScript 5.7.3 and fresh Home in both checkJs modes; 88/88 #846 CLI config streams match exactly, and test-tsc-streams passed 136/136 steps. Full checker wrapper reports 4712/4712 passed but prints its known contradictory failed-command line; direct confirmation and Program/LSP reruns await safer host pressure. Other ReadonlyArray surface gaps remain, so #960 stays open.

5 days ago

cdeb83b final verification: direct guarded checker 4712/4712, Program 456/456, tsc_main 103/103, ts_lsp 139/139, test-tsc-streams 136/136 steps, and fresh TypeScript 5.7.3 versus Home #846 auditor 88/88 exact config streams. The checker wrapper's contradictory line was resolved by direct test-binary exit 0. The U | ReadonlyArray callback shape is now modeled; other ReadonlyArray surface work remains open.

Sign in to comment on this issue.