KT-53465, KT-53677 Get rid of unnecessary checkcasts to array of reified type
This commit is contained in:
committed by
teamcity
parent
d8522a8967
commit
a75d5ba4cf
+29
@@ -0,0 +1,29 @@
|
||||
// WITH_STDLIB
|
||||
// WITH_COROUTINES
|
||||
// DONT_TARGET_EXACT_BACKEND: JVM
|
||||
// DONT_TARGET_EXACT_BACKEND: JS
|
||||
|
||||
import kotlin.coroutines.*
|
||||
|
||||
public inline fun <reified T> myEmptyArray(): Array<T> = arrayOfNulls<T>(0) as Array<T>
|
||||
|
||||
inline fun <reified T> Array<out T>?.myOrEmpty(): Array<out T> = this ?: myEmptyArray<T>()
|
||||
|
||||
fun <T> runBlocking(c: suspend () -> T): T {
|
||||
var res: T? = null
|
||||
c.startCoroutine(Continuation(EmptyCoroutineContext) {
|
||||
res = it.getOrThrow()
|
||||
})
|
||||
return res!!
|
||||
}
|
||||
|
||||
suspend fun suspendHere(x: String) {}
|
||||
|
||||
suspend fun main() {
|
||||
arrayOf("1").myOrEmpty().forEach { suspendHere(it) }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
runBlocking(::main)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user