Skip to content

Kotlin: object/class-qualified member calls are dropped across a repo boundary, not parked (#3152) #3388

Closed

Description

@xiongjianxu

What happens

A Kotlin object/class-qualified member call — Receiver.method(), a capitalized receiver
that is an object singleton or a class/companion member — resolves inside a single build
(#1698, shipped 0.9.64) but is dropped, not parked when the receiver's declaration lives
in another repository. Nothing survives into graph.json, so the cross-repo merge has
nothing to finish.

// Registry.kt   (repo lib/)
object Registry { fun register() {} }

// App.kt        (repo app/)
class App { fun run() { Registry.register() } }

Build each repo and merge-graphs app/graphify-out/graph.json lib/graphify-out/graph.json:
no App.run -> Registry.register edge, and neither input graph.json records the attempt.
The same two files in one build do produce the edge — so the receiver typing is not what is
missing; the park is. This is the Kotlin instance of #3152; Java, C++, C#, Swift and ObjC
already park.

v8 现状 → 本 PR 的净增 (verified @6478eb71, 0.9.80)

  • _resolve_kotlin_member_calls (graphify/extract.py) resolves the object/class-qualified
    shape across files, but its no-candidate path drops the call; it parks nothing.
  • kotlin is absent from _LANG_SUFFIXES (cross_repo_calls.py, which lists only
    cpp/csharp/java/swift), so even a parked Kotlin call could not be matched after merge.
  • The paired PR adds the park arm for the object-receiver case (declared nowhere in the
    build → _park_unresolved_member_call(..., "kotlin", ...), builtin globals skipped) plus
    the kotlin suffix entry, so merge-graphs / global add bind it to the single
    declaration another repo owns.

Expected

  • Registry.register() on an object/class-qualified receiver declared in another repo is
    parked at build time and bound to its single out-of-repo declaration at merge time
    (INFERRED, context cross_repo), matching the Java/C++/C#/Swift/ObjC equivalents.
  • A receiver name matching 2+ declared types, or a callee matching 2+ methods of the matched
    type, stays unresolved (the existing god-node guard).

Out of scope

The lowercase instance-receiver shape
(class App(private val greeter: Greeter) { fun run() { greeter.greet() } }) is a separate
gap: the engine captures no member_receiver for it today, so neither v8 nor this PR
resolves it. That is tracked separately; this issue and its PR are strictly the
object/class-qualified cross-repo park.

A paired PR follows.

Activity

  1. xiongjianxu commented on Sep 20, 2026

    @xiongjianxu
    ContributorAuthor

    Update after 0.9.64: the in-repo half of this — cross-file Receiver.method() resolution — landed on v8 as _resolve_kotlin_member_calls (#1698). That resolver binds the call only when the object/class is declared in the same build, so the cross-repo gap this issue describes remains: a call into another repo is still dropped with the receiver name in hand, and nothing reaches graph.json.

    #3389 is rebased onto the landed resolver and now contributes only that missing piece — parking the call at the "declared nowhere here" bail-out so merge-graphs / global add finishes the edge, the same mechanism Java/C++/C#/Swift already use (gated on .kt/.kts).

  2. xiongjianxu commented on Sep 22, 2026

    @xiongjianxu
    ContributorAuthor

    Self-contained, runnable reproduction (driven only by graphify on PYTHONPATH, so the same script runs against pristine v8 and against the PR branch). Two single-file repos are built — app calls a method on a type declared only in lib — then merge-graphs is run; the parked entry and the cross-repo calls edge are printed.

    # repro_kotlin.py  —  python repro_kotlin.py   (exit 0 = fixed, 1 = bug present)
    import json, subprocess, sys, tempfile
    from pathlib import Path
    from graphify.extract import extract
    
    FILES = {
        "app/App.kt": 'fun run() { Greeter.greet() }\n',
        "lib/Greeter.kt": 'object Greeter { fun greet() {} }\n',
    }
    
    def _extract(root):
        files = sorted(f for e in ("*.php", "*.ts", "*.kt", "*.m", "*.h")
                       for f in root.rglob(e))
        return extract(files, cache_root=root / "graphify-out")
    
    def _write(p, res):
        p.parent.mkdir(parents=True, exist_ok=True)
        p.write_text(json.dumps({"directed": False, "multigraph": False, "graph": {},
                                 "nodes": res["nodes"], "links": res["edges"]}))
    
    def main():
        with tempfile.TemporaryDirectory() as d:
            tmp = Path(d)
            for rel, body in FILES.items():
                p = tmp / rel
                p.parent.mkdir(parents=True, exist_ok=True)
                p.write_text(body)
            ag = tmp / "app/graphify-out/graph.json"
            bg = tmp / "lib/graphify-out/graph.json"
            _write(ag, _extract(tmp / "app"))
            _write(bg, _extract(tmp / "lib"))
            parked = [e for n in json.loads(ag.read_text())["nodes"]
                      if isinstance(n.get("metadata"), dict)
                      for e in n["metadata"].get("unresolved_calls", [])]
            print("parked:", parked or "(none)")
            out = tmp / "merged.json"
            subprocess.run([sys.executable, "-m", "graphify", "merge-graphs",
                            str(ag), str(bg), "--out", str(out)], cwd=tmp, check=True)
            xr = [e for e in json.loads(out.read_text())["links"]
                  if e.get("relation") == "calls" and e.get("context") == "cross_repo"]
            print("cross_repo calls:",
                  [(e["source"], e["target"]) for e in xr] or "(none)")
            return 0 if xr else 1
    
    sys.exit(main())

    On pristine v8 (20a20d3):

    parked: (none)
    cross_repo calls: (none)          # exit 1
    

    The receiver's type is declared only in the other repo, so nothing is parked and merge-graphs has nothing to finish — the call edge is lost across the boundary, exactly as described.

    With PR #3389:

    parked: [{"callee": "greet", "receiver_type": "Greeter", "lang": "kotlin", "line": "L1"}]
    cross_repo calls: [('app::…app_run', 'lib::…greeter_greet')]   # exit 0
    

    The call is parked by name (no node ids, per the #3152 contract) and finished by link_cross_repo_member_calls as an INFERRED / context=cross_repo edge when the type resolves to exactly one declaration in another repo.

    PR #3389 cherry-picks clean onto the current v8 tip 20a20d3 (git merge-tree reports no conflicts; PR is MERGEABLE / CLEAN).

  3. changed the title [-]Kotlin: member calls on a typed receiver produce no edge across files, and nothing across repos[/-] [+]Kotlin: object/class-qualified member calls are dropped across a repo boundary, not parked (#3152)[/+] on Oct 8, 2026
  4. safishamsi commented on Oct 13, 2026

    @safishamsi
    Member

    Fixed in v0.9.89 (graphifyy 0.9.89 on PyPI) via #3389.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions