fix(csharp): resolve chained static-factory calls Foo.Create().Bar() (#750) (#753)

A C# method called through a static factory or fluent chain —
`Foo.Create().Bar()`, `JObject.Parse(s).Property(...)`,
`Instant.FromUtc(...).InZone(zone)` — lost the receiver's type, so the chained
method didn't resolve and the call was invisible to callers/impact/trace. Ports
the #645/#608 mechanism to C# (additive, like Java #751):

- Part 1: capture C# return types in the extractor, reading the `returns` field
  (`static Foo Create()` -> `Foo`); predefined/array/generic/nullable/namespaced
  types are normalized or skipped.
- Part 2: encode a chained `member_access_expression` receiver
  (`Foo.Create(args).Bar()`) as `inner().Bar` with normalized empty parens, so
  factory calls that take arguments still split. Non-chained member calls keep
  their existing `recv.Method` text.
- Part 3: resolve via the shared matchDottedCallChain (now Java/Kotlin/C#),
  validated by resolveMethodOnType so a wrong inference yields NO edge.

Known limitation (safe): C# extension-method chains don't resolve, since the
method lives on the extension class, not the receiver's type — no edge, never a
wrong one.

Validated: synthetic decoy + args + absent-method safety tests; full suite green;
real-repo A/B on Newtonsoft.Json (945 .cs: +3, 0 lost) and nodatime (488 .cs:
+73, 0 lost) — node count identical (no explosion), 0 edges lost, precision
spot-checked verbatim (Instant.FromUtc().InZone(), Offset.FromHoursAndMinutes().Plus(),
OffsetDateTimePattern.CreateWithInvariantCulture().WithTwoDigitYearMax()).
EXTRACTION_VERSION 7 -> 8.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-06-09 00:30:03 -04:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 3e04650850
commit aa07dc59d4
6 changed files with 109 additions and 5 deletions
+16
View File
@@ -2567,6 +2567,22 @@ export class TreeSitterExtractor {
} else if (func.type === 'scoped_identifier' || func.type === 'scoped_call_expression') {
// Scoped call: Module::function()
calleeName = getNodeText(func, this.source);
} else if (this.language === 'csharp' && func.type === 'member_access_expression') {
// C# member call `recv.Method(...)`. When the receiver is itself a call
// — a chained factory `Foo.Create(args).Bar()` — encode `inner().Bar`
// with normalized empty parens so resolution can infer Bar's class from
// what `Foo.Create` RETURNS (#645/#608). A non-call receiver keeps the
// full member-access text (the existing `recv.Method` behavior).
const recv = getChildByField(func, 'expression');
const nameNode = getChildByField(func, 'name');
const methodName = nameNode ? getNodeText(nameNode, this.source) : '';
if (recv && recv.type === 'invocation_expression' && methodName) {
const innerFunc = getChildByField(recv, 'function');
const innerCallee = innerFunc ? getNodeText(innerFunc, this.source).replace(/\s+/g, '') : '';
calleeName = innerCallee ? `${innerCallee}().${methodName}` : methodName;
} else {
calleeName = getNodeText(func, this.source);
}
} else {
calleeName = getNodeText(func, this.source);
}