Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(objectivec): a static function in another .m file is not a call target (#2837)

Stefano Maffeisa3ee9f6587cc
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.py
index c56192f74..954446d3e 100644
--- a/packages/core/src/repowise/core/ingestion/call_resolver.py
+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py
@@ -203,7 +203,7 @@ def _has_internal_linkage(path: str, sym: Symbol) -> bool:
so only a source file keeps the symbol to itself.
"""
return (
- sym.language in ("c", "cpp")
+ sym.language in ("c", "cpp", "objectivec")
and sym.parent_name is None
and sym.visibility == "private"
and path.lower().endswith(_SOURCE_TU_EXTS)
diff --git a/packages/core/src/repowise/core/ingestion/parser.py b/packages/core/src/repowise/core/ingestion/parser.py
index f56ecbefb..fc7a7b592 100644
--- a/packages/core/src/repowise/core/ingestion/parser.py
+++ b/packages/core/src/repowise/core/ingestion/parser.py
@@ -854,8 +854,10 @@ def _refine_visibility(
"""``(visibility, is_exported_symbol)`` after the language's AST-context rules."""
# C/C++ visibility is dictated by AST context (access
# specifiers / storage class / export attributes), not by
- # modifier text. Refine after the generic fn ran.
- if language in ("cpp", "c"):
+ # modifier text. Refine after the generic fn ran. Objective-C's
+ # grammar is a superset of C's, so the same shapes apply to
+ # plain C code inside a ``.m`` file.
+ if language in ("cpp", "c", "objectivec"):
return refine_cpp_visibility(def_node, visibility, src)
# C#: an unmodified declaration's default depends on what encloses
# it, which the modifier-text fn cannot see.
diff --git a/packages/core/src/repowise/core/ingestion/resolvers/cpp.py b/packages/core/src/repowise/core/ingestion/resolvers/cpp.py
index 8a52f87af..f4e398aa9 100644
--- a/packages/core/src/repowise/core/ingestion/resolvers/cpp.py
+++ b/packages/core/src/repowise/core/ingestion/resolvers/cpp.py
@@ -34,7 +34,20 @@ from pathlib import Path
from ..languages.specs.cpp import INCLUDE_FRAGMENT_EXTENSIONS
from .context import ResolverContext
-_SOURCE_TU_EXTS: tuple[str, ...] = (".c", ".cc", ".cpp", ".cxx", ".c++", ".cppm", ".ixx", ".mxx")
+_SOURCE_TU_EXTS: tuple[str, ...] = (
+ ".c",
+ ".cc",
+ ".cpp",
+ ".cxx",
+ ".c++",
+ ".cppm",
+ ".ixx",
+ ".mxx",
+ # Objective-C is a superset of C, so a ``.m`` / ``.mm`` file is a
+ # translation unit for its plain-C symbols too.
+ ".m",
+ ".mm",
+)
# Include fragments sit with the headers: ``#include "math_impl.inl"`` resolves
# by the same rules, and a fragment is never a translation unit of its own.
_HEADER_EXTS: tuple[str, ...] = (
diff --git a/tests/unit/ingestion/test_cpp_internal_linkage.py b/tests/unit/ingestion/test_cpp_internal_linkage.py
index d10bd03f4..e1c24678d 100644
--- a/tests/unit/ingestion/test_cpp_internal_linkage.py
+++ b/tests/unit/ingestion/test_cpp_internal_linkage.py
@@ -72,3 +72,26 @@ def test_static_inline_in_a_header_still_binds(tmp_path: Path) -> None:
(tmp_path / "app.cpp").write_text("int run(int *p) { return load(p); }\n")
graph = _build(tmp_path)
assert _callees_of(graph, "app.cpp::run") == {"atomic.hpp::load"}
+
+
+def test_static_objectivec_function_in_another_m_file_is_not_bound(tmp_path: Path) -> None:
+ (tmp_path / "bench.m").write_text("static int make_client(void) { return 1; }\n")
+ (tmp_path / "server.m").write_text("int start(void) { return make_client(); }\n")
+ graph = _build(tmp_path)
+ assert _callees_of(graph, "server.m::start") == set()
+
+
+def test_static_objectivec_function_does_not_hide_the_linkable_one(tmp_path: Path) -> None:
+ (tmp_path / "bench.m").write_text("static int make_client(void) { return 1; }\n")
+ (tmp_path / "net.m").write_text("int make_client(void) { return 2; }\n")
+ (tmp_path / "server.m").write_text("int start(void) { return make_client(); }\n")
+ graph = _build(tmp_path)
+ assert _callees_of(graph, "server.m::start") == {"net.m::make_client"}
+
+
+def test_static_objectivec_function_in_the_same_m_file_still_binds(tmp_path: Path) -> None:
+ (tmp_path / "util.m").write_text(
+ "static int helper(void) { return 1; }\nint run(void) { return helper(); }\n"
+ )
+ graph = _build(tmp_path)
+ assert _callees_of(graph, "util.m::run") == {"util.m::helper"}