Repository navigation
fix(javascript): keep members unknown after a write through a local setter - #3831
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge; all previous findings are addressed and no new blocking issue was found. SummaryThe PR makes writes through local object-literal setters leave the receiver’s members unknown.
Reviews (3) · Last reviewed commit: "fix(javascript): ignore setters replaced..." · Reviewed by Greptile |
9dfc0b8 to
d17a5e0
Compare
…etter Assigning to a key that a setter of the binding's own object literal defines runs that setter, which may replace any member of its receiver. The member-mutation collector recorded it as an ordinary write to that one key, so sibling literals such as value: 1 stayed known and export-shape comparisons reported complete, unchanged shapes. Record such a write with an unknown key, which invalidates the object's known members. A computed setter key may match any written key. Fixes #3312 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… keys Resolve the written receiver along nested object-literal members so a write through a nested setter widens that receiver's members. A delete never calls a setter, so it keeps its exact path. Setter keys are computed once per object literal, including the no-setter result. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build cached setter keys from the effective definitions: a later data property or method with the same static name replaces the accessor, so assigning that key no longer runs a setter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
d17a5e0 to
8bf89cf
Compare
|
I found one more case that still reports a stale literal at export function observe() {
const { state } = { state: { value: 1, set update(next) { this.value = next; } } };
state.update = 2;
return state;
}Node returns |
|
There is a second variant where the setter write is followed by reading an ordinary member: export function observe() {
const state = { value: 1, set update(next) { this.value = next; } };
state.update = 2;
return { kind: "result", value: state.value };
}With a no-op setter, Node returns |
Fixes #3312 (setter case; see Remaining for the getter variant)
Root cause
collectSemanticMemberMutationsStepsrecordsstate.update = 2as an ordinary write to path["update"]. Whenupdateis a setter of the binding's own object literal, the assignment runs the setter instead, and the setter may write any member of its receiver (this.value = next). Only/updatewas invalidated, so the siblingvalue: 1stayed a known literal. Static return shapes then showed/value: 1, andcompare-javascript-export-shapesreported a no-op setter and a value-writing setter as complete and unchanged.Change
In the mutation collector, a one-key write whose key names a
setaccessor on one of the binding's own object-literal initializers (projection[]) is recorded with an unknown key ([null]). The existing mutation lattice already turns that intounknown("This property may have been mutated."). A computed setter key may match any written key, so it counts as matching. Writes to ordinary properties are unchanged and keep their sibling literals.Validation
The issue's public repro (
analyze-javascript-applicationon both fixtures, thencompare-javascript-export-shapes):main/valueliteral 1unknownthis.value = next)/valueliteral 1unknownunknown: 0, coveragecomplete-within-inputsunknown: 2, coveragepartialReal application: Discord
app.asarCLI output is identical: normalized JSON, 108,108,885 B both, 16.3 s vs 16.4 s. Output size is unchanged.Tests:
javascriptSemanticAnalysis.accessor_writes.test.ts: a write through a local setter leaves the returned objectunknown, and a write to an ordinary property keeps the siblingvalue: 1literal. The setter test fails onmain; I ran it before the change.npm run check:fast.Remaining
The issue also mentions the getter variant (
const observed = state.updatewithget update() { this.value = 2; … }). A getter runs on reads, which this mutation collector does not model as effects. Handling it needs read-site effect tracking, so I've left it out of this PR rather than mark every read of an accessor-bearing object unknown.🤖 Generated with Claude Code