Skip to content

[Bug]: C#: new X() binds to a method named X, and new Outer.X() is guessed by path proximity #4419

Closed

Description

@nixvideojuego-ui

What happened?

A C# new X(...) is resolved against every definition named X, methods included, so a construction can bind to a method that merely shares the type's name:

A related guess appears once those method candidates are gone. A qualified nested construction new QuickSlotsBar.Slot(), with several bare-name Slot classes in the corpus, goes to disambiguate_ambiguous_candidates. Its path-proximity tie-break ignores the qualifier and picks the Slot next to the caller. _resolve_csharp_qualified_calls (#2997) only handles namespace qualifiers, so a type qualifier is never consulted. Before, a same-named method candidate often made the tie unresolvable, which hid the guess.

Expected: new X() never binds to a method. A qualified nested construction takes the candidate nested in the named outer type, or gets no edge.

Steps to reproduce

import os, tempfile
from pathlib import Path
from graphify.extract import extract

os.chdir(tempfile.mkdtemp())
Path("Market.cs").write_text(
    "namespace Demo { public class Market { public static int List(int a) { return a; } } }\n")
Path("Use.cs").write_text(
    "namespace Demo { public class Use { public void Run() { var xs = new List<int>(); } } }\n")
Path("Box.cs").write_text(
    "namespace Demo { public class Box { static Bounds Bounds(int a) { return new Bounds(a); } } }\n")
r = extract([Path("Market.cs"), Path("Use.cs"), Path("Box.cs")], cache_root=Path(".cache"))
label = {n["id"]: n["label"] for n in r["nodes"]}
for e in r["edges"]:
    if e["relation"] == "calls":
        print(label[e["source"]], "->", label[e["target"]], f"({e['target']})", e["confidence"])

The qualified case:

import os, tempfile
from pathlib import Path
from graphify.extract import extract

os.chdir(tempfile.mkdtemp())
for d in ("UI", "Editor"):
    Path(d).mkdir()
Path("UI/Bar.cs").write_text(
    "namespace Game.UI { public class QuickSlotsBar { public class Slot { public int kind; } } }\n")
Path("Editor/Towers.cs").write_text(
    "namespace Game.Tools { public class Towers { class Slot { public string texture; } } }\n")
Path("Editor/Hud.cs").write_text(
    "using Game.UI;\n"
    "namespace Game.Tools { public class Hud {"
    " public void Ensure() { var s = new QuickSlotsBar.Slot { kind = 1 }; } } }\n")
files = [Path("UI/Bar.cs"), Path("Editor/Towers.cs"), Path("Editor/Hud.cs")]
r = extract(files, cache_root=Path(".cache"))
node = {n["id"]: n for n in r["nodes"]}
for e in r["edges"]:
    if e["relation"] == "calls":
        t = node[e["target"]]
        print(node[e["source"]]["label"], "->", t["label"], "in", t.get("source_file"), e["confidence"])

Error output or graph output

.Bounds() -> .Bounds() (box_demo_box_bounds) EXTRACTED      <- self-loop: `new Bounds(..)` is not a call to the helper
.Run() -> .List() (market_demo_market_list) INFERRED        <- `new List<int>()` is not Market.List()

.Ensure() -> Slot in Editor/Towers.cs INFERRED              <- source says QuickSlotsBar.Slot (UI/Bar.cs)

On a 1,512-file Unity C# codebase, 156 false calls edges came from this. Examples:

  • Unity's new WaitForSeconds() bound to UniTask's WaitForSeconds() method (41 callers);
  • new Rect() bound to a Rect() UI helper (23 callers);
  • new Stack<T>() bound to a Stack() method.

Graphify version

0.9.89 (v8 e8eb76e)

Operating System

Windows (11)

Python Version

3.14

Installation Method

uv / pip (graphifyy)

Activity

  1. github-actions commented on Oct 13, 2026

    @github-actions

    Thanks for opening this issue, @nixvideojuego-ui. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. added a commit that references this issue on Oct 13, 2026
    50436e7
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