Skip to content

Commit 7dd59ce

Browse files
committed
Consider inheritance chain when retrieving class attributes
1 parent 3ec279a commit 7dd59ce

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/generators/generator.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,12 @@ def gen_variable_decl(self,
823823

824824
##### Expressions #####
825825

826+
def _get_class_attributes(self, class_decl, attr_name):
827+
class_decls = self.context.get_classes(self.namespace).values()
828+
if attr_name == 'functions':
829+
return class_decl.get_callable_functions(class_decls)
830+
return class_decl.get_all_fields(class_decls)
831+
826832
def generate_expr(self,
827833
expr_type: tp.Type=None,
828834
only_leaves=False,
@@ -2354,9 +2360,7 @@ def _get_matching_objects(self,
23542360
self.function_type):
23552361
continue
23562362
cls, type_map_var = self._get_class(var_type)
2357-
# TODO for functions we should also consider
2358-
# get_callable_functions(class_decls.values())
2359-
for attr in getattr(cls, attr_name): # function or field
2363+
for attr in self._get_class_attributes(cls, attr_name):
23602364
attr_type = tp.substitute_type(
23612365
attr.get_type(), type_map_var)
23622366
if attr_type == self.bt_factory.get_void_type():
@@ -2398,12 +2402,16 @@ def _get_matching_objects(self,
23982402
# parameter with type assignment map of the
23992403
# receiver class.
24002404
bound = tp.substitute_type(bound, type_map_var)
2401-
is_wildcard = bound.is_wildcard()
2402-
if is_wildcard or func_type_var_map.get(
2405+
if func_type_var_map.get(
24032406
t_param, bound) != bound:
24042407
continue
2408+
if bound.is_wildcard():
2409+
type_var_bounds = None
2410+
break
24052411
if not bound.has_type_variables():
24062412
type_var_bounds[t_param] = bound
2413+
if type_var_bounds is None:
2414+
continue
24072415
type_var_bounds.update(type_map_var)
24082416
type_var_bounds.update(fun_type_var_map)
24092417
fun_type_var_map = tu.instantiate_parameterized_function(
@@ -2744,7 +2752,7 @@ def _get_matching_class_decls(self,
27442752

27452753
class_decls = []
27462754
for c in self.context.get_classes(self.namespace).values():
2747-
for attr in getattr(c, attr_name): # field or function
2755+
for attr in self._get_class_attributes(c, attr_name):
27482756
attr_type = attr.get_type()
27492757
if not attr_type:
27502758
continue

0 commit comments

Comments
 (0)