Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Support Enum Companion #41

Description

@atollk
@KustomExport
enum class E {
    EnumValue;

    companion object {
        val static = 1
    }
}

generates

@JsExport
public class E internal constructor(
    internal val common: CommonE,
) {
    public val name: String = common.name
}

@JsExport
public fun E_values(): Array<E> = arrayOf(E_EnumValue, E_Companion)

@JsExport
public fun E_valueOf(name: String): E? {
    if (name == E_EnumValue.name)
        return E_EnumValue

    if (name == E_Companion.name)
        return E_Companion

    return null
}

public fun E.importE(): CommonE = common

public fun CommonE.exportE(): E = E_valueOf(this.name)!!

@JsExport
public val E_EnumValue: E = E(CommonE.EnumValue)

@JsExport
public val E_Companion: E = E(CommonE.Companion)

which is an error because Type mismatch: inferred type is E.Companion but E was expected in the last line. The incorrect assumption is made that the companion object is an enum value.

Workaround: Use JsExport instead of KustomExport

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

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions