graphify icon indicating copy to clipboard operation
graphify copied to clipboard

C#: calls/references missed when chained directly off a new X(...) expression

Open crokusek opened this issue 4 months ago • 2 comments

graphify version: 0.9.10 (pip package graphifyy) Language: C# Corpus: ~6,300 C# files, AST-only extraction via graphify update <path> (no LLM/semantic backend configured)

Bug

A method call chained directly onto a new X(...) object-creation expression (no intermediate variable) is not captured at all — neither as a calls edge to the invoked method, nor as a references/instantiation edge to the constructed type.

Repro

Source (ToolProductSvc.cs):

public ConnectableItemsGroupInformation GetMachineConnectableItemsInformationExt(
    GetConnectableItemsContext getConnectableItemsContext)
{
    return new StatefulFiltersMerger(getConnectableItemsContext.QueryContextFields)
        .GetConnectableItemsInformation(getConnectableItemsContext, true);
}

Expected: a calls edge from GetMachineConnectableItemsInformationExt to StatefulFiltersMerger.GetConnectableItemsInformation, and/or a reference edge to the StatefulFiltersMerger class.

Actual: the caller's node has zero calls edges. Its only outgoing edges are two references edges — to ConnectableItemsGroupInformation (return type) and GetConnectableItemsContext (parameter type). Nothing points at StatefulFiltersMerger or .GetConnectableItemsInformation(), even though both of those nodes exist correctly elsewhere in the same graph.

Verified via direct inspection of the output graph.json:

  • Caller node id: webservices_toolproductsvc_machiningcloud_server_webservices_toolproductsvc_getmachineconnectableitemsinformationext — outgoing edges: 2 references, 0 calls.
  • StatefulFiltersMerger class node exists correctly at Source/Server/Logic/ToolProduct/Filters/StatefulFiltersMerger.cs:L55.
  • .GetConnectableItemsInformation() method node exists correctly at Source/Server/Logic/ToolProduct/Filters/StatefulFiltersMerger.cs:L126.
  • No edge of any relation connects the caller to either of those two nodes, in either direction.

Suspected cause

The call-graph pass likely only attributes a calls edge when the receiver of a method call is a resolvable named symbol (local variable, field, parameter). A call fluently chained directly onto a new X(...) expression — i.e. new X(...).Method() with no assignment — appears to fall outside what the extractor's call-detection matches, and the constructor invocation itself isn't recorded as a reference either.

This is likely systematic rather than a one-off: any fluent/chained call directly off a constructor invocation anywhere in a C# corpus would silently disappear from the graph rather than erroring or warning, which could meaningfully understate a class's real dependencies/call graph.

Environment

  • graphify 0.9.10 (graphifyy on PyPI)
  • OS: Windows 11
  • Extraction: graphify update <path> (AST-only, C# tree-sitter grammar)

crokusek avatar Jul 10 '26 07:07 crokusek

The reported bug is already fixed in current releases (you're on 0.9.10; current is 0.9.12, with 0.9.13 in progress). On v8, new StatefulFiltersMerger(...).GetConnectableItemsInformation(...) — a method chained directly off a new X(...) expression with no intermediate variable — does emit a calls edge to the constructed type's method. Verified on a faithful repro (the caller gets calls -> .GetConnectableItemsInformation()), and added a regression test for the fluent new-expression receiver.

On the secondary point — no references/instantiation edge to the constructed class itself: that's graphify's general behavior, not specific to chained new. A variable-based var w = new Widget(); w.Go() likewise emits calls -> Go() but no edge to Widget — graphify doesn't currently model constructor invocation as a class-reference edge in any receiver form. If you'd like instantiation edges (new X() -> X) as a first-class relation, that's a reasonable enhancement — happy to track it as a separate feature request, since it'd apply uniformly across languages, not just this pattern. Please upgrade (uv tool install --upgrade graphifyy) to pick up the call-resolution fix. Thanks for the precise repro.

safishamsi avatar Jul 10 '26 20:07 safishamsi

We will upgrade now. Thank you for the details. Not sure the secondary point is needed yet, will file a request tbd.

crokusek avatar Jul 10 '26 22:07 crokusek