diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index f73d9a3a..03d39c2f 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -242,6 +242,7 @@ FrameResult VM__run_top_frame(VM* self) { DISPATCH(); } case OP_LOAD_CLASS_GLOBAL: { + assert(self->__curr_class); py_Name name = byte.arg; py_Ref tmp = py_getdict(self->__curr_class, name); if(tmp) { @@ -902,6 +903,7 @@ FrameResult VM__run_top_frame(VM* self) { DISPATCH(); } case OP_STORE_CLASS_ATTR: { + assert(self->__curr_class); py_Name name = byte.arg; if(py_istype(TOP(), tp_function)) { Function* ud = py_touserdata(TOP()); @@ -912,6 +914,7 @@ FrameResult VM__run_top_frame(VM* self) { DISPATCH(); } case OP_ADD_CLASS_ANNOTATION: { + assert(self->__curr_class); // [type_hint string] py_Type type = py_totype(self->__curr_class); py_TypeInfo* ti = TypeList__get(&self->types, type); diff --git a/src/public/py_exception.c b/src/public/py_exception.c index b25d9928..9985bba0 100644 --- a/src/public/py_exception.c +++ b/src/public/py_exception.c @@ -137,7 +137,10 @@ void py_clearexc(py_StackRef p0) { vm->last_retval = *py_NIL; vm->curr_exception = *py_NIL; vm->is_curr_exc_handled = false; - vm->__curr_class = NULL; + + /* Don't clear this, because StopIteration() may corrupt the class defination */ + // vm->__curr_class = NULL; + vm->__curr_function = NULL; if(p0) vm->stack.sp = p0; } diff --git a/tests/95_bugs.py b/tests/95_bugs.py index 80924f49..63802be0 100644 --- a/tests/95_bugs.py +++ b/tests/95_bugs.py @@ -137,3 +137,9 @@ assert (g == 1), g assert list.__new__(list) == [] assert a.__new__ == list.__new__ + + +class A: + x: list[int] = [i for i in range(1, 4)] + +assert A.x == [1, 2, 3] \ No newline at end of file