-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
…ied type (cherry picked from commit a75d5ba)
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// TARGET_BACKEND: JVM | ||
|
||
inline fun <reified T : CharSequence> f(x: Array<in String>) = x as Array<T> | ||
|
||
fun box(): String = try { | ||
f<String>(arrayOf<Any>(42)) | ||
"Fail" | ||
} catch (e: Exception) { | ||
"OK" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// TARGET_BACKEND: JVM | ||
|
||
inline fun <reified T : CharSequence> f(x: Array<Any>) = x as Array<T> | ||
|
||
fun box(): String = try { | ||
f<String>(arrayOf<Any>(42)) | ||
"Fail" | ||
} catch (e: Exception) { | ||
"OK" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// TARGET_BACKEND: JVM | ||
|
||
inline fun <reified T : CharSequence> f(x: Array<out Any>) = x as Array<T> | ||
|
||
fun box(): String = try { | ||
f<String>(arrayOf<Int>(42)) | ||
"Fail" | ||
} catch (e: Exception) { | ||
"OK" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// TARGET_BACKEND: JVM_IR | ||
|
||
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 foo(a : Array<String>?) = a.myOrEmpty() | ||
|
||
val a = arrayOf<Int>(1) as Array<Any> | ||
|
||
val b = arrayOf<Int>(1) as Array<Int> | ||
|
||
val c = arrayOf(arrayOf<Int>(1)) as Array<Array<Any>?> | ||
|
||
// 0 CHECKCAST |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.