Skip to content

Kotlin imports of top-level functions and object members never resolve (import recall 62%) #3596

Closed

Description

@squid-protocol

Problem

A Kotlin import names a declaration by package + name, and the file it lives in doesn't have to be named after it. The engine resolves the last segment as a file stem, so two common shapes never link:

  • Top-level functions and properties: import com.squareup.kotlinpoet.asClassName lives in a file with another name (e.g. ClassNames.kt).
  • Object/companion members: import com.squareup.kotlinpoet.metadata.classinspectors.ClassInspectorUtil.JAVA_DEPRECATED. The member retry (imports_may_name_member) is Java-only.

Measured

tests/tools/import_graph_accuracy.py kotlin (square/kotlinpoet, added in #3594): precision 100%, recall 62.1%, 143 missed imports. For example, ElementsClassInspector.kt → metadata/KotlinPoetMetadata.kt and classinspectors/ClassInspectorUtil.kt.

Fix direction

  1. Set imports_may_name_member: True for Kotlin. Same retry as Java: drop up to 3 trailing segments. This handles Util.X and nested classes.
  2. For a top-level function or property, use what the scan already knows. Each parsed file has its function names, and a Kotlin file's directory usually mirrors its package. Resolve a.b.name to the file under a …/a/b/ directory that declares a function named name; several candidates draw no edge (Dependency Attribution Error duplicate filenames #261).

Check both with import_graph_accuracy.py kotlin --samples 10.

Activity

  1. added
    bug
    core-engine
    on Sep 25, 2026
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

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions