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
+5
-5
@@ -1,5 +1,5 @@
|
||||
// SKIP_TXT
|
||||
// ISSUE: KT-55729
|
||||
// ISSUE: KT-55729, KT-55931, KT-55936
|
||||
|
||||
fun main(b: Boolean) {
|
||||
callWithLambda {
|
||||
@@ -9,16 +9,16 @@ fun main(b: Boolean) {
|
||||
|
||||
callWithLambda {
|
||||
// Unit conversion should work (for K2 see KT-55936)
|
||||
<!ARGUMENT_TYPE_MISMATCH!>if (b) ::test1 else ::test2<!>
|
||||
if (b) ::test1 else ::test2
|
||||
}
|
||||
|
||||
callWithLambda {
|
||||
// That hasn't been working ever in K1 nor K2
|
||||
<!ARGUMENT_TYPE_MISMATCH!>if (b) {
|
||||
// Doesn't work in K1, but does in K2 (see KT-55931)
|
||||
if (b) {
|
||||
::test1
|
||||
} else {
|
||||
::test2
|
||||
}<!>
|
||||
}
|
||||
}
|
||||
|
||||
callWithLambda {
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
// SKIP_TXT
|
||||
// ISSUE: KT-55729
|
||||
// ISSUE: KT-55729, KT-55931, KT-55936
|
||||
|
||||
fun main(b: Boolean) {
|
||||
callWithLambda {
|
||||
@@ -13,7 +13,7 @@ fun main(b: Boolean) {
|
||||
}
|
||||
|
||||
callWithLambda {
|
||||
// That hasn't been working ever in K1 nor K2
|
||||
// Doesn't work in K1, but does in K2 (see KT-55931)
|
||||
if (b) <!TYPE_MISMATCH!>{
|
||||
<!TYPE_MISMATCH!>::<!TYPE_MISMATCH!>test1<!><!>
|
||||
}<!> else <!TYPE_MISMATCH!>{
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ fun bar(block: () -> String) {}
|
||||
fun test_5(b: Boolean) {
|
||||
bar {
|
||||
<!ARGUMENT_TYPE_MISMATCH!>if (b) {
|
||||
println("meh")
|
||||
<!TYPE_MISMATCH!>println("meh")<!>
|
||||
}<!>
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ fun main() {
|
||||
val x3: () -> String = if (true) {{ -> "this" }} else {{ -> "this" }}
|
||||
val x4: String.() -> String = if (true) {{ str: String -> "this" }} else {{ str: String -> "this" }}
|
||||
val x41: String.(String) -> String = if (true) {{ str: String, str2: String -> "this" }} else {{ str: String, str2: String -> "this" }}
|
||||
val x42: String.(String) -> String = if (true) {<!ARGUMENT_TYPE_MISMATCH!>{ str, <!CANNOT_INFER_PARAMETER_TYPE!>str2<!> -> "this" }<!>} else {<!ARGUMENT_TYPE_MISMATCH!>{ str, <!CANNOT_INFER_PARAMETER_TYPE!>str2<!> -> "this" }<!>}
|
||||
val x42: String.(String) -> String = if (true) {{ str, <!CANNOT_INFER_PARAMETER_TYPE!>str2<!> -> "this" }} else {{ str, <!CANNOT_INFER_PARAMETER_TYPE!>str2<!> -> "this" }}
|
||||
val x5: String.() -> String = if (true) {<!ARGUMENT_TYPE_MISMATCH!>{ <!CANNOT_INFER_PARAMETER_TYPE!>str<!> -> "this" }<!>} else {<!ARGUMENT_TYPE_MISMATCH!>{ <!CANNOT_INFER_PARAMETER_TYPE!>str<!> -> "this" }<!>}
|
||||
val x6: String.() -> String = if (true) {<!ARGUMENT_TYPE_MISMATCH!>{ <!CANNOT_INFER_PARAMETER_TYPE!>str<!> -> "this" }<!>} else {{ "this" }}
|
||||
val x7: String.() -> String = select({ -> this }, { -> this })
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
fun foo() {
|
||||
val s: String? = if (true) <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing?")!>materialize()<!> else null
|
||||
}
|
||||
|
||||
fun <K> materialize(): K = TODO()
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
fun foo() {
|
||||
|
||||
Reference in New Issue
Block a user