[FIR] Fix mutant extension function types

Consider the following example from
`extensionLambdasAndArrow.kt`:

```
val x4: String.() -> String = if (true) {
    { str: String -> "this" }
} else {
    { str: String -> "this" }
}
```

Because of
`coerceFirstParameterToExtensionReceiver`
the given lambdas must be of the type
`String.() -> String`, but because of a bug
they are `String.(String) -> String`. At the
same time, during inference their expected
types are, indeed, calculated correctly as
`String.() -> String`.

^KT-59394 Declined
(no more compiler crashes, #potential-feature)
This commit is contained in:
Nikolay Lunyak
2023-07-13 14:55:06 +03:00
committed by Space Team
parent bca44e5d8c
commit 9850987415
11 changed files with 96 additions and 20 deletions
+25
View File
@@ -0,0 +1,25 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
fun <K> id(x: K): K = x
fun box(): String {
val x4: String.() -> String = if (true) {fun String.(): String { return "this" }} else {{ str: String -> "that" }}
val x51: String.() -> String = if (false) {fun String.(): String { return "this" }} else {{ "that" }}
val x52: String.() -> String = if (false) {fun String.(): String { return "this" }} else {{ str: String -> "that" }}
val x53: String.() -> String = if (false) {fun String.(): String { return "this" }} else {fun(str: String) = "that"}
val i28: Int.(String) -> Int = id { i: Int, s -> i + s.length }
val result = "test".x4() +
"::" + "test".x51() +
"::" + "test".x52() +
"::" + "test".x53() +
"::" + 10.i28("test")
return if (result == "this::that::that::that::14") {
"OK"
} else {
"Fail: $result"
}
}