FIR: improve inference of implicit type arguments in casts

Type parameters do not necessarily match one-to-one, or preserve order.
This commit is contained in:
pyos
2021-01-06 14:39:22 +01:00
committed by Dmitriy Novozhilov
parent acdc1f532b
commit 29f95c7df2
32 changed files with 134 additions and 149 deletions
@@ -0,0 +1,19 @@
sealed class C<out T, out U>
class A<out T>(val x: T) : C<T, Nothing>()
class B<out U>(val x: U) : C<Nothing, U>()
fun bar(x: String): C<Int, String> = B(x)
fun baz(x: Any) = "fail: $x"
fun baz(x: String) = x
typealias Z<U> = B<U>
fun box(): String =
when (val x = bar("O")) {
is A -> "fail??"
is B -> baz(x.x)
} + when (val y = bar("K")) {
is A -> "fail??"
is Z -> baz(y.x)
else -> "..."
}