Repository navigation
fix(javascript): attribute writes through a simple thunk's call result - #1468
akushonkamen wants to merge 1 commit into
Conversation
A write through a function's returned object, such as `get().x = 2` where `get` is a local thunk returning `shared`, never reached the underlying binding. The mutation collector's referencedValues had no CallExpression branch, so call bases fell through to the empty fallback, mutatedPaths stayed empty, and the return shape kept reporting the stale literal while coverage claimed to be complete. Call results now resolve through simple local thunks: the callee's initializer must be a synchronous, non-generator function whose returns are identifiers or member chains with exact static keys rooted in a captured binding. Each resolved root re-enters the alias walk, where the existing per-origin lifetime closes cycles; returned calls stay unexpanded. Async and generator callees hand back wrappers rather than the returned object, so they are skipped and unrelated results keep their known literals. Fixes morluto#1449 Co-authored-by: Claude Opus 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: On 64 small cases, plain thunks now give an honest Every row returns 2 in real JS.
The PR body says slot forms stay as they were. Here the plain slot went to The async skip fits Controls: 19 forms where 1 is right. They cover fresh objects, copies and primitives. Some write another field. They also cover writes to a promise or iterator. 16 keep Tests: the PR's test file passes 163 of 163 on head. On main it fails 8 of 163. Those are the 8 new write-through cases. Both guards pass on main and head. Node 22, 24 and 26 agree. CLI and MCP agree on every case. Not runEdit: optional calls and async generators ran on main and #1471, not on this PR, in the #1471 results. Both give the stale
Thanks, akushonkamen, for the quick fix and the clear write-up. Full matrix (64 cases)Each case is
Commands
Test setup
🤖 Generated with Claude Code (Opus 5.5) 🦊 |
Fixes #1449
Root cause
referencedValuesinsrc/domain/javascript/javascriptSemanticMemberMutations.tshandled Object/Array/Assignment/Await/Sequence/Conditional/Logical bases, but had noCallExpressionbranch: a call base such asget()fell through to the emptyreturn []fallback. Forget().x = 2withconst get = () => shared, the write therefore never attributed toshared,binding.mutatedPathsstayed empty, the evaluation side never invalidated the cache (evaluateBindingwalksmutatedPathsinjavascriptSemanticValues.ts), andstatic_return_shapeskept reportingliteral 1while coverage claimedcomplete— a fact real JS cannot produce.Reproduction
The issue's fixture (
get().x = 2through a thunk) reportedliteral 1; a return shape ofliteral 2/unknownis the truth. Equivalent formsconst t = get(); t.x = 2,function get() { return shared; }, IIFE, member-chain thunks (() => shared.inner),deleteand++targets all reproduced. Reproduced as 8 failing unit cases before the fix (red), all passing after (green).Fix
referencedValuesgains aCallExpression/OptionalCallExpressionbranch that resolves the call through simple local thunks:returnat the function's own top level (skipping nested functions/classes) must be an identifier or a member chain with exact static keys rooted in a captured binding.Resolved roots re-enter the existing alias walk as exact paths (
[...chainKeys, ...initializerProjection, ...path]), where the per-origin binding lifetime already closes cycles — no fixed-cap pruning, consistent with the exact-path semantics established in #1390/#1445. A returned call is deliberately left unexpanded, so thunk chains cannot loop the pending queue.Tests
src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts:unknown: arrow thunk, stored call result, function declaration, function expression, IIFE, member-chain thunk,delete,++.asyncthunk keepsharedknown.tsc --noEmitclean; prettier/oxfmt/oxlint clean.Known remaining gap (not a regression)
Forms that park the call result in a property slot first (
o.a = get(); o.a.x = 2) still need slot-level value flow to attribute the later write; this change does not alter their behavior. They are listed under the issue's own "Not run" scope and need a slot-carried-reference mechanism, which I'd propose as a follow-up.Disclosure: prepared with AI assistance (ZCode agent, GLM), reviewed and tested by a human.