Skip to content

Scala: receiver.method(...) calls are bound to an arbitrary same-named symbol by short name (weak-member suppression not applied) #2155

Open

Description

@htarnacki

Version

Built from source, main @ 9b24332 (v0.10.8-181)

Platform / Install channel / Binary variant

Linux (x64) / Built from source / standard

What happened, and what did you expect?

Scala has no LSP resolver, so a member call such as map.get(key), _.register(x) or builder.build() falls through to the registry and is bound to an arbitrary project-wide get / register / build by short name. On a project with a few hundred Scala files this produces many confident-looking but wrong CALLS edges (e.g. every .get on an Option/Map pointing at some unrelated def get).

Python and the JS/TS family already have a receiver-aware guard for exactly this case (weak short-name matches on receiver.method(...) are suppressed unless an import-map or same-module match exists). Scala calls are not marked as member calls, so the guard never applies.

Expected: Scala receiver.method(...) calls are flagged as member calls and go through the same weak-member suppression; import-map and same-module matches stay eligible.

Same class of problem as #1906 (Go selector calls) and #2053 (Rust std-typed receivers), for Scala.

Reproduction

  1. Dummy snippet:
package a
class Registry { def register(x: Int): Unit = () }
package b
object Job {
  def run(items: Map[String, Int]): Unit = {
    items.get("k")            // scala.collection — no target in the project
    items.foreach(_.register)  // not a.Registry
  }
}
  1. Command: codebase-memory-mcp cli trace_path '{"project":"repro","function_name":"register","direction":"inbound"}'

  2. Result: b.Job.run → a.Registry.register (strategy short_name, low confidence).
    Expected: no edge.

A second symptom fixed alongside: try_field_type_hint picks between identically named owners in different packages by iteration order; when the hint is ambiguous it should leave the low-confidence registry result so the guard can suppress it deterministically (sequential and parallel indexing currently may disagree).

Proposed fix

Mark Scala receiver.method(...) as is_method, enable the existing receiver-aware weak-member suppression for Scala, and make the ambiguous field-type hint fail closed. One commit with pipeline tests (sequential + parallel). Stacked on #2153 / #2154 (shared fixtures); branch:
https://github.com/htarnacki/codebase-memory-mcp/tree/feat/scala-receiver-resolution (third commit).

Confirmations

  • I searched existing issues and this is not a duplicate.
  • My reproduction uses shareable code (a dummy snippet), not proprietary code.

Activity

  1. added
    bugSomething isn't working
    priority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.
    on Sep 19, 2026
  2. DeusData commented on Sep 25, 2026

    @DeusData
    Owner

    Thank you @htarnacki. This was a clear, well-scoped report, and your repro snippet showed the exact shape. You were right that the Python/JS receiver guard never applied to Scala, because Scala calls were never flagged as member calls in the first place.

    Since you already have a fix on your branch, we'd love for you to carry this one. To help, here's what we found while measuring the same approach locally, in case it's useful for your PR:

    • Mechanism: flag recv.m(...) (including curried recv.m(a)(b)) and named infix recv m arg as member calls when the receiver is a value, and add Scala to the weak-member suppression in both resolvers (pass_calls.c and pass_parallel.c, kept identical). Leave this/super, upper-case object/type paths (Utils.helper, Bijections.finagle.m) and upper-case applies through a package path (http.param.Streaming(x)) unflagged; the registry's receiver-chain check already covers those.
    • Locality exemption that paid off: keeping unique_name / field_type_hint matches whose target is in the caller's own file restored true edges (and keeps the existing mkc_c7_scala_inherited_method pin green); suffix_match stays suppressed.
    • Numbers on twitter/finagle @ ca472deb (1,898 .scala files): CALLS 28,128 → 17,037. Seeded hand review of the dropped edges: roughly 75% were false (math.max → a project max, items.get → ToggleMap.get, str.getBytes → Row.getBytes), ~25% were real calls (client.zRem, stack.contains → Stack.contains) that only a type-aware resolver could keep. A possible refinement is to keep Scala unique_name edges unless the name is a Scala/Java stdlib member (modelled on the Python builtin-member list); in our sample that kept ~10 true / 5 false per 25.
    • Tests we found useful: an extraction test for the flag shapes in both directions, sequential + parallel pipeline repros (the parallel one needs 50+ files to take the parallel path), and a registry unit test for the exemption.

    Your point about the ambiguous field-type hint is noted as a separate follow-up, because that heuristic is shared by every language (and it currently only exists in the parallel resolver). Once your PR is up we'll review it promptly. Thanks again for the careful write-up!

  3. added 4 commits that reference this issue on Sep 27, 2026
    06ef2f6
    4a0f966
    a5652ee
    bff50fe
  4. DeusData commented on Oct 19, 2026

    @DeusData
    Owner

    Thank you again for the Scala receiver cases. I have no new verified status beyond the September 25 guidance. The weak-member suppression and shared ambiguous field-hint behavior remain distinct review concerns.

  5. DeusData commented on Oct 25, 2026

    @DeusData
    Owner

    Thank you again for the receiver examples and proposed suppression work. The weak-member policy and shared ambiguous field-hint behavior still need maintainer follow-up. Sorry for the delay; I’ll follow up soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparsing/qualityGraph extraction bugs, false positives, missing edgespriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions