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(ingestion): resolve Dart call chains of three or more links (#3794)

Ensard82adbe7bda0
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.py
index 6006297ff..1676da986 100644
--- a/packages/core/src/repowise/core/ingestion/call_resolver.py
+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py
@@ -1774,11 +1774,11 @@ class CallResolver(LanguageStrategiesMixin, ReceiverTypingMixin):
A receiver records one hop, but the parser keeps every link of a chain
as its own site on the chain's first line, so the hop below is read
- off the site *inner* names. C#, Go and Java read it, so a builder chain
+ off the site *inner* names. C#, Dart, Go and Java read it, so a builder chain
types each link from the one before; elsewhere an inner call is still
typed as if nothing were chained under it.
"""
- if language not in ("csharp", "go", "java"):
+ if language not in ("csharp", "dart", "go", "java"):
return None
sites = self._chained_sites.get(file_path)
if sites is None:
diff --git a/packages/core/src/repowise/core/ingestion/parser.py b/packages/core/src/repowise/core/ingestion/parser.py
index d9e25a4b9..933b4a769 100644
--- a/packages/core/src/repowise/core/ingestion/parser.py
+++ b/packages/core/src/repowise/core/ingestion/parser.py
@@ -263,7 +263,11 @@ def _dart_call_receiver(name: Node, src: str) -> CallReceiver | None:
"""
if name.parent.type == "unconditional_assignable_selector":
head = name.parent.parent
- receiver: str | None = _node_text(head.prev_named_sibling, src).strip()
+ prev = head.prev_named_sibling
+ if prev is not None and any(c.type == "argument_part" for c in prev.named_children):
+ receiver = None
+ else:
+ receiver = _node_text(prev, src).strip() if prev is not None else None
else:
head, receiver = name, None
return CallReceiver(
diff --git a/packages/core/src/repowise/core/ingestion/queries/dart.scm b/packages/core/src/repowise/core/ingestion/queries/dart.scm
index f6425cc05..a8d1bb70f 100644
--- a/packages/core/src/repowise/core/ingestion/queries/dart.scm
+++ b/packages/core/src/repowise/core/ingestion/queries/dart.scm
@@ -184,3 +184,34 @@
)
) @call.site
)
+
+; Chained on a call anywhere in the run: ...a(args).b(args).c(args).
+(_
+ (selector
+ (argument_part)
+ )
+ .
+ (selector
+ (unconditional_assignable_selector
+ (identifier) @call.receiver_call
+ )
+ )
+ .
+ (selector
+ (argument_part)
+ )
+ .
+ (selector
+ [
+ (unconditional_assignable_selector (identifier) @call.target)
+ (conditional_assignable_selector (identifier) @call.target)
+ ]
+ )
+ .
+ (selector
+ (argument_part
+ (arguments) @call.arguments
+ )
+ ) @call.site
+)
+
diff --git a/tests/unit/ingestion/test_return_type_chain_resolution.py b/tests/unit/ingestion/test_return_type_chain_resolution.py
index bc07a246c..1412645a6 100644
--- a/tests/unit/ingestion/test_return_type_chain_resolution.py
+++ b/tests/unit/ingestion/test_return_type_chain_resolution.py
@@ -742,6 +742,7 @@ _DART_REPO = (
" factory Repo.copy() {\n return Repo.other();\n }\n"
" static Repo parse(String text) => Repo();\n"
" Item item(int i) => Item();\n"
+ " Repo self() => this;\n"
" Item? maybe() => null;\n"
" Future<Item> later() async => Item();\n"
" void close() {}\n"
@@ -832,6 +833,8 @@ def test_dart_chain_binds_the_method_of_the_inner_return_type(
[
"r.later().save();", # a Future is not the class it wraps
"r.item(1).close();", # the returned class lacks the method
+ "r.self().later().save();", # a Future mid-chain binds nothing
+ "r.self().item(1).close();", # class lacks method on third link
"unknown().save();", # nothing types the inner call
"r..item(1)..close();", # a cascade is not a chain
"r?.item(1).save();", # a null-aware first link is not captured
@@ -841,12 +844,36 @@ def test_dart_chain_without_a_typed_method_binds_no_bare_name(tmp_path: Path, bo
assert {e for e in _dart_edges(tmp_path, body) if e[1] in _DART_OUTER} == set()
+def test_dart_third_link_of_a_chain_binds_by_return_type(tmp_path: Path) -> None:
+ edges = _dart_edges(tmp_path, "r.self().self().close();")
+
+ assert (1, "repo.dart::Repo::close", "return_type_import") in edges
+
+
+def test_dart_third_link_on_constructor_binds_by_return_type(tmp_path: Path) -> None:
+ edges = _dart_edges(tmp_path, "Repo().self().self().close();")
+
+ assert (1, "repo.dart::Repo::close", "return_type_import") in edges
+
+
+def test_dart_third_link_type_changes_mid_chain(tmp_path: Path) -> None:
+ edges = _dart_edges(tmp_path, "r.self().item(1).save();")
+
+ assert (1, "repo.dart::Item::save", "return_type_import") in edges
+
+
+def test_dart_three_links_parser_yields_three_sites(tmp_path: Path) -> None:
+ parsed = _parse(tmp_path, "app.dart", "dart", "void run(Repo r) { r.self().self().close(); }")
+ assert len(parsed["app.dart"].calls) == 3
+
+
def test_dart_third_link_of_a_chain_is_dropped_not_misbound(tmp_path: Path) -> None:
edges = _dart_edges(tmp_path, "r.item(1).save().close();")
assert {e[1] for e in edges if e[1] in _DART_OUTER} == {"repo.dart::Item::save"}
+
def test_dart_constructor_initializers_are_not_calls(tmp_path: Path) -> None:
source = (
"class A {\n A.named(int x);\n}\n"