Skip to content

Commit 3b29844

Browse files
authored
fix(parity): infer var-typed local types from new-expression initializers in C# (#1424)
* test(bench): add JS fixture for bare-call class-scoped lookup regression guard (#1407) Adds class-scope.js to the JS resolution benchmark. The fixture contains a class with a bare flush() call inside run() and a Processor.flush method that must NOT be the target of that call — JS bare calls are lexically scoped to the module, never the class. The 1.0 precision floor for the JS fixture acts as the enforcement mechanism: if the call.receiver guard in resolveByMethodOrGlobal is ever removed, the resolver would emit Processor.run → Processor.flush as a false positive, immediately failing CI. Closes #1407 * fix(parity): infer var-declared local types from new-expression initializers in C# Both the WASM and native C# extractors were skipping variable declarations with `var`/`implicit_type` type nodes entirely, so `var service = new UserService(repo)` never added `service → UserService` to the typeMap. The call-edge resolver therefore could not resolve `service.AddUser()` or `service.GetUser()` to the qualified methods on `UserService`. The dist copy of the WASM extractor already had the fix (extractVarInitType), but the source had drifted out of sync. This commit re-introduces the logic in both engines: WASM (TypeScript): add `extractVarInitType(declarator)` that walks the variable_declarator children looking for an `object_creation_expression` (or one inside an `equals_value_clause`), then reads the `type` field via `extractCSharpTypeName`. `handleCSharpVarDecl` now sets `isVar` for `implicit_type | var_keyword` and calls `extractVarInitType` in that branch. Native (Rust): mirror the same logic in `extract_var_init_type` and update `match_csharp_type_map` to drive it when the type node is `var_keyword` or `implicit_type`. Infrastructure: add CODEGRAPH_NATIVE_ADDON_PATH env-var override to `loadNative()` for local development workflows where the published npm binary can't be loaded (its dylib install-name points to the CI build path). Tests now pass with CODEGRAPH_NATIVE_ADDON_PATH set to the locally rebuilt binary. Fixes: #1418 (build-parity test failure — native vs WASM C# edge/role divergence on `var`-typed local variables instantiated with `new`). * fix(resolver): gate bare-call same-class lookup on language (#1424) In JS/TS, bare foo() calls inside a class method are module-scoped — there is no implicit class binding. The same-class fallback in resolveByMethodOrGlobal was incorrectly emitting class-scoped edges for bare calls with no module-level match (e.g. flush() inside Processor.run resolving to Processor.flush). Gate the fallback: skip for bare calls in JS/TS, keep for this.method() calls and for C#/Java where bare calls are class-scoped. * fix: update class-scope.js PR reference from #1407 to #1422 (#1424) * fix: update bare-call guard PR reference from #1407 to #1422/#1424 (#1424)
1 parent 7019424 commit 3b29844

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

tests/benchmarks/resolution/resolution-benchmark.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const THRESHOLDS: Record<string, { precision: number; recall: number }> = {
129129
// total expected now 35. multi-class.js adds 4 class-scoped typeMap edges (#1382) → 39.
130130
// call/apply this-rebinding adds 2 edges (runCallThis→invoker, invoker→handler) and removes
131131
// the false-positive from handler being extracted as a callback arg of .call() (#1405) → 41.
132-
// #1407 adds class-scope.js (bare-call guard), +1 → total 42.
132+
// #1422 adds class-scope.js (bare-call guard), +1 → total 42.
133133
javascript: { precision: 1.0, recall: 0.9 },
134134
// pts-javascript: hand-authored points-to JS fixture (for-of, Set, Array.from, spread) — patterns
135135
// too broad for the main JS fixture. Patterns split per file to prevent intra-fixture FPs.

tests/unit/call-resolver.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* method fallback must apply computeConfidence >= 0.5 to avoid false edges from
1111
* distant files in a polyglot project.
1212
*
13-
* Also covers the bare-call JS/TS module-scope guard (#1407): bare `foo()` calls
13+
* Also covers the bare-call JS/TS module-scope guard (#1422/#1424): bare `foo()` calls
1414
* (no receiver) inside a JS/TS class method must NOT fall through to the same-class
1515
* lookup, because bare calls in those languages are module-scoped, not class-scoped.
1616
*/

0 commit comments

Comments
 (0)