Skip to content

Kotlin: phantom <init>() for classes with only secondary constructors #1063

Open

Description

@christoph-sg

Example

class Secondary {
    constructor(s: String)
    constructor(i: Int)
}

Expected: Two constructor definitions with the signatures (s: String) and (i: Int), and no no-arg constructor.

Actual: A phantom Secondary#<init>(). definition is emitted at the class name. The String constructor gets the same symbol, and the phantom's no-arg signature wins.

Cause: KotlinAnalysisIndexer.kt synthesizes an implicit constructor whenever primaryConstructor == null, without checking for secondary constructors.

Fix: Skip the implicit constructor when secondary constructors exist, and add a snapshot test.

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