Files
kotlin-fork/compiler/testData/codegen/box/fir/selectingLambdas.kt
T
Nikolay Lunyak 9850987415 [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)
2023-08-04 11:20:39 +00:00

26 lines
921 B
Kotlin
Vendored

// 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"
}
}