Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sealed interface not supported #38

Open
GrahamBorland opened this issue May 1, 2023 · 1 comment
Open

Sealed interface not supported #38

GrahamBorland opened this issue May 1, 2023 · 1 comment

Comments

@GrahamBorland
Copy link
Contributor

package ynab.slik.data.repository

import deezer.kustomexport.KustomExport

@KustomExport
sealed interface InvalidDataError

@KustomExport
class InvalidNumber(val number: Int) : InvalidDataError

@KustomExport
class InvalidName(val name: String) : InvalidDataError

This fails to compile:

> Task :lib:compileKotlinJs FAILED
e: file:///Users/graham/Work/YNAB/slik/lib/build/generated/ksp/js/jsMain/kotlin/ynab/slik/data/repository/js/InvalidDataError.kt:11:5 Inheritance of sealed classes or interfaces from different module is prohibited
e: file:///Users/graham/Work/YNAB/slik/lib/build/generated/ksp/js/jsMain/kotlin/ynab/slik/data/repository/js/InvalidDataError.kt:11:5 Inheritor of sealed class or interface declared in package ynab.slik.data.repository.js but it must be in package ynab.slik.data.repository where base class is declared

FAILURE: Build failed with an exception.

If I change the sealed interface to sealed class, then it works.

package ynab.slik.data.repository

import deezer.kustomexport.KustomExport

@KustomExport
sealed class InvalidDataError

@KustomExport
class InvalidNumber(val number: Int) : InvalidDataError()

@KustomExport
class InvalidName(val name: String) : InvalidDataError()
@GrahamBorland
Copy link
Contributor Author

The generated wrapper for the sealed interface looks like this:

package ynab.slik.`data`.repository.js

import kotlin.js.JsExport
import ynab.slik.`data`.repository.InvalidDataError as CommonInvalidDataError

@JsExport
public external interface InvalidDataError

private class ImportedInvalidDataError(
    internal val exported: InvalidDataError,
) : CommonInvalidDataError

private class ExportedInvalidDataError(
    internal val common: CommonInvalidDataError,
) : InvalidDataError

public fun CommonInvalidDataError.exportInvalidDataError(): InvalidDataError =
        (this as? ImportedInvalidDataError)?.exported ?: ExportedInvalidDataError(this)

public fun InvalidDataError.importInvalidDataError(): CommonInvalidDataError =
        (this as? ExportedInvalidDataError)?.common ?: ImportedInvalidDataError(this)

It doesn't compile because ImportedInvalidDataError is trying to implement CommonInvalidDataError which is the original sealed interface, and it's in a different package (not the .js package).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant