b857c28ab3
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
67 lines
1.3 KiB
Kotlin
Vendored
67 lines
1.3 KiB
Kotlin
Vendored
fun test1(a: Function0<Unit>) {
|
|
when {
|
|
a is Runnable -> { // BLOCK
|
|
runStatic(r = a /*as Runnable */)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test2(a: Function0<Unit>) {
|
|
when {
|
|
a is Runnable -> { // BLOCK
|
|
J().run1(r = a /*as Runnable */)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test3(a: Function0<Unit>) {
|
|
when {
|
|
a is Runnable -> { // BLOCK
|
|
J().run2(r1 = a /*as Runnable */, r2 = a /*as Runnable */)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test4(a: Function0<Unit>, b: Function0<Unit>) {
|
|
when {
|
|
a is Runnable -> { // BLOCK
|
|
J().run2(r1 = a /*as Runnable */, r2 = b /*-> Runnable */)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test5(a: Any) {
|
|
when {
|
|
a is Runnable -> { // BLOCK
|
|
J().run1(r = a /*as Runnable */)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test5x(a: Any) {
|
|
when {
|
|
a is Runnable -> { // BLOCK
|
|
a /*as Runnable */ as Function0<Unit> /*~> Unit */
|
|
J().run1(r = a /*as Runnable */)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun test6(a: Any) {
|
|
a as Function0<Unit> /*~> Unit */
|
|
J().run1(r = a /*as Function0<Unit> */ /*-> Runnable */)
|
|
}
|
|
|
|
fun test7(a: Function1<Int, Int>) {
|
|
a as Function0<Unit> /*~> Unit */
|
|
J().run1(r = a /*as Function0<Unit> */ /*-> Runnable */)
|
|
}
|
|
|
|
fun test8(a: Function0<Unit>) {
|
|
J().run1(r = id<@FlexibleNullability Function0<Unit>?>(x = a) /*-> @FlexibleNullability Runnable? */)
|
|
}
|
|
|
|
fun test9() {
|
|
J().run1(r = ::test9 /*-> Runnable */)
|
|
}
|