Skip to content

Kotlin: generated data-class copy/componentN collide with explicit overloads #1062

Open

Description

@christoph-sg

Example

data class Generated(val x: Int) {
    fun copy(text: String) = Generated(text.length)
    fun component1(dummy: Int) = dummy
}
fun use(p: Generated) {
    p.copy()
    p.copy("one")
    p.component1()
    p.component1(3)
}

Expected: The generated and explicit overloads get distinct symbols, and each call references its definition.

Actual: Both copy definitions are emitted as Generated#copy().. The call p.copy() references Generated#copy(+1)., which has no definition. component1 has the same problem.

Cause: Generated members are defined through memberMethodSymbol (KotlinAnalysisIndexer.kt, SymbolsCache.kt), which always uses the () disambiguator. References go through externalMethodDisambiguator.

Fix: Derive definitions from the actual generated callable symbols, using the same disambiguation as references. The existing handling of equals/hashCode/toString is a pattern to follow.

Activity

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