FIR checker: expose API to check if two types are compatible
This is useful for quickfixes offering casts. We don't want to offer user to cast incompatible types. Also, explicitly allow compare to `Nothing` and handle `Nothing` from intersection
This commit is contained in:
committed by
teamcityserver
parent
5b0ca06e95
commit
d77db2cda6
@@ -0,0 +1,9 @@
|
||||
fun test() {
|
||||
typesHaveCommonSubtype(listOf(1), listOf(1))
|
||||
typesHaveCommonSubtype(listOf(1), setOf(1))
|
||||
typesHaveCommonSubtype(listOf(1), mutableSetOf(1))
|
||||
|
||||
typesHaveNoCommonSubtype(listOf(1), listOf(""))
|
||||
typesHaveNoCommonSubtype(listOf(1), setOf(""))
|
||||
typesHaveNoCommonSubtype(listOf(1), mutableSetOf(""))
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
interface I
|
||||
data class Foo(val i: Int) : I
|
||||
data class Bar(val s: String)
|
||||
|
||||
fun test(f1: Foo, f2: Foo, f3: Foo?, b1: Bar, b2: Bar?, i: I) {
|
||||
typesHaveCommonSubtype(f1, f2)
|
||||
typesHaveCommonSubtype(f1, f3)
|
||||
typesHaveCommonSubtype(f3, b2)
|
||||
typesHaveCommonSubtype(f1, i)
|
||||
|
||||
typesHaveNoCommonSubtype(f1, b1)
|
||||
typesHaveNoCommonSubtype(f1, b2)
|
||||
typesHaveNoCommonSubtype(b1, i)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
enum class A {
|
||||
A1, A2
|
||||
}
|
||||
|
||||
enum class B {
|
||||
B1, B2
|
||||
}
|
||||
|
||||
fun test(a1: A, a2: A, b: B) {
|
||||
typesHaveCommonSubtype(a1, a2)
|
||||
typesHaveCommonSubtype(a1, A.A1)
|
||||
|
||||
typesHaveNoCommonSubtype(a1, b)
|
||||
typesHaveNoCommonSubtype(A.A1, b)
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fun test() {
|
||||
typesHaveCommonSubtype(1, 1)
|
||||
typesHaveCommonSubtype("", "")
|
||||
typesHaveCommonSubtype(null, null)
|
||||
|
||||
typesHaveNoCommonSubtype("", null)
|
||||
typesHaveNoCommonSubtype(1, 1L)
|
||||
typesHaveNoCommonSubtype(1, 1.0)
|
||||
typesHaveNoCommonSubtype(1, "")
|
||||
}
|
||||
Reference in New Issue
Block a user