diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index 68ed30c9..f5c7124d 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -887,7 +887,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) { goto __ERROR; } case OP_RE_RAISE: { - py_raise(&self->curr_exception); + assert(self->curr_exception.type); goto __ERROR_RE_RAISE; } case OP_PUSH_EXCEPTION: { diff --git a/src/public/modules.c b/src/public/modules.c index cc24429c..f7ef1616 100644 --- a/src/public/modules.c +++ b/src/public/modules.c @@ -199,6 +199,11 @@ static bool _py_builtins__print(int argc, py_Ref argv) { return true; } +static bool _py_NoneType__repr__(int argc, py_Ref argv) { + py_newstr(py_retval(), "None"); + return true; +} + py_TValue pk_builtins__register() { py_Ref builtins = py_newmodule("builtins", NULL); py_bindnativefunc(builtins, "repr", _py_builtins__repr); @@ -214,6 +219,9 @@ py_TValue pk_builtins__register() { py_bind(builtins, "print(*args, sep=' ', end='\\n')", _py_builtins__print); py_bind(builtins, "sorted(iterable, key=None, reverse=False)", _py_builtins__sorted); + + // None __repr__ + py_bindmagic(tp_NoneType, __repr__, _py_NoneType__repr__); return *builtins; } diff --git a/tests/28_exception.py b/tests/28_exception.py index 0e8071f7..d2da2335 100644 --- a/tests/28_exception.py +++ b/tests/28_exception.py @@ -1,3 +1,12 @@ +def f(): + raise IndexError + +try: + f() + exit(1) +except IndexError: + pass + try: assert False exit(1)