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
fix(call-resolver): resolve VB.NET Me and MyClass calls in the caller's own class (#2855)
Yang Bai8a796523791e
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.pyindex 954446d3e..eba0ba6e9 100644--- a/packages/core/src/repowise/core/ingestion/call_resolver.py+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py@@ -88,6 +88,9 @@ _IMPLICIT_RECEIVER_LANGUAGES = frozenset({"java", "csharp", "cpp", "kotlin"})# ``resolve_file`` narrows it to the member the argument count names._INHERITED_LANGUAGES = frozenset({"kotlin", "python", "typescript", "swift", "csharp"})+# VB.NET's own-instance receivers, lowercased: the language is case-insensitive.+_VBNET_SELF_RECEIVERS = frozenset({"me", "myclass"})+# Languages where a bare name is scoped lexically: it can only mean the# caller's own module, an explicit ``import`` or ``open``, or the prelude, so# repo-wide uniqueness is no evidence and only wildcard imports may merge names.@@ -1670,7 +1673,7 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):can hold the match, so index straight into those instead of scanningevery file's method dict."""- if call.receiver_name not in ("self", "this"):+ if not self._is_self_receiver(file_path, call.receiver_name):return Nonecaller_class = _extract_class_from_symbol_id(caller_id)if not caller_class:@@ -1682,6 +1685,21 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):return Nonereturn ResolvedCall(caller_id, sym_id, 0.95, call.line, "self_scope")+ def _is_self_receiver(self, file_path: str, receiver_name: str | None) -> bool:+ """Whether a receiver names the enclosing class's own instance.++ VB.NET spells it ``Me``, and ``MyClass`` for a call that skips an+ override, in any case since the language is case-insensitive. Asked+ of VB.NET files only: elsewhere ``Me`` is an ordinary identifier.+ """+ if receiver_name in ("self", "this"):+ return True+ return (+ receiver_name is not None+ and receiver_name.lower() in _VBNET_SELF_RECEIVERS+ and self._language_of(file_path) == "vbnet"+ )+def _self_inherited_call(self,file_path: str,diff --git a/tests/unit/ingestion/test_vbnet_self_calls.py b/tests/unit/ingestion/test_vbnet_self_calls.pynew file mode 100644index 000000000..1d0edbc83--- /dev/null+++ b/tests/unit/ingestion/test_vbnet_self_calls.py@@ -0,0 +1,93 @@+"""VB.NET spells its self-reference ``Me`` (and ``MyClass``), not ``this``."""++from __future__ import annotations++from pathlib import Path++from repowise.core.ingestion import ASTParser, FileTraverser, GraphBuilder+++def _build(repo: Path):+ traverser = FileTraverser(repo)+ parser = ASTParser()+ builder = GraphBuilder(repo_path=repo)+ for fi in traverser.traverse():+ builder.add_file(parser.parse_file(fi, Path(fi.abs_path).read_bytes()))+ return builder.build()+++def _calls(graph, caller: str) -> dict[str, str]:+ """``{callee id: resolution origin}`` for every call edge out of *caller*."""+ return {+ callee: data.get("resolution_origin")+ for _, callee, data in graph.out_edges(caller, data=True)+ if data.get("edge_type") == "calls"+ }+++def _form(receiver: str) -> str:+ return (+ "Public Class MainForm\n"+ " Private Sub Load()\n"+ f" {receiver}.Wire()\n"+ " End Sub\n"+ " Private Sub Wire()\n"+ " End Sub\n"+ "End Class\n"+ )+++def test_me_call_resolves_in_the_same_class(tmp_path: Path) -> None:+ (tmp_path / "MainForm.vb").write_text(_form("Me"))++ assert _calls(_build(tmp_path), "MainForm.vb::MainForm::Load") == {+ "MainForm.vb::MainForm::Wire": "self_scope"+ }+++def test_myclass_call_resolves_in_the_same_class(tmp_path: Path) -> None:+ (tmp_path / "MainForm.vb").write_text(_form("MyClass"))++ assert _calls(_build(tmp_path), "MainForm.vb::MainForm::Load") == {+ "MainForm.vb::MainForm::Wire": "self_scope"+ }+++def test_me_is_a_keyword_in_any_case(tmp_path: Path) -> None:+ # VB.NET is case-insensitive, so `me.Wire()` is the same call.+ (tmp_path / "MainForm.vb").write_text(_form("me"))++ assert _calls(_build(tmp_path), "MainForm.vb::MainForm::Load") == {+ "MainForm.vb::MainForm::Wire": "self_scope"+ }+++def test_me_call_reaches_a_sibling_partial_fragment(tmp_path: Path) -> None:+ (tmp_path / "MainForm.vb").write_text(+ "Partial Public Class MainForm\n"+ " Private Sub Load()\n"+ " Me.Wire()\n"+ " End Sub\n"+ "End Class\n"+ )+ (tmp_path / "MainForm.Designer.vb").write_text(+ "Partial Public Class MainForm\n Private Sub Wire()\n End Sub\nEnd Class\n"+ )++ assert _calls(_build(tmp_path), "MainForm.vb::MainForm::Load") == {+ "MainForm.Designer.vb::MainForm::Wire": "self_scope"+ }+++def test_a_csharp_receiver_named_me_is_not_a_self_call(tmp_path: Path) -> None:+ # `Me` is only a keyword in VB.NET. In C# it is an ordinary identifier, and+ # a call on it must not be read as a call on the enclosing class.+ (tmp_path / "Form.cs").write_text(+ "class Peer { public void Wire() {} }\n"+ "class Form\n{\n"+ " void Load(Peer Me)\n {\n Me.Wire();\n }\n"+ " void Wire() {}\n"+ "}\n"+ )++ assert "Form.cs::Form::Wire" not in _calls(_build(tmp_path), "Form.cs::Form::Load")