mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-16 15:53:55 +00:00
36 lines
983 B
Kotlin
Vendored
36 lines
983 B
Kotlin
Vendored
fun fn0() {}
|
|
fun fn1(x: Any) {}
|
|
|
|
inline fun <reified T> reifiedAsSucceeds(x: Any, operation: String) {
|
|
try {
|
|
x as T
|
|
}
|
|
catch (e: Throwable) {
|
|
throw AssertionError("$operation: should not throw exceptions, got $e")
|
|
}
|
|
}
|
|
|
|
inline fun <reified T> reifiedAsFailsWithCCE(x: Any, operation: String) {
|
|
try {
|
|
x as T
|
|
}
|
|
catch (e: java.lang.ClassCastException) {
|
|
return
|
|
}
|
|
catch (e: Throwable) {
|
|
throw AssertionError("$operation: should throw ClassCastException, got $e")
|
|
}
|
|
throw AssertionError("$operation: should fail with CCE, no exception thrown")
|
|
}
|
|
|
|
fun box(): String {
|
|
val f0 = ::fn0 as Any
|
|
val f1 = ::fn1 as Any
|
|
|
|
reifiedAsSucceeds<Function0<*>>(f0, "f0 as Function0<*>")
|
|
reifiedAsFailsWithCCE<Function1<*, *>>(f0, "f0 as Function1<*, *>")
|
|
reifiedAsFailsWithCCE<Function0<*>>(f1, "f1 as Function0<*>")
|
|
reifiedAsSucceeds<Function1<*, *>>(f1, "f1 as Function1<*, *>")
|
|
|
|
return "OK"
|
|
} |