blueloveTH пре 1 година
родитељ
комит
a96173fd6a
3 измењених фајлова са 13 додато и 2 уклоњено
  1. 7 0
      src/interpreter/ceval.c
  2. 5 1
      src/interpreter/vm.c
  3. 1 1
      src/public/py_exception.c

+ 7 - 0
src/interpreter/ceval.c

@@ -909,6 +909,13 @@ FrameResult VM__run_top_frame(VM* self) {
                     base = py_totype(TOP());
                 }
                 POP();
+
+                py_TypeInfo* base_ti = c11__at(py_TypeInfo, &self->types, base);
+                if(base_ti->is_sealed){
+                    TypeError("type '%t' is not an acceptable base type", base);
+                    goto __ERROR;
+                }
+
                 py_Type type =
                     pk_newtype(py_name2str(name), base, frame->module, NULL, true, false);
                 PUSH(py_tpobject(type));

+ 5 - 1
src/interpreter/vm.c

@@ -313,8 +313,12 @@ py_Type pk_newtype(const char* name,
     c11_vector* types = &pk_current_vm->types;
     py_Type index = types->count;
     py_TypeInfo* ti = c11_vector__emplace(types);
+    py_TypeInfo* base_ti = base ? c11__at(py_TypeInfo, types, base) : NULL;
+    if(base_ti && base_ti->is_sealed){
+        c11__abort("type '%s' is not an acceptable base type", py_name2str(base_ti->name));
+    }
     py_TypeInfo__ctor(ti, py_name(name), index, base, module ? *module : *py_NIL);
-    if(!dtor && base) { dtor = c11__at(py_TypeInfo, types, base)->dtor; }
+    if(!dtor && base) dtor = base_ti->dtor;
     ti->dtor = dtor;
     ti->is_python = is_python;
     ti->is_sealed = is_sealed;

+ 1 - 1
src/public/py_exception.c

@@ -106,7 +106,7 @@ py_Type pk_BaseException__register() {
 }
 
 py_Type pk_Exception__register() {
-    py_Type type = pk_newtype("Exception", tp_BaseException, NULL, NULL, false, true);
+    py_Type type = pk_newtype("Exception", tp_BaseException, NULL, NULL, false, false);
     return type;
 }