Files
kotlin-fork/compiler/testData/codegen/box/reified/safecast.kt
T
Roman Artemev c62e4b4fcf [JS IR BE] Support coroutines
* Move FinallyBlockLowering to common part
* Fix catching of dynamic exception
* Fix bridges for suspend functions
* Disable explicit cast to Unit
* Run lowering per module
* Update some test data
2018-08-08 18:33:39 +03:00

21 lines
358 B
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME
import kotlin.test.assertEquals
inline fun<reified T> safecast(x: Any?): T? {
return x as? T
}
fun box(): String {
val x = safecast<String>("abc")
assertEquals("abc", x)
val y = safecast<Int>(1)
assertEquals(1, y)
val z = safecast<Int>("abc")
assertEquals(null, z)
return "OK"
}