Repository navigation
fix(js): shadow for...of / for...in loop bindings in indirect_call resolution (#2606) - #2685
ousamabenyounes wants to merge 1 commit into
Conversation
…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]>
There was a problem hiding this comment.
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
|
Shipped in v0.9.42 ( |
…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]>
Summary
Fix #2606
A JS/TS
for...of/for...inloop binding used as a value fabricates a phantomindirect_calledge to an unrelated same-named module function._js_local_bound_namescollected parameters andvariable_declaratortargets, but the loop variable offor (const entry of xs)is the statement'sleftpattern — not wrapped in avariable_declarator— soentrycontributed nothing to the per-function shadow set. Referenced as a value (object-shorthandpush({ entry })), it read as an unresolved by-name reference, resolved against the corpus-wide label index, and minted an INFERREDindirect_calledge (0.8) to an unrelated top-levelentry()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/vardeclarators. Both bare (for (const entry of xs)) and destructured (for (const { entry } of xs)) forms are handled; C-stylefor (let i = 0; ...)uses alexical_declarationwith real declarators and was always covered.Reproduces with
declaration.mjsdefinesentry(),consumer.mjsloopsfor (const entry of entries)and doesresolved.push({ entry }). Onv8before the fix:Expected: no edge — the
entryis afor...ofbinding, 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):
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):
Full suite
uv run --frozen pytest tests/ -q→4331 passed, 3 skipped. The only failures are 3 pre-existingtests/test_ollama.pybackend-detection tests that fail identically on the unmodifiedv8base (a local Ollama is reachable on the test host); they are unrelated to this change.Files changed
graphify/extractors/engine.pyfor_in_statement.leftbinding in_js_local_bound_namestests/test_indirect_call_for_of_binding_shadow.pyCHANGELOG.md