Files
kotlin-fork/compiler/testData/codegen/box/reified/checkcast.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

23 lines
379 B
Kotlin
Vendored

// WITH_RUNTIME
import kotlin.test.assertEquals
inline fun<reified T> checkcast(x: Any?): T {
return x as T
}
fun box(): String {
val x = checkcast<String>("abc")
assertEquals("abc", x)
val y = checkcast<Int>(1)
assertEquals(1, y)
try {
val z = checkcast<Int>("abc")
} catch (e: Exception) {
return "OK"
}
return "Fail"
}