Introduce common ArithmeticException

Make divisionByZero test still fail in JS after introducing ArithmeticException
This commit is contained in:
Ilya Gorbunov
2018-08-09 23:39:17 +03:00
parent ceb909d261
commit 2df78fc81a
5 changed files with 30 additions and 9 deletions
+18 -8
View File
@@ -1,15 +1,25 @@
// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JS
// reason - no ArithmeticException in 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 = try { 1 / 0 } catch(e: ArithmeticException) { 0 }
val a3 = try { 1 / a1 } catch(e: ArithmeticException) { 0 }
val a4 = try { 1 / a2 } catch(e: ArithmeticException) { 0 }
val a5 = try { 2 * (1 / 0) } catch(e: ArithmeticException) { 0 }
val a6 = try { 2 * 1 / 0 } catch(e: ArithmeticException) { 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
try { val s1 = "${2 * (1 / 0) }" } catch(e: ArithmeticException) { }
val s1 = expectFail { "${2 * (1 / 0) }" } ?: "OK"
return "OK"
return s1
}