Support non-trivial default argument values in expected functions on JVM

#KT-22818 Fixed
This commit is contained in:
Alexander Udalov
2019-02-20 19:30:54 +01:00
parent b2cc661783
commit b8bc79e17c
16 changed files with 297 additions and 7 deletions
@@ -0,0 +1,18 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: JVM_IR
// FILE: common.kt
expect class C {
val value: String
fun test(result: String = value): String
}
// FILE: platform.kt
actual class C(actual val value: String) {
actual fun test(result: String): String = result
}
fun box() = C("Fail").test("OK")
@@ -0,0 +1,16 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: JVM_IR
// FILE: common.kt
class Receiver(val value: String)
expect fun Receiver.test(result: String = value): String
// FILE: platform.kt
actual fun Receiver.test(result: String): String {
return result
}
fun box() = Receiver("Fail").test("OK")
@@ -0,0 +1,17 @@
// !LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND: JVM_IR
// FILE: common.kt
class B(val value: Int)
expect fun test(a: Int = 2, b: Int = B(a * 2).value, c: String = "${b}$a"): String
// FILE: platform.kt
actual fun test(a: Int, b: Int, c: String): String = c
fun box(): String {
val result = test()
return if (result == "42") "OK" else "Fail: $result"
}
@@ -0,0 +1,31 @@
// !LANGUAGE: +MultiPlatformProjects
// NO_CHECK_LAMBDA_INLINING
// IGNORE_BACKEND: JVM_IR
// FILE: 1.kt
class C(val s1: String, val s2: String)
expect fun C.test(r1: () -> String = { s1 }, r2: () -> String = this::s2): String
actual inline fun C.test(r1: () -> String, r2: () -> String): String = r1() + r2()
expect class D {
val s1: String
val s2: String
fun test(r1: () -> String = { s1 }, r2: () -> String = this::s2): String
}
actual class D(actual val s1: String, actual val s2: String) {
actual inline fun test(r1: () -> String, r2: () -> String): String = r1() + r2()
}
// FILE: 2.kt
fun box(): String {
if (C("O", "K").test() != "OK") return "Fail extension receiver"
if (D("O", "K").test() != "OK") return "Fail dispatch receiver"
return "OK"
}