Use non-allowed actual defaults in backends to workaround compiler exception
It's difficult to fix KT-22818 until the IR comes along, so we're providing a workaround where one can disable the ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS error and provide default values in the actual function, to avoid exception from the backend. #KT-22818
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||
// FILE: common.kt
|
||||
|
||||
public expect fun <T> Array<out T>.copyInto(
|
||||
destination: Array<T>, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size
|
||||
): Array<T>
|
||||
|
||||
// FILE: platform.kt
|
||||
|
||||
// This test should be updated once KT-22818 is fixed; default values are not allowed in the actual function
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
public actual fun <T> Array<out T>.copyInto(
|
||||
destination: Array<T>, destinationOffset: Int = 42, startIndex: Int = 43, endIndex: Int = size + 44
|
||||
): Array<T> {
|
||||
destination as Array<Int>
|
||||
destination[0] = destinationOffset
|
||||
destination[1] = startIndex
|
||||
destination[2] = endIndex
|
||||
return destination
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = Array<Int>(3) { it }
|
||||
val result = a.copyInto(a)
|
||||
return if (result[0] == 42 && result[1] == 43 && result[2] == 47) "OK"
|
||||
else "Fail: ${result[0]} ${result[1]} ${result[2]}"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// IGNORE_BACKEND: JVM_IR, JS_IR
|
||||
// FILE: common.kt
|
||||
|
||||
expect interface I {
|
||||
fun test(source: String = "expect")
|
||||
}
|
||||
|
||||
expect interface J : I
|
||||
|
||||
// FILE: platform.kt
|
||||
|
||||
actual interface I {
|
||||
// This test should be updated once KT-22818 is fixed; default values are not allowed in the actual function
|
||||
@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS")
|
||||
actual fun test(source: String = "actual")
|
||||
}
|
||||
|
||||
actual interface J : I {
|
||||
override fun test(source: String) {
|
||||
if (source != "actual") throw AssertionError(source)
|
||||
}
|
||||
}
|
||||
|
||||
class K : J
|
||||
|
||||
fun box(): String {
|
||||
K().test()
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user