// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not // IGNORE_BACKEND: JS fun fn0() {} fun fn1(x: Any) {} inline fun reifiedSafeAsReturnsNonNull(x: Any?, operation: String) { val y = try { x as? T } catch (e: Throwable) { throw AssertionError("$operation: should not throw exceptions, got $e") } if (y == null) { throw AssertionError("$operation: should return non-null, got null") } } inline fun reifiedSafeAsReturnsNull(x: Any?, operation: String) { val y = try { x as? T } catch (e: Throwable) { throw AssertionError("$operation: should not throw exceptions, got $e") } if (y != null) { throw AssertionError("$operation: should return null, got $y") } } fun box(): String { val f0 = ::fn0 as Any val f1 = ::fn1 as Any reifiedSafeAsReturnsNonNull>(f0, "f0 as Function0<*>") reifiedSafeAsReturnsNull>(f0, "f0 as Function1<*, *>") reifiedSafeAsReturnsNull>(f1, "f1 as Function0<*>") reifiedSafeAsReturnsNonNull>(f1, "f1 as Function1<*, *>") reifiedSafeAsReturnsNull>(null, "null as Function0<*>") reifiedSafeAsReturnsNull>(null, "null as Function1<*, *>") return "OK" }