Repository navigation
Description
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:
- Same file: inside
static Bounds Bounds(int a) => new Bounds(a);, whereBoundsis Unity's type and outside the corpus, the construction becomes anEXTRACTEDself-loop on theBounds()helper. - Across files:
new List<int>()binds to an unrelatedMarket.List()method as anINFERREDedge. On a real codebase this turns oneList()method into a hub with a false caller for everynew List<T>()in the corpus. The cross-file pass already excludes enum members and fields/properties forcsharp_new(fix: prevent non-type nodes from hijacking C# type resolution #3815, C#: calls bind to enum members of the same name (follow-up to #3795) #4245), but not methods.
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'sWaitForSeconds()method (41 callers); new Rect()bound to aRect()UI helper (23 callers);new Stack<T>()bound to aStack()method.
Graphify version
0.9.89 (v8 e8eb76e)
Operating System
Windows (11)
Python Version
3.14
Installation Method
uv / pip (graphifyy)
Activity
github-actions commentedon Oct 13, 2026
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.
fix(csharp): `new X()` never binds to a method that shares X's name