blueloveTH hai 1 ano
pai
achega
3ea3cf7366
Modificáronse 3 ficheiros con 18 adicións e 1 borrados
  1. 1 1
      src/interpreter/ceval.c
  2. 8 0
      src/public/modules.c
  3. 9 0
      tests/28_exception.py

+ 1 - 1
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: {

+ 8 - 0
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;
 }
 

+ 9 - 0
tests/28_exception.py

@@ -1,3 +1,12 @@
+def f():
+    raise IndexError
+
+try:
+    f()
+    exit(1)
+except IndexError:
+    pass
+
 try:
     assert False
     exit(1)