K2: Change resolution rules of when/if expressions with expected type

When expected type is known, use it as expected type for branch bodies.
While it indeed becomes different from the usual select call resolution,
where expected type is applied only after completion starts,
it helps to support, e.g. callable references resolution just as powerful
as it was in K1.

Also, in some cases where diagnostics have been changed, they become
a bit more helpful since they are reported closer
to the problematic places

cannotCastToFunction.kt test has been removed because it relied
on the case erroneously supported by the hack removed from
the FirCallResolver in this commit.

^KT-45989 Fixed
^KT-55936 Fixed
^KT-56445 Fixed
^KT-54709 Related
^KT-55931 Related
This commit is contained in:
Denis.Zharkov
2022-11-29 13:54:07 +01:00
committed by Space Team
parent a38040680c
commit 33dcbaac16
26 changed files with 156 additions and 81 deletions
@@ -1,22 +0,0 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
open class IrElement
fun IrElement.dumpKotlinLike(options: String = ""): String = "O"
fun IrElement.dump(normalizeNames: Boolean = false, stableOrder: Boolean = false): String = "K"
fun <T> select(flag: Boolean, a: T, b: T): T =
if (flag) a else b
fun dump(data: IrElement, dumpStrategy: String): String {
// Note: K1 reports TYPE_MISMATCH here (see also cannotCastToFunctionInIf.kt working both in K1/K2)
val dump: IrElement.() -> String = select(dumpStrategy == "KotlinLike", IrElement::dumpKotlinLike, IrElement::dump)
return data.dump()
}
fun box(): String {
val element = IrElement()
return dump(element, "KotlinLike") + dump(element, "OtherStrategy")
}