[FIR2IR] Fix cast insertion for SAM conversion

The rule is: no cast is required iff the argument type is a
non-reflection function type and a subtype of the expected
function type.
We approximate the cone types using the FIR2IR specific config
to account for intersection types, captured types, etc.

#KT-63345 Fixed
#KT-63510
#KT-62865
This commit is contained in:
Kirill Rakhman
2023-11-15 15:25:15 +01:00
committed by Space Team
parent dd1d36816b
commit b857c28ab3
10 changed files with 105 additions and 10 deletions
@@ -70,12 +70,12 @@ fun test6(a: Any) {
fun test7(a: Function1<Int, Int>) {
a as Function0<Unit> /*~> Unit */
run1(r = a /*-> KRunnable */)
run1(r = a /*as Function0<Unit> */ /*-> KRunnable */)
}
fun <T : Function1<Int, Int>> test7a(a: T) {
a as Function0<Unit> /*~> Unit */
run1(r = a /*-> KRunnable */)
run1(r = a /*as Function0<Unit> */ /*-> KRunnable */)
}
fun <T> test7b(a: T) where T : Function1<Int, Unit>, T : Function0<Unit> {
@@ -97,3 +97,14 @@ fun test9() {
run1(r = ::test9 /*-> KRunnable */)
}
fun test10(a: Any) {
when {
when {
a is Unrelated -> a /*as Unrelated */ is Function0<Unit>
else -> false
} -> { // BLOCK
run1(r = a /*as Function0<Unit> */ /*-> KRunnable */)
}
}
}