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.

feat(graph): capture three call receivers a bare-name match was guessing (#1686)

Raghav Chamadiyac70dbc995f8f
diff --git a/packages/core/src/repowise/core/ingestion/call_resolver.py b/packages/core/src/repowise/core/ingestion/call_resolver.py
index fea5cc1a2..1cec8e4f5 100644
--- a/packages/core/src/repowise/core/ingestion/call_resolver.py
+++ b/packages/core/src/repowise/core/ingestion/call_resolver.py
@@ -951,6 +951,17 @@ class CallResolver:
if method_name not in self._global_symbols:
return None
+ # The caller's own file first. Every other tier is ordered narrow-first
+ # and this one was not: the language strategies below run before
+ # ``_receiver_pair_match``, so ``_resolve_jvm_receiver_same_package``
+ # claimed ``new Builder<>(...).build()`` for any same-package class of
+ # that name — a test-source-set one included — while the caller's own
+ # file declared a private inner ``Builder`` on the same page. The
+ # narrowest scope that can answer is the one the call actually means.
+ own_file = self._file_methods.get(file_path, {}).get((receiver_name, method_name))
+ if own_file is not None and own_file != caller_id:
+ return ResolvedCall(caller_id, own_file, 0.93, call.line, "receiver_same_file")
+
# A language may reach a receiver no import statement mentions: a Go
# package alias spanning several files, a JVM class in the same package.
for strategy in self._strategies_for(file_path).member:
diff --git a/packages/core/src/repowise/core/ingestion/queries/java.scm b/packages/core/src/repowise/core/ingestion/queries/java.scm
index 5e1cf79d0..0f1191b68 100644
--- a/packages/core/src/repowise/core/ingestion/queries/java.scm
+++ b/packages/core/src/repowise/core/ingestion/queries/java.scm
@@ -103,6 +103,51 @@
arguments: (argument_list) @call.arguments
) @call.site
+; Self-dispatch: this.method(args). The pattern above claims ``this.field.m()``
+; and the bare pattern claims everything, so without this a plain ``this.m()``
+; arrives receiver-less and is read as an implicit receiver — which resolves by
+; bare name through the flat same-file index instead of against the caller's own
+; class.
+;
+; ``super`` is deliberately NOT in this alternation, and the reason is narrower
+; than "super is unsafe". Capturing any receiver makes the bare twin
+; member-shaped, which suppresses ``_enclosing_class_method``'s recursion
+; refusal — the guard that emits no edge when the flat index hands a method its
+; own name. The call then falls through to the same-file tier, and THAT is only
+; wrong when the file declares the target name on MORE THAN ONE class: the flat
+; index is last-wins, so it answers with a sibling's method.
+;
+; So the hazard is a property of the file, not of the keyword, and ``this`` is
+; not immune to it — it is merely far less likely to sit in such a file.
+; Measured on caffeine: ``super`` costs 2 wrong edges (``DelegationBenchmark``
+; declares ``get`` on both ``InheritMap`` and ``DelegateMap``), while all 3
+; self-recursive ``this.add()`` sites are safe because ``IntegerSum`` is the only
+; class in its file declaring ``add`` and the ``callee != caller`` guard then
+; refuses. ``super`` is excluded because its population sits in override-heavy
+; files where sibling classes share names; that costs recall only, which is the
+; right direction to err in. If a future session adds ``super``, the fix it
+; needs first is a same-file index keyed by class, not a wider capture.
+(method_invocation
+ object: (this) @call.receiver
+ name: (identifier) @call.target
+ arguments: (argument_list) @call.arguments
+) @call.site
+
+; Fluent construction: new Foo().bar(args). The receiver type is written at the
+; call site, so this lands on the receiver-names-a-class tier — which only binds
+; when that class declares the method — instead of the bare-name pool. Same
+; shape as csharp.scm's ``new Builder().Method()`` (#1680).
+(method_invocation
+ object: (object_creation_expression
+ type: [
+ (type_identifier) @call.receiver
+ (generic_type (type_identifier) @call.receiver)
+ ]
+ )
+ name: (identifier) @call.target
+ arguments: (argument_list) @call.arguments
+) @call.site
+
; Chained method call: obj.method1().method2(args)
(method_invocation
object: (method_invocation)
diff --git a/packages/core/src/repowise/core/ingestion/queries/ruby.scm b/packages/core/src/repowise/core/ingestion/queries/ruby.scm
index b02963912..bc2d41f25 100644
--- a/packages/core/src/repowise/core/ingestion/queries/ruby.scm
+++ b/packages/core/src/repowise/core/ingestion/queries/ruby.scm
@@ -55,3 +55,20 @@
receiver: (identifier) @call.receiver
method: (identifier) @call.target
) @call.site
+
+; Namespaced class/module method call: Foo::Bar.baz(args).
+;
+; The pattern above constrains the receiver to a bare ``constant``, and the
+; simple-call pattern constrains nothing, so a namespaced receiver arrives with
+; no receiver at all and resolves by bare name.
+;
+; The TRAILING constant is captured rather than the whole path, because that is
+; the name the class index holds — so no receiver normalizer is needed (contrast
+; ``_normalize_php_receiver``). The collapse is lossy and its cost is known and
+; stated: ``A::Foo`` and ``B::Foo`` both offer ``Foo``, so a short class name
+; reused across sibling gems in one repo can bind to the wrong namespace. Fixing
+; that needs Ruby module nesting in the index, which this does not build.
+(call
+ receiver: (scope_resolution name: (constant) @call.receiver)
+ method: (identifier) @call.target
+) @call.site