abf70a586c
Being disabled by default and not well-documented, these functions cause confusion among early adopters as to why their code don't work properly. Assert APIs need a proper design across Kotlin platforms. Since APIs are not available in common code and K/JS, it is premature to have such a general feature in a new experimental platform. Compiler tests: * Mute tests that rely on assert. * Replace JVM-specific assert calls with require calls and unmute passed K/JS tests. Merge-request: KT-MR-8636 Merged-by: Svyatoslav Kuzmich <svyatoslav.kuzmich@jetbrains.com>
44 lines
1.1 KiB
Kotlin
Vendored
44 lines
1.1 KiB
Kotlin
Vendored
// IGNORE_BACKEND: JS_IR
|
|
// IGNORE_BACKEND: JS_IR_ES6
|
|
// TODO: muted automatically, investigate should it be ran for JS or not
|
|
// IGNORE_BACKEND: JS
|
|
|
|
// WITH_STDLIB
|
|
|
|
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")
|
|
}
|
|
require(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")
|
|
}
|
|
require(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"
|
|
}
|