@@ -134,14 +134,12 @@ def build_type_map(mapper: 'Mapper',
134
134
for module , cdef in classes :
135
135
class_ir = ClassIR (cdef .name , module .fullname , is_trait (cdef ),
136
136
is_abstract = cdef .info .is_abstract )
137
+ class_ir .is_ext_class = is_extension_class (cdef )
137
138
# If global optimizations are disabled, turn of tracking of class children
138
139
if not options .global_opts :
139
140
class_ir .children = None
140
141
mapper .type_to_ir [cdef .info ] = class_ir
141
142
142
- # Figure out which classes need to be compiled as non-extension classes.
143
- mark_non_ext_classes (mapper .type_to_ir )
144
-
145
143
# Populate structural information in class IR for extension classes.
146
144
for module , cdef in classes :
147
145
with catch_errors (module .path , cdef .line ):
@@ -250,39 +248,6 @@ def is_extension_class(cdef: ClassDef) -> bool:
250
248
return True
251
249
252
250
253
- def mark_non_ext_classes (class_map : Dict [TypeInfo , ClassIR ]) -> None :
254
- """
255
- Mark which classes should be compiled as non-extension classes.
256
- Classes in the chain of base classes of a non-extension class
257
- will all be marked as non-extension because currently
258
- non-extension classes cannot inherit from extension classes.
259
- """
260
- visit_first = list (class_map .keys ())
261
- visit_second = [] # type: List[TypeInfo]
262
- # First pass to gather all non-extension classes without
263
- # considering base class chains
264
- for typ in visit_first :
265
- ir = class_map [typ ]
266
- ir .is_ext_class = is_extension_class (typ .defn )
267
- if not ir .is_ext_class :
268
- visit_second .append (typ )
269
-
270
- # FIXME: Just reject these?
271
- # Second pass to propagate non-extension markings up the base class
272
- # chains of classes marked as non-extension classes during the first pass.
273
- for typ in visit_second :
274
- todo = [typ ]
275
- while todo :
276
- child = todo .pop ()
277
- for parent in child .bases :
278
- if parent .type in class_map :
279
- parent_ir = class_map [parent .type ]
280
- if not parent_ir .is_ext_class :
281
- continue
282
- parent_ir .is_ext_class = False
283
- todo .append (parent .type )
284
-
285
-
286
251
def get_func_def (op : Union [FuncDef , Decorator , OverloadedFuncDef ]) -> FuncDef :
287
252
if isinstance (op , OverloadedFuncDef ):
288
253
assert op .impl
@@ -699,9 +664,15 @@ def prepare_non_ext_class_def(path: str, module_name: str, cdef: ClassDef,
699
664
path , cdef .line )
700
665
# Handle case for regular function overload
701
666
else :
702
- errors .error ("Non-extension classes do not support overlaoded functions" ,
667
+ errors .error ("Non-extension classes do not support overloaded functions" ,
703
668
path , cdef .line )
704
669
670
+ if any (
671
+ cls in mapper .type_to_ir and mapper .type_to_ir [cls ].is_ext_class for cls in info .mro
672
+ ):
673
+ errors .error (
674
+ "Non-extension classes may not inherit from extension classes" , path , cdef .line )
675
+
705
676
706
677
def concrete_arg_kind (kind : int ) -> int :
707
678
"""Find the concrete version of an arg kind that is being passed."""
0 commit comments