Skip to content

C#: an unqualified generic call (Get<T>(...), this.Get<T>(...)) drops its calls edge #3406

Closed

Description

@JensD-git

Summary

In C#, a call with an explicit type argument and no receiver never gets a calls edge, even
when the target method is declared on the caller's own class or on its base class. The
non-generic spelling of the same call resolves normally, so the type-argument list at the call
site is the whole trigger.

Measured on v0.9.56, the current release (published 2026-09-07). v0.9.55 behaves identically.

Reproducer

Three files, no corpus, no build needed. dotnet build on net8.0: 0 errors, 0 warnings.

// Settings.cs
namespace Demo
{
    public class Settings
    {
        public T Get<T>(string key) { return default(T); }   // target
        public string GetRaw(string key) { return key; }     // control target
    }
}

// Reader.cs
namespace Demo
{
    public class Reader : Settings
    {
        public int A() { return Get<int>("port"); }        // 1) no edge
        public int B() { return this.Get<int>("port"); }   // 2) no edge
        public string C() { return GetRaw("host"); }       // 3) edge
        public string D() { return this.GetRaw("host"); }  // 4) edge
    }
}

// Local.cs
namespace Demo
{
    public class Local
    {
        public T Make<T>() { return default(T); }
        public int E() { return Make<int>(); }             // 5) no edge, same class
    }
}
graphify extract src --code-only --no-cluster --out out
# Call site v0.9.56
1 Get<int>("port") — unqualified, generic, target on base class no edge
2 this.Get<int>("port") — same through this no edge
3 GetRaw("host") — control, unqualified, non-generic edge
4 this.GetRaw("host") — control, through this edge
5 Make<int>() — unqualified, generic, target on the same class no edge

2 of 5. All five target member nodes exist in the graph, and method/inherits edges are
correct — only the call-site-to-member match fails. Case 5 shows inheritance is not involved.

Expected

Cases 1, 2 and 5 should produce a calls edge to .Get() / .Make(), exactly as the
non-generic controls 3 and 4 do. The type-argument list is not part of the method's identity.

Where it happens (v0.9.56, graphify/extractors/engine.py; identical in v0.9.55)

  • :5389 elif fn_node is not None and fn_node.type == "identifier": — for Get<int>("port")
    tree-sitter gives the function field as a generic_name, not an identifier, so this branch
    is skipped. Control flow falls into the generic fallback at :5391-5408, which takes the
    node text verbatim (callee_name = raw at :5407) and so assigns
    callee_name = "Get<int>".
  • :5365 callee_name = _read_text(mname, source) — for this.Get<int>("port") the name
    field of the member_access_expression is a generic_name, so callee_name becomes
    "Get<int>".
  • In both cases the member index is keyed on the bare declared name, the lookup misses, and the
    edge is dropped silently.

What makes this worth one small change: a few lines further down, at :5409 and following,
the very same call node is walked structurally to emit the references[generic_arg] edges added
in #2911 — the code descends into generic_name and reads its type_argument_list properly. So
v0.9.56 already recognises these call sites as generic and already records what they instantiate;
only the callee name a few lines above is still taken as raw text. The comment on that block says
so itself: "the fallback path uses raw text and never sees the structured type-arg list".

Relation to existing reports — deliberately not a duplicate

#2624 (open) reports the qualified form, Registry.Fetch<Payload>() and
Bag<Payload>.Make(), and its reproducer contains only those. The unqualified forms appear nowhere in
that issue's reproducer; they were mentioned in passing in one comment on it, and demonstrated in
a comment on PR #2676. This report is about those forms only, with its own reproducer, its own
prevalence count, and — for the receiverless form — its own code path: :5389 and the fallback,
which #2624's reproducer never reaches. (The this.-spelling shares :5365 with it.)

PR #2676, open since 2026-08-12, strips the type-argument list from the call-site name; measured
locally against v0.9.56 it also resolves cases 1, 2 and 5 above. It is not part of any release,
so the behaviour described here is what v0.9.56 does today.

#2911 (type arguments at the call site) and #2913 (the same in field position) are closed and
their effect is in the release — the engine comment at :5409 names both. The unqualified
calls edge is what is left.

Scope

Counted on the syntax tree (not by regex) over a ~15,300-file C# estate, mixed .NET Framework and
net8: 2159 unqualified generic call sites and 628 spelled through this. Those are
occurrences of the shape, not confirmed lost edges — unlike the qualified form, whose targets
are frequently outside the corpus, these resolve against the caller's own class or a base class,
so their targets are in-corpus by construction. I am reporting the shape's prevalence, not
claiming a number of lost edges.

The three files above are the whole reproducer -- no corpus, no build step, and the
behaviour is reproducible from the PyPI release alone.

Activity

  1. safishamsi commented on Sep 9, 2026

    @safishamsi
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions