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:
committed by
Space Team
parent
a38040680c
commit
33dcbaac16
+1
-1
@@ -26,7 +26,7 @@ fun <T> bind2(r: Option<T>): Option<T> {
|
||||
fun <T, R> bind3(r: Option<T>): Option<T> {
|
||||
return <!RETURN_TYPE_MISMATCH!>if (r is Some) {
|
||||
// Diagnoses an error correctly
|
||||
if (true) None<R>() else r
|
||||
<!TYPE_MISMATCH!>if (true) <!TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>None<R>()<!> else r<!>
|
||||
}
|
||||
else r<!>
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -29,11 +29,11 @@ val testSafeCall4: String? = J.m[""]?.let { it.toString() }
|
||||
val testIf1: String = if (true) J.s else J.s
|
||||
val testIf2: String? = if (true) J.s else J.s
|
||||
|
||||
val testIf3: String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>if (true) J.m[""] else J.m[""]<!>
|
||||
val testIf3: String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>if (true) <!TYPE_MISMATCH!>J.m[""]<!> else <!TYPE_MISMATCH!>J.m[""]<!><!>
|
||||
val testIf4: String? = if (true) J.m[""] else J.m[""]
|
||||
|
||||
val testWhen1: String = when { else -> J.s }
|
||||
val testWhen2: String? = when { else -> J.s }
|
||||
|
||||
val testWhen3: String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>when { else -> J.m[""] }<!>
|
||||
val testWhen3: String = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH!>when { else -> <!TYPE_MISMATCH!>J.m[""]<!> }<!>
|
||||
val testWhen4: String? = when { else -> J.m[""] }
|
||||
|
||||
Reference in New Issue
Block a user