Hildebrandt Tobias
12/05/2025, 11:34 AMsealed class with a companion object that has some fields and functions that access fields in the declared object and inner sealed class.
In JVM it compiles fine, but in KotlinJS it says that it cannot resolve the fields.
In this example the Error Unresolved reference 'name' would be at the it.name
sealed class Product(open val name: String) {
object TestProduct1 : Product("Test1")
sealed class MetaProduct(override val name): Product(name) {
object SubProduct1: MetaProduct("sub1")
object SubProduct2: MetaProduct("sub2")
}
companion object {
val entries = listOf(
TestProduct1,
MetaProduct.SubProduct1,
MetaProduct.SubProduct2
)
val byName = entries.associateBy { it.name } // Error here in KotlinJS, but not JVM
}
}ephemient
12/05/2025, 11:55 AMHildebrandt Tobias
12/05/2025, 11:57 AMlistOf to listOf<Product>Hildebrandt Tobias
12/05/2025, 11:57 AM