Sealed interface not supported
Opened this issue · 1 comments
GrahamBorland commented
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 commented
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).