[JS IR] Add deep copying for callable reference

Perform a deep copy of callable reference adapter on inline lowering

^KT-49844 Fixed
This commit is contained in:
Alexander Korepanov
2021-12-09 14:12:00 +03:00
committed by Space
parent 7b41d382b8
commit b82c306530
13 changed files with 133 additions and 20 deletions
@@ -0,0 +1,34 @@
// WITH_STDLIB
// KJS_WITH_FULL_RUNTIME
// FILE: 1.kt
package test
inline fun doIt(f: () -> Int): Int = f()
inline fun calcOnePlusTwo(f: (Int) -> Int): Int = f(1) + f(2)
inline fun getFirstArg(a: Int, vararg other: Int): Int = a
fun testCustomFunction(): Boolean {
val x = doIt { calcOnePlusTwo(::getFirstArg) }
return x == 3
}
fun testRuntimeFunctionCase1(): Boolean {
val x = "123".let { it.minOf(::maxOf) }
return x == '1'
}
fun testRuntimeFunctionCase2(): Boolean {
val x = "3123".minOfOrNull { a: Char -> a.titlecase().maxOf(::maxOf) }
return x == '1'
}
// FILE: 2.kt
import test.*
fun box(): String {
if (!testCustomFunction()) return "testCustomFunction failed"
if (!testRuntimeFunctionCase1()) return "testRuntimeFunctionCase1 failed"
if (!testRuntimeFunctionCase2()) return "testRuntimeFunctionCase2 failed"
return "OK"
}