Files
kotlin-fork/compiler/testData/codegen/box/fir/localInvokeExtension.kt
T
Denis.Zharkov 3279313f2c K2: Fix priority for implicit receiver + extensionInvoke
See K1 counterpart at org.jetbrains.kotlin.resolve.calls.tower.TowerResolver.Task.processImplicitReceiver

^KT-58943 Fixed
^KT-59541 Fixed
2023-07-01 16:29:06 +00:00

56 lines
1.2 KiB
Kotlin
Vendored

// ISSUE: KT-59541
interface WriteContext {
val x: String
}
interface ReadContext {
val y: String
}
interface Codec<T> {
fun WriteContext.encode(value: T)
fun ReadContext.decode(): T?
}
fun <T> codec(
encode: WriteContext.(T) -> Unit,
decode: ReadContext.() -> T?
): Codec<T> = object : Codec<T> {
// Mostly, we check in this test that both `encode(value)` and `decode()` are resolved
// to the corresponding parameters of `codec` function (see KT-59541)
// Because before the fix for KT-37375, they both were resolved to the members of the anonymous objects
// leading to recursion and stack overflow.
override fun WriteContext.encode(value: T) = encode(value)
override fun ReadContext.decode(): T? = decode()
}
fun box(): String {
var result = ""
val t = codec(
{
result += x + it
},
{
y
}
)
with(t) {
object : WriteContext {
override val x: String
get() = "O"
}.encode("K")
result += object : ReadContext {
override val y: String
get() = "123"
}.decode()
}
if (result != "OK123") return "fail: $result"
return "OK"
}