Repository navigation
Description
What
While verifying findResolvingScopeNode's new for_in_statement disjunct (PR #2612, plan for issue #2088) against the real tree-sitter-javascript grammar, found that a PARENTHESIZED for-of/for-in loop-head target is invisible to the shadow check the disjunct relies on, patternBindsName.
Verified against tree-sitter-javascript@0.25.0's node-types.json: for_in_statement.left's declared type list includes parenthesized_expression alongside identifier/array_pattern/object_pattern/member_expression/subscript_expression/undefined — i.e. for ((x) of arr) is grammar-valid, with left a parenthesized_expression wrapping the identifier x. patternBindsName (src/extractors/javascript.ts:4861-4909) has no case for parenthesized_expression and falls through to its default: return false (javascript.ts:4906-4907), so patternBindsName(left, name) returns false even when x === name — the loop-head binding is invisible to any caller that resolves it through this primitive.
Why this matters, and why it's the safe direction
Two call sites are affected identically, since both resolve the SAME left field through the SAME primitive:
findResolvingScopeNode'sfor_in_statementdisjunct (PR [Plan] issue-2088: receiver-correlated invoked-property evidence for object-literal value-refs #2612's plan, condition 4's identifier resolution) — a parenthesized loop-head shadow would resolve to whateverfindTopLevelFunctionNodeByNamefinds at module level instead of failing safe, the same failure class round 11 closed for the unparenthesized case.blockContainsIdentifierExcluding's own, pre-existingfor_in_statementbranch (javascript.ts:5197-5199, condition 3's reference-walk pruning, Computed-property (bracket-access) dispatch-table lookups lack a real calls edge, unlike dot-property value-refs #2260) — the identical call, on the identical field, already shipped.
Both are the same shadow-miss shape as the arrow-bare-parameter gap filed separately as its own #2088 plan follow-up — pathological syntax (parenthesizing a bare for-of/for-in target has no practical use apparent here, but the grammar permits it), and, for blockContainsIdentifierExcluding specifically, the safe direction: a missed shadow there causes over-inclusion in a reference walk whose contract only ever gets MORE conservative (more likely to escape) from spurious extra matches, never less sound.
Suggested fix shape (not binding — decide at execute/fix time)
Unwrap a leading parenthesized_expression (recursively, in case of nested parens) before applying the existing pattern-shape cases in patternBindsName, or add a dedicated case that delegates to its own single child. Add a fixture for for ((x) of arr) proving the unwrapped target is recognised, for both affected call sites.
Where
src/extractors/javascript.ts:4861-4909(patternBindsName, missingparenthesized_expressioncase)src/extractors/javascript.ts:5197-5199(blockContainsIdentifierExcluding's for-in branch, pre-existing consumer)docs/plans/issue-2088.md— WU-2'sfindResolvingScopeNode(new consumer, same field, same primitive)- Tracking issue: follow-up: receiver-type-aware invoked-property matching to reduce dead-code false negatives #2088. PR: [Plan] issue-2088: receiver-correlated invoked-property evidence for object-literal value-refs #2612.
Activity
docs: close round-12 arrow-parameter shadow gap in WU-2 condition 4
carlos-alm commentedon Aug 24, 2026
Correction to this issue's own rationale, found while implementing round 13 of the #2088 plan (PR #2612).
This issue's "Why this matters" section calls a parenthesized for-of/for-in loop-head target "the same shadow-miss shape as the arrow-bare-parameter gap" (filed as #2629). It is not, and the difference matters for anyone who picks this up.
for (const (x) of arr)— parenthesizing a target inside a DECLARING for-of/for-in head — is a SyntaxError, and tree-sitter-javascript's own grammar confirms this structurally, not just empirically. Checked againstgrammar.jsonintree-sitter-javascript@0.25.0: the hidden_for_headerrule's threekind-bearing branches (var;let/const;using/await using) each requireleftto beidentifier | alias('of', identifier) | _destructuring_pattern—parenthesized_expressionis not one of the alternatives in any of them.parenthesized_expressionis reachable only through the OTHER member of the same top-levelCHOICE— the one with nokindfield at all. So a parenthesized loop-head target is, by construction, never a declaration and never introduces a shadow — it is always an ASSIGNMENT to a pre-existing binding declared somewhere else. The arrow-bare-parameter gap (#2629) is the opposite kind of thing: a barerun => {…}parameter genuinely DECLARES a new, shadowing binding thatintroducesShadowedBindingsimply fails to see. Those are different failure classes, not the same one twice.This doesn't change what's broken here —
patternBindsName's missingparenthesized_expressioncase is real, and the suggested fix (unwrap the parens before applying the existing pattern-shape cases) is still correct and still safe: under-detecting either a shadow (condition 4's resolution question) or a write (a case added this round, see below) only ever pushes the analysis toward its already-accepted conservative direction, never toward unsoundness. But the write-up's framing would send whoever picks this up looking for a missed DECLARATION, when what's actually missing is recognition of an ASSIGNMENT target.One more consumer worth noting for whoever fixes this: round 13 of the #2088 plan (PR #2612) adds a
subtreeContainsReassignmentOfcheck that also callspatternBindsNameon afor_in_statement'sleftfield, for the same reasonfindResolvingScopeNode's existing for-in disjunct does. FixingpatternBindsNamehere will close a matching gap for that new caller too (a parenthesizedfor ((run) of arr)reassignment target), not just for the two consumers already listed in "Where."Leaving this open — the underlying
patternBindsNamegap is still real and still worth fixing, just for the reason above rather than the one originally stated.docs: fix issue-2088 plan's condition-4 reassignment gap (round 13)
carlos-alm commentedon Aug 24, 2026
Correction to my own immediately-preceding comment on this issue -- it was wrong, and the error is soundness-relevant, not a wording nit, so I want to flag it plainly rather than let it stand alongside the first correction.
That comment claimed: "under-detecting either a shadow (condition 4's resolution question) or a write (a case added this round, see below) only ever pushes the analysis toward its already-accepted conservative direction, never toward unsoundness." That is inverted, for both the shadow case and the write case. I over-generalized a safety property this issue's own original body correctly scoped to ONE consumer only, and wrongly extended it to the other two.
Why the original issue body's scoping was right.
blockContainsIdentifierExcluding's reference walk (condition 3, #2260) is a monotonic AND over every candidate reference position it finds. Missing a shadow there only ever ADDS an extra candidate node to check -- which can flip the walk's verdict from "tracked" to "not tracked" (conservative:escapesmoves towardtrue) but can never flip it the other way, since adding a conjunct to an AND cannot turn a false result true. The original issue body said this explicitly and correctly: "forblockContainsIdentifierExcludingspecifically, the safe direction."Why
findResolvingScopeNode's shadow check andsubtreeContainsReassignmentOf's write check are NOT this shape. Both are single fail-safe branches, not conjuncts in a walk. Missing a shadow infindResolvingScopeNodedoes not add anything to a check -- it REMOVES the fail-safe branch that would otherwise have fired, letting execution fall through tofindTopLevelFunctionNodeByName's module-level search, which then confidently resolves to whatever declaration it finds there. If that declaration happens to bethis-free, the function returns "safe" -- wrongly, since the shadow it missed might genuinely bethis-using. That is a confidently WRONG "safe" vote, i.e. fail-OPEN -- exactly the round-10/round-11 failure mode this whole resolution chain exists to close, not the conservative direction. The identical mechanism applies tosubtreeContainsReassignmentOf's write check: missing a write does not add a candidate to an AND, it lets a stale, already-resolved initial value be trusted as though no later reassignment existed -- again fail-open, not conservative.Net effect. My prior comment's safety claim holds ONLY for
blockContainsIdentifierExcluding, exactly as the original issue body already said. It does NOT extend tofindResolvingScopeNode's shadow check or tosubtreeContainsReassignmentOf's write check, both of which remain genuine, if narrow and pathological, soundness gaps for as long aspatternBindsNamehas noparenthesized_expressioncase.Re-scoping. This issue now names FOUR affected call sites, not three. Round 14 (PR #2612) additionally routes
subtreeContainsReassignmentOf's assignment-expression branch throughpatternBindsName(closing a separate, unrelated detection gap -- see that commit), so a parenthesized assignment target ((run) = fn) is now invisible to that arm too, alongside the pre-existing gaps infindResolvingScopeNode's for-in disjunct,blockContainsIdentifierExcluding's for-in branch, andsubtreeContainsReassignmentOf's OWN for-in branch. Of these four, onlyblockContainsIdentifierExcluding's is conservative-only; the other three are latent, narrow soundness gaps, not merely recall costs.Leaving this open -- the suggested fix (unwrap a leading
parenthesized_expressioninpatternBindsNamebefore applying its existing pattern-shape cases) is unchanged from the original.docs: close round-16 under-escape gaps in WU-2 condition 4 (#2630/#2632/
carlos-alm commentedon Aug 24, 2026
Status update, round 16 (PR #2612).
This issue's own second comment above already corrected the "safe direction" framing for three of its four named consumers (fail-OPEN, not conservative) and re-scoped this issue to four affected call sites. This comment is a closure update on top of that correction, not a re-litigation of it.
Round 16 closes three of the four:
findResolvingScopeNode'sfor_in_statementdisjunct (condition 4's resolution question)subtreeContainsReassignmentOf's ownfor_in_statementbranch (condition 4's write-scan)subtreeContainsReassignmentOf'sassignment_expression/augmented_assignment_expressionbranch (the fourth consumer the second comment above named)Fixed via a small local
unwrapParens(node)helper, called at each of these three call sites immediately before delegating topatternBindsName— not by adding aparenthesized_expressioncase topatternBindsNameitself.patternBindsNamestays exactly as narrow as its other verified consumers (blockContainsIdentifierExcluding's own for-in branch,killsBinding's assignment branch,declarationDeclaresName) already depend on it being.This issue's remaining scope narrows to its one conservative-direction consumer:
blockContainsIdentifierExcluding's ownfor_in_statementbranch (condition 3, #2260's reference-walk boundary). The second comment above already proves that one is safe to leave as-is — a missed shadow there only ever adds a spurious candidate to a conjunction (pushing towardescapes = true, never the other way) — so it's fine for it to remain open as an accepted, over-escape-direction limitation. The other three, being fail-open, could not be left that way.Mirrored in the Rust engine (
crates/codegraph-core/src/extractors/javascript.rs): a newunwrap_parenshelper at the equivalent three call sites, verified against the real, already-shippedpattern_binds_name's own_ => falsedefault arm (javascript.rs:5036), which carries the identical gap.See
docs/plans/issue-2088.md, WU-2'sfindResolvingScopeNodeandsubtreeContainsReassignmentOf(round-16 essays), and WU-10 escape-fallback cases (al)-(an).docs: apply Greptile's update_expression unwrapParens fix in WU-2
feat(roles): receiver-correlated invoked-property evidence for object…