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(graph): type Kotlin, Swift and Dart locals from the call that assigns them (#3734)

Swati Ahujabd02d4d0db40
diff --git a/packages/core/src/repowise/core/ingestion/call_receiver_typing.py b/packages/core/src/repowise/core/ingestion/call_receiver_typing.py
index 0cd862382..b40616b77 100644
--- a/packages/core/src/repowise/core/ingestion/call_receiver_typing.py
+++ b/packages/core/src/repowise/core/ingestion/call_receiver_typing.py
@@ -48,7 +48,7 @@ from .languages.receiver_types import (
)
from .models import CallSite, NamedBinding, ParsedFile, Symbol, symbol_id_language
from .resolved_call import ResolvedCall
-from .return_types import declared_return_type, go_first_result
+from .return_types import declared_return_type, go_first_result, signature_parameter_count
from .symbol_identity import id_segment_name, outer_scope, symbol_id_path
from .type_names import (
POINTER_LIKE_MEMBERS,
@@ -126,6 +126,8 @@ _MAX_CHAIN_FIELDS = 3
# A chain is only as scoped as its weakest hop.
_CHAIN_TIER_RANK = {"same_file": 0, "import": 1}
_BODY_TYPE_CACHE_ENTRIES = 2048
+# What a Dart ``await`` unwraps: ``Future<T>`` / ``FutureOr<T>`` yield ``T``.
+_AWAITED_FUTURE = re.compile(r"(?:Future|FutureOr)<(.+)>\??")
_K = TypeVar("_K")
_V = TypeVar("_V")
@@ -1476,9 +1478,11 @@ class ReceiverTypingMixin:
# A repo-wide guess at the callee is not evidence of what it returns.
if resolved is None or "global" in resolved.origin:
return None
- return self._returned_type_id(resolved.callee_id, awaited)
+ return self._returned_type_id(resolved.callee_id, awaited, site.argument_count)
- def _returned_type_id(self, callee_id: str, awaited: bool = False) -> str | None:
+ def _returned_type_id(
+ self, callee_id: str, awaited: bool = False, argument_count: int | None = None
+ ) -> str | None:
"""The repository type a call to *callee_id* yields, as a symbol id.
A go ``T`` is looked up in the callee's own package and ``pkg.T`` in the
@@ -1489,7 +1493,8 @@ class ReceiverTypingMixin:
read in the callee's file as a chain hop reads a field's type. A
property is read, not called, and an ``async def`` returns a coroutine
unless the call is *awaited*. Any other language's declared return
- type is read by ``_written_returned_class``.
+ type is read by ``_written_returned_class``. Overloads that disagree
+ on what they return type nothing.
"""
symbol = self._symbols_by_id.get(callee_id)
path = self._symbol_paths_by_id.get(callee_id)
@@ -1497,11 +1502,26 @@ class ReceiverTypingMixin:
return None
if symbol.kind in _TYPE_KINDS:
return callee_id # a conversion, ``T(x)``
+ if self._overloads_disagree(symbol, path, argument_count):
+ return None
if symbol.language == "go":
return self._go_returned_type_id(symbol, path)
if symbol.language == "python":
return self._python_call_returns(symbol, path, awaited)
- return self._written_returned_class(symbol, path)
+ return self._written_returned_class(symbol, path, awaited)
+
+ def _overloads_disagree(self, symbol: Symbol, path: str, argument_count: int | None) -> bool:
+ """Do the overloads a call to *symbol* may mean declare different return types?
+
+ Asked at the call's argument count and at the symbol's own parameter
+ count: overloads sharing an id keep one declaration, and an extension
+ is called one argument short of its parameters.
+ """
+ counts = {argument_count, signature_parameter_count(symbol.signature or "")}
+ return any(
+ len(self._overload_return_types.get((path, symbol.parent_name, symbol.name, n), ())) > 1
+ for n in counts
+ )
def _python_call_returns(self, symbol: Symbol, path: str, awaited: bool) -> str | None:
"""``_returned_type_id`` for a Python function.
@@ -1534,14 +1554,18 @@ class ReceiverTypingMixin:
]
return found[0] if len(found) == 1 else None
- def _written_returned_class(self, symbol: Symbol, path: str) -> str | None:
+ def _written_returned_class(
+ self, symbol: Symbol, path: str, awaited: bool = False
+ ) -> str | None:
"""The class *symbol*'s declared return type names, as its file *path* sees it.
- One unqualified class name, nullable or not. Ceiling: a generic
+ One unqualified class name, nullable or not; an *awaited* Dart
+ ``Future<T>`` yields its ``T``. Ceiling: any other generic
(``Result<T>``) or prefixed (``p.Foo``) return type types nothing.
"""
- raw = declared_return_type(symbol.signature or "")
- written = raw.rstrip("?") if raw else ""
+ raw = declared_return_type(symbol.signature or "") or ""
+ future = _AWAITED_FUTURE.fullmatch(raw) if awaited else None
+ written = (future.group(1) if future else raw).rstrip("?")
if not written.isidentifier():
return None
found = self._class_seen_from(path, symbol.id, written, symbol.start_line)
@@ -1553,8 +1577,11 @@ class ReceiverTypingMixin:
"""The edge a bare ``name(..)`` in *scope_id* draws, when it lands on a class.
The tiers a constructor call takes say which class a name means in a
- file. A repository-wide guess is no evidence of that and is not taken.
+ file. A repository-wide guess is no evidence of that and is not taken,
+ nor is a same-package class the file's import from outside shadows.
"""
+ if name in self._externally_bound_names(file_path):
+ return None
probe = CallSite(
target_name=name,
receiver_name=None,
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.py
index 04edc8408..ba5af3a0a 100644
--- a/packages/core/src/repowise/core/ingestion/call_resolver.py
+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py
@@ -1785,12 +1785,8 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):
symbol_path = self._symbol_paths_by_id.get(callee_id)
if symbol_path is None:
return None
- # Overloads the arguments may mean, and declarations sharing this id
- # (an extension is called one argument short of its parameters).
- for count in {argument_count, signature_parameter_count(symbol.signature or "")}:
- key = (symbol_path, symbol.parent_name, symbol.name, count)
- if len(self._overload_return_types.get(key, ())) > 1:
- return None
+ if self._overloads_disagree(symbol, symbol_path, argument_count):
+ return None
if type_name is not None and language == "java":
# Read where the method declares it, with its member types in scope.
return self._read_java_type(symbol_path, callee_id, type_name)
diff --git a/packages/core/src/repowise/core/ingestion/extractors/signatures.py b/packages/core/src/repowise/core/ingestion/extractors/signatures.py
index 480752712..571e80a7f 100644
--- a/packages/core/src/repowise/core/ingestion/extractors/signatures.py
+++ b/packages/core/src/repowise/core/ingestion/extractors/signatures.py
@@ -43,7 +43,8 @@ def build_signature(node_type: str, name: str, params_text: str, def_node: Node,
node_type == "function_signature" and def_node.child_by_field_name("parameters")
):
# TS/JS use return_type; Go uses result
- return f"function {name}{params_text}{_ret(('return_type', 'result'))}"
+ returns = _ret(("return_type", "result")) or _kotlin_return(def_node, src)
+ return f"function {name}{params_text}{returns}"
if node_type == "function_signature":
# Dart: the return type is the unfielded nodes ahead of the name.
name_node = def_node.child_by_field_name("name")
@@ -113,3 +114,19 @@ def build_signature(node_type: str, name: str, params_text: str, def_node: Node,
return f"{name}{params_text}"
# Fallback
return f"{name}{params_text}"
+
+
+def _kotlin_return(def_node: Node, src: str) -> str:
+ """`` -> T`` for a Kotlin function: the unfielded type after ``(..):``."""
+ after_parameters = False
+ colon = False
+ for child in def_node.children:
+ if child.type == "function_value_parameters":
+ after_parameters = True
+ elif after_parameters and child.type == ":":
+ colon = True
+ elif colon:
+ return f" -> {node_text(child, src)}"
+ elif after_parameters:
+ return ""
+ return ""
diff --git a/packages/core/src/repowise/core/ingestion/languages/receiver_types.py b/packages/core/src/repowise/core/ingestion/languages/receiver_types.py
index 06f521708..94a33cd33 100644
--- a/packages/core/src/repowise/core/ingestion/languages/receiver_types.py
+++ b/packages/core/src/repowise/core/ingestion/languages/receiver_types.py
@@ -1071,16 +1071,34 @@ class CallAssignment(NamedTuple):
awaited: bool = False
+# The call a local is assigned from: ``[receiver.]target(``. A Kotlin, Swift or
+# Dart local annotated with its type is typed by its declaration instead.
+_CALL_HEAD = r"(?:(?P<receiver>[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)\.)?(?P<target>[A-Za-z_]\w*)\s*\("
+
# ``x = f(..)``, ``x = await obj.f(..)``: a plain statement-start assignment
# that ends its line. The resolver refuses a name the body also binds elsewhere.
_PY_CALL_ASSIGNMENT = re.compile(
- r"(?m)^[ \t]*(?P<name>[a-z_]\w*)[ \t]*=[ \t]*(?P<awaited>await[ \t]+)?"
- r"(?:(?P<receiver>[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)\.)?(?P<target>[A-Za-z_]\w*)\s*\("
+ rf"(?m)^[ \t]*(?P<name>[a-z_]\w*)[ \t]*=[ \t]*(?P<awaited>await[ \t]+)?{_CALL_HEAD}"
+)
+
+# ``val x = f(..)``, ``let x = try await obj.f(..)``, ``final x = await f(..);``.
+# Swift's ``try?`` value still calls the callee type's methods. A Dart
+# ``await`` unwraps the ``Future`` the callee declares.
+_KT_CALL_ASSIGNMENT = re.compile(rf"(?<![\w.])va[lr]\s+(?P<name>[a-z_]\w*)\s*=\s*{_CALL_HEAD}")
+_SWIFT_CALL_ASSIGNMENT = re.compile(
+ rf"(?<![\w.])(?:let|var)\s+(?P<name>[a-z_]\w*)\s*=\s*(?:try[?!]?\s+)?(?:await\s+)?{_CALL_HEAD}"
+)
+_DART_CALL_ASSIGNMENT = re.compile(
+ rf"(?<![\w.])(?:final|var|const)\s+(?P<name>[a-z_]\w*)\s*=\s*(?P<awaited>await\s+)?"
+ rf"(?:(?:new|const)\s+)?{_CALL_HEAD}"
)
_CALL_ASSIGNMENT_PATTERNS: dict[str, re.Pattern[str]] = {
+ "dart": _DART_CALL_ASSIGNMENT,
"go": _GO_CALL_DECL,
+ "kotlin": _KT_CALL_ASSIGNMENT,
"python": _PY_CALL_ASSIGNMENT,
+ "swift": _SWIFT_CALL_ASSIGNMENT,
}
# Languages whose locals may be typed from a call's declared return type.
@@ -1089,7 +1107,14 @@ CALL_TYPED_LANGUAGES = frozenset(_CALL_ASSIGNMENT_PATTERNS)
_QUOTES = frozenset("\"'`")
_STATEMENT_ENDS = frozenset("\n;}")
# A Python ``;`` may rebind the name later on the line, where no scan sees it.
-_LANGUAGE_STATEMENT_ENDS = {"python": frozenset("\n")}
+# Dart ends a statement only at ``;``, so ``f()\n.g()`` is one statement.
+_LANGUAGE_STATEMENT_ENDS = {"python": frozenset("\n"), "dart": frozenset(";")}
+# Kotlin and Swift may carry a statement onto a line that starts with a member
+# access or an operator (``.f()``, ``?: x``, ``as T``, ``&& y``). Refused
+# wholesale: a new statement starting so only costs the local its type.
+_NEXT_LINE_CONTINUES = {
+ language: re.compile(r"[.?:+\-*/%&|=!<>]|(?:as|is)\b") for language in ("kotlin", "swift")
+}
def _call_end(text: str, index: int) -> int:
@@ -1112,6 +1137,18 @@ def _call_end(text: str, index: int) -> int:
return -1
+def _call_ends_statement(cleaned: str, opened: int, language: str) -> bool:
+ """Does the call whose ``(`` ends just before *opened* end its statement?"""
+ end = _call_end(cleaned, opened)
+ if end < 0:
+ return False
+ rest = cleaned[end:].lstrip(" \t\n" if language == "dart" else " \t")
+ if rest and rest[0] not in _LANGUAGE_STATEMENT_ENDS.get(language, _STATEMENT_ENDS):
+ return False
+ continues = _NEXT_LINE_CONTINUES.get(language)
+ return continues is None or not continues.match(rest.lstrip())
+
+
def scan_call_assignments(text: str, language: str) -> tuple[CallAssignment, ...]:
"""Every local *text* declares from a single call, in line order.
@@ -1123,12 +1160,9 @@ def scan_call_assignments(text: str, language: str) -> tuple[CallAssignment, ...
return ()
cleaned = _without_comments(text, language)
starts = [0, *(newline.end() for newline in _NEWLINE.finditer(cleaned))]
- ends = _LANGUAGE_STATEMENT_ENDS.get(language, _STATEMENT_ENDS)
found: list[CallAssignment] = []
for match in pattern.finditer(cleaned):
- end = _call_end(cleaned, match.end())
- rest = cleaned[end:].lstrip(" \t") if end >= 0 else ""
- if end < 0 or (rest and rest[0] not in ends):
+ if not _call_ends_statement(cleaned, match.end(), language):
continue
found.append(
CallAssignment(
diff --git a/packages/core/src/repowise/core/ingestion/return_types.py b/packages/core/src/repowise/core/ingestion/return_types.py
index f6176c7d6..0727f35fe 100644
--- a/packages/core/src/repowise/core/ingestion/return_types.py
+++ b/packages/core/src/repowise/core/ingestion/return_types.py
@@ -12,10 +12,22 @@ _CPP_SUFFIX = re.compile(r"\s*(?:\*|&|&&)\s*$")
def declared_return_type(signature: str) -> str | None:
- """Return the declared portion of a stored symbol signature, if present."""
+ """Return the declared portion of a stored symbol signature, if present.
- _, separator, raw = signature.partition(" -> ")
- value = raw.strip() if separator else ""
+ The arrow is the one after the first parameter list, so a function-typed
+ parameter (``f(cb: () -> Foo) -> Bar``) does not end the list early.
+ """
+
+ opened = signature.find("(")
+ arrow = signature.find(" -> ")
+ if 0 <= opened < arrow:
+ depth = 0
+ for index in range(opened, len(signature)):
+ depth += {"(": 1, ")": -1}.get(signature[index], 0)
+ if depth == 0:
+ arrow = signature.find(" -> ", index)
+ break
+ value = signature[arrow + 4 :].strip() if arrow >= 0 else ""
return value or None
diff --git a/packages/core/src/repowise/core/upgrade/version.py b/packages/core/src/repowise/core/upgrade/version.py
index afc3b5e3c..fc0ad5f22 100644
--- a/packages/core/src/repowise/core/upgrade/version.py
+++ b/packages/core/src/repowise/core/upgrade/version.py
@@ -88,6 +88,7 @@ STORE_FORMAT_VERSION: int = 2
#: inner call.
#: A Dart call chained on a call (``a.b().c()``) carries that inner call too,
#: and a Dart function's signature carries its declared return type.
+#: A Kotlin function's signature carries its declared return type.
PARSER_SCHEMA_VERSION: int = 8
#: state.json key holding the store format version that wrote the store.
diff --git a/tests/unit/ingestion/test_receiver_types.py b/tests/unit/ingestion/test_receiver_types.py
index c599c3653..511a6bc26 100644
--- a/tests/unit/ingestion/test_receiver_types.py
+++ b/tests/unit/ingestion/test_receiver_types.py
@@ -798,6 +798,54 @@ class TestPythonCallAssignments:
assert scan_call_assignments("def f():\n u = g(); u = 3\n", "python") == ()
+class TestKotlinSwiftDartCallAssignments:
+ """``val x = f(..)``, ``let x = try f(..)``, ``final x = await f(..);``."""
+
+ @pytest.mark.parametrize(
+ ("language", "statement", "expected"),
+ [
+ ("kotlin", "val r = repo.make(1)", CallAssignment(2, "r", "repo", "make")),
+ ("swift", "let r = try await make()", CallAssignment(2, "r", None, "make")),
+ ("swift", "var r = try? A.make()", CallAssignment(2, "r", "A", "make")),
+ (
+ "dart",
+ "final r = await make(\n ')');",
+ CallAssignment(2, "r", None, "make", awaited=True),
+ ),
+ ("dart", "var r = Repo.create();", CallAssignment(2, "r", "Repo", "create")),
+ ],
+ )
+ def test_a_whole_statement_call(
+ self, language: str, statement: str, expected: CallAssignment
+ ) -> None:
+ body = f"f() {{\n {statement}\n}}"
+ assert scan_call_assignments(body, language) == (expected,)
+
+ @pytest.mark.parametrize(
+ ("language", "statement"),
+ [
+ ("kotlin", "val r = make()\n .other()"),
+ ("kotlin", "val r = make()\n ?.other()"),
+ ("kotlin", "val r = make()\n ?: Other()"),
+ ("kotlin", "val r = make()\n as Other"),
+ ("kotlin", "val r = make()\n && ok"),
+ ("kotlin", "val r: Repo = make()"), # its declaration types it
+ ("swift", "let r = make()\n .other()"),
+ ("swift", "let r = make()\n as! Other"),
+ ("dart", "final r = make()\n .other();"),
+ ("dart", "final r = make()\n ..other();"),
+ ],
+ )
+ def test_a_call_continued_on_the_next_line_is_refused(
+ self, language: str, statement: str
+ ) -> None:
+ assert scan_call_assignments(f"f() {{\n {statement}\n}}", language) == ()
+
+ def test_a_new_statement_on_the_next_line_keeps_the_call(self) -> None:
+ body = "f() {\n val r = make()\n r.load()\n}"
+ assert scan_call_assignments(body, "kotlin") == (CallAssignment(2, "r", None, "make"),)
+
+
class TestClassScope:
"""What counts as a field, given that a class span contains every method.
diff --git a/tests/unit/ingestion/test_return_type_chain_resolution.py b/tests/unit/ingestion/test_return_type_chain_resolution.py
index 9633ba556..57aff8f4f 100644
--- a/tests/unit/ingestion/test_return_type_chain_resolution.py
+++ b/tests/unit/ingestion/test_return_type_chain_resolution.py
@@ -855,3 +855,130 @@ def test_dart_constructor_initializers_are_not_calls(tmp_path: Path) -> None:
parsed = _parse(tmp_path, "b.dart", "dart", source)
assert parsed["b.dart"].calls == []
+
+
+ "body",
+ [
+ "var a = r.item(1);\na.save();",
+ "final a = await r.later();\na.save();", # an awaited Future yields its type
+ "final a = Repo.load('x');\na.close();", # a factory constructor
+ ],
+)
+def test_dart_local_takes_the_type_its_call_returns(tmp_path: Path, body: str) -> None:
+ assert {e[1] for e in _dart_edges(tmp_path, body) if e[0] == 2} & _DART_OUTER
+
+
+ "body",
+ [
+ "final a = r.later();\na.save();", # an unawaited Future is not an Item
+ "var a = r.item(1);\na.close();", # the returned class lacks the method
+ "final a = r.item(1)\n .other();\na.save();", # the call is not the whole value
+ ],
+)
+def test_dart_local_without_a_typed_call_binds_nothing(tmp_path: Path, body: str) -> None:
+ assert not {e for e in _dart_edges(tmp_path, body) if e[1] in _DART_OUTER}
+
+
+def test_kotlin_signature_carries_the_declared_return_type(tmp_path: Path) -> None:
+ source = "class Repo\nfun make(x: Int): Repo? = null\nfun none() = Repo()\n"
+ parsed = _parse(tmp_path, "a.kt", "kotlin", source)
+ signatures = {s.name: s.signature for s in parsed["a.kt"].symbols}
+
+ assert signatures["make"] == "function make(x: Int) -> Repo?"
+ assert signatures["none"] == "function none()"
+
+
+_KOTLIN_LOCALS = (
+ "class Repo {\n fun load() {}\n}\n"
+ "class Other {\n fun load() {}\n}\n"
+ "fun makeRepo(): Repo = Repo()\n"
+ "fun mk(a: Int): Repo = Repo()\nfun mk(a: String): Other = Other()\n"
+ "fun <T> gen(): T = TODO()\n"
+ "object Factory {\n fun other(): Other = Other()\n}\n"
+ "class Use {\n fun go() {\n{body}\n }\n}\n"
+)
+_SWIFT_LOCALS = (
+ "class Repo {\n func load() {}\n}\n"
+ "class Other {\n func load() {}\n}\n"
+ "func makeRepo() throws -> Repo { return Repo() }\n"
+ "func mk(a: Int) -> Repo { return Repo() }\nfunc mk(a: String) -> Other { return Other() }\n"
+ "func fetch() async -> Repo { return Repo() }\n"
+ "enum Factory {\n static func other() async -> Other { return Other() }\n}\n"
+ "class Use {\n func go() async throws {\n{body}\n }\n}\n"
+)
+
+
+_LOCALS = {"kotlin": ("a.kt", _KOTLIN_LOCALS), "swift": ("a.swift", _SWIFT_LOCALS)}
+
+
+def _last_line_callees(tmp_path: Path, language: str, body: str) -> set[str]:
+ """Callees on the last line of *body*, held in ``Use.go``."""
+ path, source = _LOCALS[language]
+ text = source.replace("{body}", body)
+ parsed = _parse(tmp_path, path, language, text)
+ line = len(text.split("\n")) - 3
+ resolver = CallResolver(parsed, {path: set()})
+ return {
+ rc.callee_id
+ for rc in resolver.resolve_file(path, parsed[path].calls)
+ if rc.line == line
+ }
+
+
+ ("language", "body", "callee"),
+ [
+ ("kotlin", "val r = makeRepo()\nr.load()", "a.kt::Repo::load"),
+ ("kotlin", "val r = Factory.other()\nr.load()", "a.kt::Other::load"),
+ ("swift", "let r = try makeRepo()\nr.load()", "a.swift::Repo::load"),
+ ("swift", "let r = await Factory.other()\nr.load()", "a.swift::Other::load"),
+ ("swift", "let r = try? makeRepo()\nr?.load()", "a.swift::Repo::load"),
+ ("swift", "async let r = fetch()\nawait r.load()", "a.swift::Repo::load"),
+ ],
+)
+def test_kotlin_and_swift_local_takes_the_type_its_call_returns(
+ tmp_path: Path, language: str, body: str, callee: str
+) -> None:
+ assert _last_line_callees(tmp_path, language, body) == {callee}
+
+
+ ("language", "body"),
+ [
+ ("kotlin", "val r = makeRepo()\n .let { Other() }"),
+ ("kotlin", "val r = makeRepo()\n ?.let { Other() }"),
+ ("swift", "var r = try makeRepo()\n .other()"),
+ ("kotlin", "val r = makeRepo()\n ?: Other()"),
+ ("kotlin", "val r = makeRepo()\n as Other"),
+ ("swift", "let r = try makeRepo()\n as! Other"),
+ ("kotlin", "val r = mk(1)"), # overloads of one arity that return different types
+ ("swift", "let r = mk(a: 1)"),
+ ("kotlin", "val r = gen()"), # a type parameter is no class
+ ],
+)
+def test_kotlin_and_swift_local_without_a_typed_call_binds_nothing(
+ tmp_path: Path, language: str, body: str
+) -> None:
+ callees = _last_line_callees(tmp_path, language, body + "\nr.load()")
+
+ assert not {callee for callee in callees if callee.endswith("::load")}
+
+
[email protected]("imported", ["", "import java.net.Socket\n"])
+def test_kotlin_return_type_an_external_import_names_is_not_the_repo_class(
+ tmp_path: Path, imported: str
+) -> None:
+ """``Socket`` in a file importing ``java.net.Socket`` is not the repo's ``Socket``."""
+ source = (
+ f"package okio\n\n{imported}\ninterface Socket {{\n fun source()\n}}\n"
+ "fun socket(): Socket = TODO()\n\n"
+ "class Use {\n fun go() {\n val s = socket()\n s.source()\n }\n}\n"
+ )
+ parsed = _parse(tmp_path, "Use.kt", "kotlin", source)
+ resolver = CallResolver(parsed, {"Use.kt": set()})
+ callees = {rc.callee_id for rc in resolver.resolve_file("Use.kt", parsed["Use.kt"].calls)}
+
+ assert ("Use.kt::Socket::source" in callees) == (not imported)
+
diff --git a/tests/unit/ingestion/test_return_types.py b/tests/unit/ingestion/test_return_types.py
index 0b34dc2ad..f0f714b3d 100644
--- a/tests/unit/ingestion/test_return_types.py
+++ b/tests/unit/ingestion/test_return_types.py
@@ -15,6 +15,22 @@ def test_declared_return_type_reads_stored_signature() -> None:
assert declared_return_type("factory()") is None
+ ("signature", "expected"),
+ [
+ ("function f(cb: () -> Foo) -> Bar", "Bar"), # Kotlin / Swift function-typed parameter
+ ("function f(cb: () -> Foo)", None),
+ ("fn f(cb: impl Fn() -> Foo) -> Bar", "Bar"),
+ ("func (r *T) Name(a int) -> int", "int"), # a go receiver list comes first
+ ("function make -> Repo", "Repo"), # a Swift signature with no list
+ ],
+)
+def test_declared_return_type_follows_the_parameter_list(
+ signature: str, expected: str | None
+) -> None:
+ assert declared_return_type(signature) == expected
+
+
@pytest.mark.parametrize(
("signature", "expected"),
[