eygraber
07/18/2022, 6:38 PMpublic sealed class Foo
public expect class Bar : Foo
When I define the actual class in the same package and module in a platform source set (e.g. jvmMain
):
public actual class Bar : Foo()
I get an error that says:
Inheritance of sealed classes or interfaces from different module is prohibited
Tim Schraepen
07/18/2022, 7:02 PMTim Schraepen
07/18/2022, 7:12 PMInheritor of sealed class or interface declared in package bar
but it must be in package foo where base class is declared
Landry Norris
07/18/2022, 7:14 PMeygraber
07/18/2022, 7:16 PMSort of feels like it beats the purpose of sealed interfaces no?I'm not sure how that would beat the purpose of a sealed interface?
What is it that you're trying to do?Essentially, I need platform specific behavior in one of the subclasses of a sealed class.
The rest of the compilation errorWhat I posted is the entirety of the error that I can see
eygraber
07/18/2022, 7:17 PMI personally would write a separate expect PlatformBar and make bar wrap that.I specifically need to not wrap it for this use case
Tim Schraepen
07/18/2022, 7:18 PMLandry Norris
07/18/2022, 7:18 PMeygraber
07/18/2022, 7:19 PM```Inheritor of sealed class or interface declared in package bar
but it must be in package foo where base class is declared```In any case, it is declared in the same package and module, just a different source set
Tim Schraepen
07/18/2022, 7:20 PMeygraber
07/18/2022, 7:20 PMTim Schraepen
07/18/2022, 7:20 PMLandry Norris
07/18/2022, 7:21 PMeygraber
07/18/2022, 7:21 PMTim Schraepen
07/18/2022, 7:22 PMTim Schraepen
07/18/2022, 7:24 PMLandry Norris
07/18/2022, 7:25 PMeygraber
07/18/2022, 7:26 PMLandry Norris
07/18/2022, 7:28 PMexpect class PlatformBar(param: Type) {
fun foo()
val x: Int
}
class Bar(param: Type): Foo() {
private val platform = PlatformBar(param)
fun foo() = platform.foo()
val x get() = platform.x
}
Should be indistinguishable from an external perspective. The only issue would be in the case of performance, no?Landry Norris
07/18/2022, 7:29 PMthis
into the PlatformBar constructoreygraber
07/18/2022, 7:49 PMBar
is being used a sealed class itself that just has objects that extend it, and those objects are what differ based on platformTim Schraepen
07/18/2022, 7:50 PMLandry Norris
07/18/2022, 7:51 PMeygraber
07/18/2022, 7:55 PMsealed class Typography {
class Deferred(val lookup: Map<String, Typography>) : Typography()
}
expect sealed class PlatformTypography : Typography {
object Title1 : PlatformTypography
object Title2 : PlatformTypography
object Title3 : PlatformTypography
}
Landry Norris
07/18/2022, 7:58 PMactual sealed class PlatformTypography: Typography {
actual object Title1: PlatformTypography() {...}
actual object Title2: PlatformTypography() {...}
actual object Title3: PlatformTypography() {...}
}
eygraber
07/18/2022, 8:02 PMpublic actual sealed class PlatformTypography : Typography() {
public abstract val weight: FontWeight
public actual object Title1 : PlatformTypography() {
override val weight: FontWeight = FontWeight.Regular
}
...
}
And another looks like:
public actual sealed class PlatformTypography(
public val weight: FontWeight,
public val size: Px
) : Typography() {
public abstract val weight: FontWeight
public actual object Title1 : PlatformTypography(
weight = FontWeight.Regular,
size = 34.px
)
...
}
Landry Norris
07/18/2022, 8:03 PMLandry Norris
07/18/2022, 8:03 PMeygraber
07/18/2022, 8:10 PMeygraber
07/18/2022, 8:16 PM