Michael de Kaste
02/24/2022, 9:52 AMfun main{
val scope = getScope()
when(scope){
// scope not smartcast and thus error
is DeeperScope.Impl1, is DeeperScope.Impl2 -> scope.someVar = "2"
}
}
interface Scope
sealed interface DeeperScope : Scope{
var someVar: String
data class Impl1(override var someVar: String) : DeeperScope
data class Impl2(override var someVar: String) : DeeperScope
}
fun getScope() : Scope = DeeperScope.Impl2("2")
Why can't scope be smartcast to DeeperScope in the when? Both implementations have their common parent as DeeperScopeephemient
02/24/2022, 11:29 AMMichael de Kaste
02/24/2022, 1:15 PMdmitriy.novozhilov
02/24/2022, 1:50 PM