Skip to content

Commit 6dc507f

Browse files
committed
[jvm] Die with 'Division by zero' in div_i, try 2
Without this change a division by zero led to a Java exception: java.lang.ArithmeticException: / by zero For some reasons that didn't work well with 'dies-ok'. As a result t/nqp/059-nqpop.t was blowing up on the jvm backend. With this patch 'make test' is clean, again. Also, the error message is now identical to the other two backends.
1 parent fb1e5cc commit 6dc507f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@ QAST::OperationsJAST.map_jvm_core_op('sub_n', 'dsub', [$RT_NUM, $RT_NUM], $RT_NU
21962196
QAST::OperationsJAST.map_jvm_core_op('mul_i', 'lmul', [$RT_INT, $RT_INT], $RT_INT);
21972197
QAST::OperationsJAST.map_classlib_core_op('mul_I', $TYPE_OPS, 'mul_I', [$RT_OBJ, $RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
21982198
QAST::OperationsJAST.map_jvm_core_op('mul_n', 'dmul', [$RT_NUM, $RT_NUM], $RT_NUM);
2199-
QAST::OperationsJAST.map_classlib_core_op('div_i', $TYPE_OPS, 'div_i', [$RT_INT, $RT_INT], $RT_INT);
2199+
QAST::OperationsJAST.map_classlib_core_op('div_i', $TYPE_OPS, 'div_i', [$RT_INT, $RT_INT], $RT_INT, :tc);
22002200
QAST::OperationsJAST.map_classlib_core_op('div_I', $TYPE_OPS, 'div_I', [$RT_OBJ, $RT_OBJ, $RT_OBJ], $RT_OBJ, :tc);
22012201
QAST::OperationsJAST.map_classlib_core_op('div_In', $TYPE_OPS, 'div_In', [$RT_OBJ, $RT_OBJ], $RT_NUM, :tc);
22022202
QAST::OperationsJAST.map_jvm_core_op('div_n', 'ddiv', [$RT_NUM, $RT_NUM], $RT_NUM);

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6761,8 +6761,11 @@ public static double div_In(SixModelObject a, SixModelObject b, ThreadContext tc
67616761
: new BigDecimal(getBI(tc, a)).divide(new BigDecimal(divisor), 309, RoundingMode.HALF_UP).doubleValue();
67626762
}
67636763

6764-
public static long div_i(long a, long b) {
6765-
return (b == 0) ? a / b : (long)Math.floor((double) a / b);
6764+
public static long div_i(long a, long b, ThreadContext tc) {
6765+
if (b == 0) {
6766+
die_s("Division by zero", tc);
6767+
}
6768+
return (long)Math.floor((double) a / b);
67666769
}
67676770

67686771
public static SixModelObject mod_I(SixModelObject a, SixModelObject b, SixModelObject type, ThreadContext tc) {

0 commit comments

Comments
 (0)