fix a bug

This commit is contained in:
blueloveTH 2024-09-08 23:56:18 +08:00
parent 2d4cf81356
commit 0109829ad4
3 changed files with 13 additions and 1 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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]