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(graph): never bind a Kotlin member call to a property of the same name (#4829)
Swati Ahujaa5c9dd5f813d
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.pyindex dd642ca45..583beb87f 100644--- a/packages/core/src/repowise/core/ingestion/call_resolver.py+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py@@ -549,8 +549,11 @@ class CallResolver():aliases.append((sym.id, sym.alias_of, sym.parent_name))- # Method index: (class_name, method_name) → symbol_id- if sym.parent_name:+ # Method index: (class_name, method_name) → symbol_id. A property+ # holding no function is a value: ``x.f()`` never calls it, and a+ # same-named extension or inherited method is what it reaches.+ uncallable = _is_data_member(sym) and not self._holds_function(path, sym)+ if sym.parent_name and not (uncallable and sym.language in _PROPERTY_VARIABLE_LANGUAGES):key = (sym.parent_name, sym.name)file_methods[key] = index_idself._global_methods[key].append((path, index_id))@@ -563,7 +566,7 @@ class CallResolver(if extended is not None:extensions[(extended, sym.name)].add((path, index_id))- self._index_globally(path, sym, index_id)+ self._index_globally(path, sym, index_id, uncallable)for alias_id, alias_of_name, parent_name in aliases:# Prefer a target in the alias's own scope before falling back@@ -610,10 +613,10 @@ class CallResolver(return Nonereturn self._kotlin_receiver(sym)- def _index_globally(self, path: str, sym: Symbol, index_id: str) -> None:+ def _index_globally(self, path: str, sym: Symbol, index_id: str, uncallable: bool) -> None:if _has_internal_linkage(path, sym):self._tu_local_ids.add(index_id)- self._record_callability(path, sym, index_id)+ self._record_callability(index_id, uncallable)# A getter and its setter are two declarations under one id, which reads# as an overload set and is not one: the name is an attribute.if is_property_accessor(sym.decorators):@@ -623,12 +626,12 @@ class CallResolver(if not (bodiless_method or sym.kind in _EXTENSION_KINDS or is_anonymous_member(sym)):self._global_symbols[sym.name].append(index_id)- def _record_callability(self, path: str, sym: Symbol, index_id: str) -> None:+ def _record_callability(self, index_id: str, uncallable: bool) -> None:"""Mark *index_id* a data member's, unless anything callable shares it.A Kotlin `val isDark` and `fun isDark()` in one file are one id."""- if _is_data_member(sym) and not self._holds_function(path, sym):+ if uncallable:if index_id not in self._callable_ids:self._non_callable_ids.add(index_id)else:diff --git a/tests/unit/ingestion/test_return_type_chain_resolution.py b/tests/unit/ingestion/test_return_type_chain_resolution.pyindex 6fa0d037a..24c7cd115 100644--- a/tests/unit/ingestion/test_return_type_chain_resolution.py+++ b/tests/unit/ingestion/test_return_type_chain_resolution.py@@ -1086,6 +1086,46 @@ def test_kotlin_chained_call_reaches_an_extension_on_the_returned_type(tmp_path:assert any(callee.endswith("::extra") for callee in callees)+_KOTLIN_PROPERTY_AND_EXTENSION = (+ "interface Source\n"+ "class Peek(private val up: Int) : Source {\n"+ " private val buffer = 1\n"+ " val onClose: () -> Unit = {}\n"+ "}\n"+ "{extension}"+ "class Use {\n"+ " fun chain() { Peek(1).buffer() }\n"+ " fun local() { val p = Peek(1); p.buffer() }\n"+ " fun param(p: Peek) { p.buffer() }\n"+ " fun lambda(p: Peek) { p.onClose() }\n"+ "}\n"+ "class Holder(val p: Peek) {\n"+ " fun field() { p.buffer() }\n"+ "}\n"+)++[email protected]("extension", ["fun Source.buffer(): Int = 0\n", ""])+def test_kotlin_member_call_never_binds_a_property_of_the_name(+ tmp_path: Path, extension: str+) -> None:+ """``x.buffer()`` is the ``Source.buffer()`` extension, never the ``val buffer`` of ``x``'s class."""+ text = _KOTLIN_PROPERTY_AND_EXTENSION.replace("{extension}", extension)+ parsed = _parse(tmp_path, "a.kt", "kotlin", text)+ resolver = CallResolver(+ parsed, {"a.kt": set()}, heritage_parents={"a.kt::Peek": {"a.kt::Source"}}+ )+ edges = {+ (rc.caller_id.rpartition("::")[2], rc.callee_id)+ for rc in resolver.resolve_file("a.kt", parsed["a.kt"].calls)+ if not rc.callee_id.endswith("::Peek")+ }++ bound = {(caller, "a.kt::buffer") for caller in ("chain", "local", "param", "field")}+ # A property holding a function is still the callee of its call.+ assert edges == (bound if extension else set()) | {("lambda", "a.kt::Peek::onClose")}++@pytest.mark.parametrize("body",[