Why does the compiler not give an incompatibility ...
# compiler
m
Why does the compiler not give an incompatibility error in this case?
Copy code
interface TestType
interface NonTestType
//sealed class NonTestType() {
//    data class NonTestTypeImpl(val test: Int = 1): NonTestType()
//}

class TestType1() : TestType
class TestType2() : TestType
class TestType3() : TestType
class NonTestTypeImpl(): NonTestType

fun main() {
    println("Hello, world!!!")

    val testTypeFlow = MutableSharedFlow<TestType>(replay = 1)

    val nonTestTypeFlow: Flow<NonTestType> = testTypeFlow.map {
        when (it) {
            is TestType1 -> {
                println("Hello, TestType1!!!")
                NonTestTypeImpl()
            }

            is TestType2 -> {
                println("Hello, TestType2!!!")
                NonTestTypeImpl()
            }

            is TestType3 -> {
                println("Hello, TestType3!!!")
                NonTestTypeImpl()
            }

            is NonTestType -> {
                println("Hello, NonTestType!!!")
                it
            }
            else -> {
                NonTestTypeImpl()
            }
        }
    }
}
We have a flow of
TypeTest
and one of the when conditions is checking if the value is of type
NonTypeTest
which is could not be. These are 2 interfaces which have no common parent entity. I would expect an incompatible error here
d
It's an an just interface, non a sealed interface Which means that there is nothing which against user to write a class which inherits both TestType and NonTestType at the same time
👌 1