'Kotlin typealias does not seem to recognize child classes of other sealed classes

I have a sealed class and a subclass like this -

sealed class TimePeriod {
    data class TwoLineTimePeriod(
        val lineOneTimePeriod: String,
        val lineTwoTimePeriod: String
    ) : TimePeriod()
}

In another file, I have a when statement that does some work after checking the type -

This works -

typealias ModelTimePeriod = com.x.x.x.x.TimePeriod

fun ModelTimePeriod.toTimePeriod(): TimePeriod =
    when (this) {
        is TimePeriod.TwoLineTimePeriod -> // Works fine 
            //does something 
    }

However, this does not work -

fun ModelTimePeriod.toTimePeriod(): TimePeriod =
    when (this) {
        is ModelTimePeriod.TwoLineTimePeriod -> //Does not work . Does not compile 
            //does something 
    }

Is this designed in this way for a reason? Or is this a bug in the compiler? IntelliJ does not recognize it either



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source