mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-04-30 19:09:26 +08:00
The assign_remainder (%=) case in Boxed_Number::go was missing the check_divide_by_zero guard, causing a hardware SIGFPE on integer modulo by zero. Also moved a misplaced check_divide_by_zero from assign_bitwise_and (&=) where it was erroneous. Additionally, the catch block in Equation_AST_Node::eval_internal was masking the arithmetic_error exception as a generic "unsupported operation" error; arithmetic_error is now re-thrown to provide the correct error message. Co-authored-by: leftibot <leftibot@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
17 lines
322 B
ChaiScript
17 lines
322 B
ChaiScript
// modulo by zero should throw, not crash
|
|
try {
|
|
3 % 0
|
|
assert_true(false)
|
|
} catch (e) {
|
|
assert_equal("Arithmetic error: divide by zero", e.what())
|
|
}
|
|
|
|
// assign-modulo by zero should also throw
|
|
var x = 3;
|
|
try {
|
|
x %= 0
|
|
assert_true(false)
|
|
} catch (e) {
|
|
assert_equal("Arithmetic error: divide by zero", e.what())
|
|
}
|