Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt
T
Kirill Rakhman 69a7bf7f68 [FIR] Add equality constraint from expected type for some synthetic function calls
This fixes some cases where we infer some type variable inside one
of the branches to Nothing instead of the expected type because Nothing
appeared in some other branch.

Specifically, we add an equality instead of a subtype constraint during
completion of calls to synthetic functions for if/when, try and !!.
We don't do it when the call contains a (possibly nested) elvis or is
inside the RHS of an assignment.
Otherwise, we would prevent some smart-casts.

#KT-65882 Fixed
2024-03-05 17:38:59 +00:00

17 lines
1.2 KiB
Kotlin
Vendored

// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER
fun <T> select(vararg x: T) = x[0]
fun main() {
val x1: String.() -> String = if (true) {{ this }} else {{ this }}
val x2: String.() -> String = if (true) {{ -> this }} else {{ -> this }}
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) {{ 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 = <!INITIALIZER_TYPE_MISMATCH!>if (true) {<!ARGUMENT_TYPE_MISMATCH!>{ <!CANNOT_INFER_PARAMETER_TYPE!>str<!> -> "this" }<!>} else {{ "this" }}<!>
val x7: String.() -> String = select({ -> this }, { -> this })
val x8: String.() -> String = select({ this }, { this })
}