Skip to content

fix(javascript): keep members unknown after a write through a local setter - #3831

Merged
kaoru0822-kitauji merged 3 commits into
mainfrom
fix/3312-setter-write-effects
Oct 15, 2026
Merged

kaoru0822-kitauji merged 3 commits into
mainfrom
fix/3312-setter-write-effects

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Fixes #3312 (setter case; see Remaining for the getter variant)

Root cause

collectSemanticMemberMutationsSteps records state.update = 2 as an ordinary write to path ["update"]. When update is 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 /update was invalidated, so the sibling value: 1 stayed a known literal. Static return shapes then showed /value: 1, and compare-javascript-export-shapes reported 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 set accessor 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 into unknown ("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-application on both fixtures, then compare-javascript-export-shapes):

main this PR
left (no-op setter) /value literal 1 unknown
right (this.value = next) /value literal 1 unknown
comparison unknown: 0, coverage complete-within-inputs unknown: 2, coverage partial

Real application: Discord app.asar CLI output is identical: normalized JSON, 108,108,885 B both, 16.3 s vs 16.4 s. Output size is unchanged.

Tests:

  • New javascriptSemanticAnalysis.accessor_writes.test.ts: a write through a local setter leaves the returned object unknown, and a write to an ordinary property keeps the sibling value: 1 literal. The setter test fails on main; I ran it before the change.
  • 161 JavaScript/domain test files pass (2,975 tests), as do the export-shape and mutation-presence MCP boundary tests (21) and npm run check:fast.

Remaining

The issue also mentions the getter variant (const observed = state.update with get 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

@kaoru0822-kitauji kaoru0822-kitauji added the track:perf Performance track PRs (issues & perf loop) label Oct 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-15T03:38:44.338653Z 9dfc0b8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; all previous findings are addressed and no new blocking issue was found.

Summary

The PR makes writes through local object-literal setters leave the receiver’s members unknown.

  • Writes through local setters make their receiver’s members unknown.

Reviews (3) · Last reviewed commit: "fix(javascript): ignore setters replaced..." · Reviewed by Greptile

@kaoru0822-kitauji
kaoru0822-kitauji force-pushed the fix/3312-setter-write-effects branch from 9dfc0b8 to d17a5e0 Compare October 15, 2026 03:53
kaoru0822-kitauji and others added 3 commits October 15, 2026 04:17
…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]>
@kaoru0822-kitauji
kaoru0822-kitauji force-pushed the fix/3312-setter-write-effects branch from d17a5e0 to 8bf89cf Compare October 15, 2026 04:18
@dayvison2b

Copy link
Copy Markdown
Contributor

I found one more case that still reports a stale literal at 8bf89cf:

export function observe() {
  const { state } = { state: { value: 1, set update(next) { this.value = next; } } };
  state.update = 2;
  return state;
}

Node returns value: 2, while the analysis keeps /value as literal 1. Array destructuring behaves the same way. The direct-initializer control is correctly marked unknown by this PR. I also get literal 1 at the parent commit 70cd4cb, so this looks like a remaining coverage gap rather than a regression from the PR. Could projected initializers be covered too?

@dayvison2b

Copy link
Copy Markdown
Contributor

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 1; with the value-writing setter, it returns 2. On this PR head, analyzing both apps and comparing their export shapes reports changes: [], unknown: 0, and complete-within-inputs. The parent commit 70cd4cb gives the same result, so this also looks like a remaining coverage gap rather than a regression. Returning state directly is covered by the PR; I haven't pinned down why this projected property read remains literal.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit acca91d into main Oct 15, 2026
32 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/3312-setter-write-effects branch October 15, 2026 04:39
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working track:perf Performance track PRs (issues & perf loop)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Setter writes leave stale sibling return literals

3 participants