Files
kotlin-fork/compiler/testData/codegen/box/binaryOp/divisionByZero.kt
T
Juan Chen 7249d2f889 [FIR] Fix translation of invokes & add return expressions for lambdas
* fixed NoSuchMethod caused by mismatched signatures of the "invoke" method generated for lambda arguments
* added test cases in invoke.kt for KFunction and anonymous functions
* added a transformer to wrap the last expression in the bodies of lambdas with return
2020-02-06 12:44:14 +03:00

25 lines
612 B
Kotlin
Vendored

// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JS
// reason - no error from division by zero in JS
fun expectFail(f: () -> Unit): Nothing? {
try {
f()
} catch (e: ArithmeticException) {
return null
}
throw AssertionError("Expected ArithmeticException to be thrown")
}
fun box(): String {
val a1 = 0
val a2 = expectFail { 1 / 0 } ?: 0
val a3 = expectFail { 1 / a1 } ?: 0
val a4 = expectFail { 1 / a2 } ?: 0
val a5 = expectFail { 2 * (1 / 0) } ?: 0
val a6 = expectFail { 2 * 1 / 0 } ?: 0
val s1 = expectFail { "${2 * (1 / 0) }" } ?: "OK"
return s1
}