Files
kotlin/compiler/testData/codegen/boxWithStdlib/casts/reifiedIsFunKSmall.kt
2015-10-06 10:06:27 +03:00

36 lines
942 B
Kotlin
Vendored

fun fn0() {}
fun fn1(x: Any) {}
inline fun <reified T> assertReifiedIs(x: Any, type: String) {
val answer: Boolean
try {
answer = x is T
}
catch (e: Throwable) {
throw AssertionError("$x is $type: should not throw exceptions, got $e")
}
assert(answer) { "$x is $type: failed" }
}
inline fun <reified T> assertReifiedIsNot(x: Any, type: String) {
val answer: Boolean
try {
answer = x !is T
}
catch (e: Throwable) {
throw AssertionError("$x !is $type: should not throw exceptions, got $e")
}
assert(answer) { "$x !is $type: failed" }
}
fun box(): String {
val f0 = ::fn0 as Any
val f1 = ::fn1 as Any
assertReifiedIs<Function0<*>>(f0, "Function0<*>")
assertReifiedIs<Function1<*, *>>(f1, "Function1<*, *>")
assertReifiedIsNot<Function0<*>>(f1, "Function0<*>")
assertReifiedIsNot<Function1<*, *>>(f0, "Function1<*, *>")
return "OK"
}