[FE 1.0] Create DONT_CARE type only for callable references with no expected type

Otherwise, it can be resolved safety

^KT-52270 Fixed
This commit is contained in:
Victor Petukhov
2022-07-09 11:44:23 +02:00
committed by teamcity
parent fb21937eb1
commit 2057deb91b
10 changed files with 108 additions and 1 deletions
@@ -0,0 +1,61 @@
// WITH_STDLIB
import kotlin.random.Random
fun fun1() {
}
fun fun2() {
}
fun takesLambda(lambda: () -> Unit) {
lambda()
}
fun takesOtherLambda(lambda: () -> Unit) = lambda()
fun foo() {}
fun bar2(): Int = 1
fun <K> foo4(): K = 2 as K
fun test1(): String {
takesOtherLambda {
val reference: () -> Unit = if (Random.nextBoolean()) {
::fun1
} else {
::fun2
}
takesLambda(reference)
}
return "OK"
}
fun test2(): String {
takesOtherLambda {
val reference: () -> Unit = if (Random.nextBoolean())
::fun1
else
::fun2
takesLambda(reference)
}
return "OK"
}
fun test3(): String {
takesOtherLambda {
val reference: () -> Unit = if (Random.nextBoolean()) {
foo()
::fun1
} else {
foo()
::fun2
}
takesLambda(reference)
}
return "OK"
}
fun box(): String {
return if (test1() == "OK" && test2() == "OK" && test3() == "OK") "OK" else "NOK"
}