Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
feat(graph): resolve inherited calls in C# again (#1651)
Raghav Chamadiya12398b8686c4
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.pyindex 76ac8a0c5..be2a6fc43 100644--- a/packages/core/src/repowise/core/ingestion/call_resolver.py+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py@@ -58,18 +58,19 @@ _IMPLICIT_RECEIVER_LANGUAGES = frozenset({"java", "csharp", "cpp", "kotlin"})# its ancestors. Both shapes — an explicit ``self``/``this`` receiver and an# implicit one — end in the same walk.#-# C# is absent, and it is an exclusion rather than an omission: the method-# indexes are keyed ``(class, method)`` with no parameter list, so a class-# declaring several overloads of one name keeps whichever the index kept. Its-# precision audit came back 7/30, every failure the same wrong-overload-# pairing. C++ is absent because its heritage binds a qualified external+# C++ is absent because its heritage binds a qualified external# parent to a same-named local type, which puts unrelated siblings in one# hierarchy before this walk even runs. Java is absent because `java.scm`'s# bare-call pattern also matches `this.field.m()`, which no receiver-carrying# pattern claims, so such a call arrives here indistinguishable from a real# implicit receiver — and its measured population on two Java repos was zero,# so the tier could only cost.-_INHERITED_LANGUAGES = frozenset({"kotlin", "python", "typescript", "swift"})+#+# C# is present, and was once wrongly removed: a name's overloads all share one+# symbol id, so a declaration line read back out of the graph names an+# arbitrary overload. That reads as a wrong target and is not one — the id+# these calls resolve to is the id C# binds.+_INHERITED_LANGUAGES = frozenset({"kotlin", "python", "typescript", "swift", "csharp"})# Ancestors within four hops: ``heritage_ancestors`` bounds expansion, not# reach, so 3 reaches 4.diff --git a/packages/core/src/repowise/core/ingestion/parser_helpers.py b/packages/core/src/repowise/core/ingestion/parser_helpers.pyindex 62f7a1ab8..ede09b8ad 100644--- a/packages/core/src/repowise/core/ingestion/parser_helpers.py+++ b/packages/core/src/repowise/core/ingestion/parser_helpers.py@@ -830,9 +830,19 @@ TYPE_HEAD_EXTRACTORS: dict[str, Callable[[Node, str], str | None]] = {def _count_arguments(arg_node: Node) -> int:- """Count the number of arguments in an argument/argument_list node."""+ """Count the number of arguments in an argument/argument_list node.++ Comments are children of the argument list, so an argument annotated with+ a trailing ``// name`` counted twice. Grammars spell the node type several+ ways (``comment``, ``line_comment``, ``block_comment``), hence the+ substring test rather than a fixed set.+ """skip_types = frozenset({"(", ")", ",", "[", "]"})- return sum(1 for child in arg_node.children if child.type not in skip_types)+ return sum(+ 1+ for child in arg_node.children+ if child.type not in skip_types and "comment" not in child.type+ )def _find_enclosing_symbol(diff --git a/tests/unit/ingestion/parser/test_misc.py b/tests/unit/ingestion/parser/test_misc.pyindex 7b9b310db..3a54bf03b 100644--- a/tests/unit/ingestion/parser/test_misc.py+++ b/tests/unit/ingestion/parser/test_misc.py@@ -93,3 +93,42 @@ class TestLanguageConfigs:assert result in ("public", "private", "protected", "internal"), (f"{lang} visibility_fn returned unexpected: {result}")+++class TestArgumentCount:+ """``CallSite.argument_count`` counts arguments, not comment tokens."""++ def _calls(self, source: bytes, path: str, language: str) -> dict[str, int | None]:+ parser = ASTParser()+ parsed = parser.parse_file(_make_file_info(path, language), source)+ return {c.target_name: c.argument_count for c in parsed.calls}++ def test_csharp_inline_comments_are_not_arguments(self) -> None:+ source = b"""\+public class C+{+ void Run()+ {+ Target(+ first, // Action<A, B> one,+ second, // Action<C> two,+ third);+ Plain(a, b);+ None();+ }+}+"""+ counts = self._calls(source, "C.cs", "csharp")+ assert counts["Target"] == 3+ assert counts["Plain"] == 2+ assert counts["None"] == 0++ def test_python_inline_comment_is_not_an_argument(self) -> None:+ source = b"""\+def run():+ target(+ first, # one+ second,+ )+"""+ assert self._calls(source, "m.py", "python")["target"] == 2diff --git a/tests/unit/ingestion/test_dispatch_edges.py b/tests/unit/ingestion/test_dispatch_edges.pyindex 4400c2234..72a8fb8fc 100644--- a/tests/unit/ingestion/test_dispatch_edges.py+++ b/tests/unit/ingestion/test_dispatch_edges.py@@ -335,3 +335,56 @@ def test_a_python_bare_call_is_not_read_as_an_implicit_receiver(tmp_path: Path)"python",)assert not _calls_by_origin(graph, "enclosing_inherited")+++def test_a_csharp_bare_call_reaches_an_inherited_method(tmp_path: Path) -> None:+ """C# resolves a bare call by neither package nor imported name, so an+ inherited member is only reachable through the ancestor walk. A decoy+ declares the name too, so a global-name guess cannot answer instead."""+ graph = _build(+ tmp_path,+ {+ "Base.cs": (+ "namespace App.Base;\n\npublic class Base\n{\n"+ " protected int Helper() => 1;\n}\n"+ ),+ "Mid.cs": "namespace App.Mid;\n\npublic class Mid : Base\n{\n}\n",+ "Child.cs": (+ "namespace App.Web;\n\npublic class Child : Mid\n{\n"+ " public int Run() => Helper();\n}\n"+ ),+ "Decoy.cs": (+ "namespace App.Other;\n\npublic class Decoy\n{\n"+ " public int Helper() => 9;\n}\n"+ ),+ },+ "csharp",+ )+ assert ("Child.cs::Child::Run", "Base.cs::Base::Helper") in _calls_by_origin(+ graph, "enclosing_inherited"+ )+++def test_a_csharp_overload_set_resolves_to_the_one_id_it_shares(tmp_path: Path) -> None:+ """Overloads of one name in one class carry one symbol id, so a call+ reaching any of them lands on the same node. Pins the property the+ inherited tier relies on: there is nothing to choose between."""+ graph = _build(+ tmp_path,+ {+ "Steps.cs": (+ "namespace App;\n\npublic class Steps\n{\n"+ " protected int Given() => 0;\n"+ " protected int Given(int a) => a;\n"+ " protected int Given(int a, int b) => a + b;\n}\n"+ ),+ "Test.cs": (+ "namespace App;\n\npublic class Test : Steps\n{\n"+ " public int Run() => Given(1, 2);\n}\n"+ ),+ },+ "csharp",+ )+ assert ("Test.cs::Test::Run", "Steps.cs::Steps::Given") in _calls_by_origin(+ graph, "enclosing_inherited"+ )