From e82f4f33d698497611fc0b37a07c8ba03c06a6a1 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Fri, 18 Nov 2022 18:27:18 +0800 Subject: [PATCH] fix % zero error --- src/pocketpy.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pocketpy.h b/src/pocketpy.h index db79ab16..84935711 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -203,7 +203,9 @@ void __initializeBuiltinFunctions(VM* _vm) { _vm->bindMethod("int", "__mod__", [](VM* vm, PyVarList args) { if(!args[0]->isType(vm->_tp_int) || !args[1]->isType(vm->_tp_int)) vm->typeError("unsupported operand type(s) for " "%" ); - return vm->PyInt(vm->PyInt_AS_C(args[0]) % vm->PyInt_AS_C(args[1])); + _Int rhs = vm->PyInt_AS_C(args[1]); + if(rhs == 0) vm->zeroDivisionError(); + return vm->PyInt(vm->PyInt_AS_C(args[0]) % rhs); }); _vm->bindMethod("int", "__repr__", [](VM* vm, PyVarList args) {