fix(resolution): C and C++ nesting is never a scope

isLexicallyReachable trusted the graph's nesting for every language. C and
C++ have no nested named functions, so a function shown inside another is an
extraction artifact: tree-sitter-c cannot parse a macro call whose arguments
are designated initializers — betaflight's

    RESET_CONFIG(pidProfile_t, pidProfile, .pid = { … }, …);

— and its error recovery runs the enclosing function_definition (source lines
168–309) to line 1667, nesting the 45 functions after it. That tree has 310
such functions in 73 files. Before this commit exact-match already rejected
them as unreachable and the fuzzy fallback picked them up at 0.5; with the
survivor-side check alone, fuzzy rejected them too and 117 real calls into
pid.c disappeared (base → 4c8f165 on the 2,109-file betaflight fork: LOST
117, GAINED 0, all fuzzy, all pid.c).

With the gate the same tree is LOST 117 fuzzy / GAINED 117 exact-match — the
identical edges, now resolved by the strategy that should have had them, at
0.9. vite (no C) is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
danusha2345
2026-09-08 11:12:07 +03:00
co-authored by Claude Fable 5.1
parent 2521b49a9a
commit 7c758aaf0a
2 changed files with 20 additions and 0 deletions
+11
View File
@@ -354,6 +354,9 @@ export function matchFunctionRef(
return null;
}
/** Languages with no nested named functions: nesting in the graph is never a scope. */
const NO_NESTED_FUNCTIONS = new Set<string>(['c', 'cpp']);
/**
* A function nested inside another FUNCTION is only callable from within its
* container — Python, JS/TS, and every closure language scope it lexically.
@@ -371,6 +374,14 @@ function isLexicallyReachable(
context: ResolutionContext
): boolean {
if (candidate.kind !== 'function') return true;
// C and C++ have no nested named functions, so a function the graph shows
// inside another is an extraction artifact, not a scope: tree-sitter-c
// cannot parse a macro call whose arguments are designated initializers
// (betaflight's `RESET_CONFIG(pidProfile_t, pidProfile, .pid = {…})`), and
// its error recovery runs the enclosing function_definition to the end of
// the file, nesting every function after it. Trusting that nesting rejected
// 117 real calls into pid.c on that tree; the functions are reachable.
if (NO_NESTED_FUNCTIONS.has(candidate.language)) return true;
const qn = candidate.qualifiedName;
if (!qn || !qn.includes('::')) return true;
const parentQn = qn.slice(0, qn.lastIndexOf('::'));