Introduce common ArithmeticException
Make divisionByZero test still fail in JS after introducing ArithmeticException
This commit is contained in:
+18
-8
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user