Files
kotlin-fork/compiler/testData/codegen/box/casts/functions/reifiedIsFunKSmall.kt
T
Juan Chen 9dd8eda1c9 [FIR]: fix library methods in packages
Library methods such as 'listOf' are resolved
to have the package fragments as their parents,
but JVM expects their containing file classes as parents.
This fix generates those file classes and
uses them as parent replacements for such library methods.
2020-02-20 14:24:02 +03:00

43 lines
1.1 KiB
Kotlin
Vendored

// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_RUNTIME
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"
}