Skip to content

fix(js): shadow for...of / for...in loop bindings in indirect_call resolution (#2606) - #2685

Closed
ousamabenyounes wants to merge 1 commit into
Graphify-Labs:v8from
ousamabenyounes:fix/issue-2606
Closed

ousamabenyounes wants to merge 1 commit into
Graphify-Labs:v8from
ousamabenyounes:fix/issue-2606

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Summary

Fix #2606

A JS/TS for...of / for...in loop binding used as a value fabricates a phantom indirect_call edge to an unrelated same-named module function.

_js_local_bound_names collected parameters and variable_declarator targets, but the loop variable of for (const entry of xs) is the statement's left pattern — not wrapped in a variable_declarator — so entry contributed nothing to the per-function shadow set. Referenced as a value (object-shorthand push({ entry })), it read as an unresolved by-name reference, resolved against the corpus-wide label index, and minted an INFERRED indirect_call edge (0.8) to an unrelated top-level entry() in another file. A generic fixture/helper name then becomes a false high-betweenness hub, distorting god-node and community analysis.

This is the same declared/undeclared trap already fixed for single-arrow parameters (#2568-era) and catch bindings — the loop binding is now collected alongside parameters and const/let/var declarators. Both bare (for (const entry of xs)) and destructured (for (const { entry } of xs)) forms are handled; C-style for (let i = 0; ...) uses a lexical_declaration with real declarators and was always covered.

Reproduces with

declaration.mjs defines entry(), consumer.mjs loops for (const entry of entries) and does resolved.push({ entry }). On v8 before the fix:

indirect_call consumer_findnamed -> declaration_entry   (source consumer.mjs:4)

Expected: no edge — the entry is a for...of binding, not the imported/module function.

Test verification (RED → GREEN)

New tests/test_indirect_call_for_of_binding_shadow.py.

RED (prod fix reverted, tests intact):

FAILED test_for_of_binding_does_not_fabricate_indirect_call
FAILED test_for_of_destructuring_binding_shadows
2 failed, 1 passed

The passing one is the positive control (test_genuine_reference_outside_the_loop_still_emits) — a same-named callable referenced outside the loop still resolves, so the shadow-set widening does not blanket-suppress real edges.

GREEN (with fix):

3 passed

Full suite

uv run --frozen pytest tests/ -q → 4331 passed, 3 skipped. The only failures are 3 pre-existing tests/test_ollama.py backend-detection tests that fail identically on the unmodified v8 base (a local Ollama is reachable on the test host); they are unrelated to this change.

Files changed

File Change
graphify/extractors/engine.py collect for_in_statement.left binding in _js_local_bound_names
tests/test_indirect_call_for_of_binding_shadow.py new regression tests + positive control
CHANGELOG.md entry under 0.9.41

…solution (Graphify-Labs#2606)

A JS/TS `for (const entry of xs)` loop binding is the statement's `left`
pattern, not a `variable_declarator`, so `_js_local_bound_names` missed it.
Used as a value — e.g. object-shorthand `push({ entry })` — the name read as an
unresolved by-name reference and fabricated an INFERRED `indirect_call` edge to
an unrelated same-named module callable, turning a generic fixture/helper name
into a false high-betweenness hub. Collect the loop binding (bare or
destructured) alongside parameters and const/let/var declarators.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

This PR adds handling for JS/TS for...of / for...in loop bindings in the _js_local_bound_names function within the extractor engine. Previously only parameters and variable_declarator targets were collected as locally-bound names; the change also walks the left pattern of for_in_statement nodes so loop-variable names (including destructured ones) are added to the shadow set. A new test file covers the reported scenario (loop binding used in an object-shorthand argument), destructuring bindings, and a case where a genuine reference outside the loop should still resolve, plus a CHANGELOG entry documents the fix. Surface area is limited to one new branch in engine.py, one new test file, and a changelog line.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 780 functions depend on the 385 functions this change touches.

Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • _extract_generic() — 18 callers, 23 callees (high)
  • extract_xaml() — 19 callers, 17 callees (high)
  • extract_objc() — 27 callers, 9 callees (high)
  • extract_js() — 75 callers, 3 callees (high)
  • extract_julia() — 16 callers, 7 callees (high)
  • extract_vue() — 10 callers, 6 callees (high)
  • walk() — 1 callers, 54 callees (high)
  • extract_groovy() — 14 callers, 3 callees (high)
  • …and 2 more

Verification — 780 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 721 function(s) in the blast radius were not formally verified this run

safishamsi added a commit that referenced this pull request Aug 13, 2026
Correctness (#2685 loop-binding shadow, #2699 provenance, #2707 affected
seed, #2688 py subpackage imports, #2602 sql grammar, #2683 cache
integrity, #2682 report basename) + Windows portability/docs batch.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.42 (graphifyy==0.9.42 on PyPI). for-of/for-in loop bindings are shadowed (completes the #2568/#2569/#2517 family). Credited in the release notes. Thanks @ousamabenyounes!

@safishamsi safishamsi closed this Aug 13, 2026
safishamsi pushed a commit that referenced this pull request Aug 15, 2026
…lution (#2757)

An identifier bound by an import whose target resolves OUTSIDE the scanned
corpus (e.g. a lucide-react icon) is now shadowed within the file, so using it
as a value no longer fabricates an INFERRED indirect_call onto an unrelated
same-named callable elsewhere in the corpus. The internal-vs-external decision
is delegated to the existing import resolver, so a relative/in-corpus import
still resolves to its real target. Same shadow family as #2241/#2568/#2685.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JavaScript resolver links block-scoped object-shorthand variables to unrelated functions

2 participants