Skip to content

Commit 8574c78

Browse files
committed
substitute_type_args => substitute_type
1 parent adea32d commit 8574c78

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

src/ir/types.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,9 @@ def get_supertypes(self):
124124
stack.append(supertype)
125125
return visited
126126

127-
def substitute_type_args(self, type_map,
128-
cond=lambda t: t.has_type_variables()):
129-
t = type_map.get(self)
130-
if t is None or cond(t):
131-
# Perform type substitution on the bound of the current type variable.
132-
if self.is_type_var() and self.bound is not None:
133-
new_bound = self.bound.substitute_type_args(type_map, cond)
134-
return TypeParameter(self.name, self.variance, new_bound)
135-
# The type parameter does not correspond to an abstract type
136-
# so, there is nothing to substitute.
137-
return self
138-
return t
127+
def substitute_type(self, type_map,
128+
cond=lambda t: t.has_type_variables()):
129+
return self
139130

140131
def not_related(self, other: Type):
141132
return not(self.is_subtype(other) or other.is_subtype(self))
@@ -311,6 +302,20 @@ def is_subtype(self, other):
311302
return False
312303
return self.bound.is_subtype(other)
313304

305+
def substitute_type(self, type_map,
306+
cond=lambda t: t.has_type_variables()):
307+
t = type_map.get(self)
308+
if t is None or cond(t):
309+
# Perform type substitution on the bound of the current type
310+
# variable.
311+
if self.bound is not None:
312+
new_bound = self.bound.substitute_type(type_map, cond)
313+
return TypeParameter(self.name, self.variance, new_bound)
314+
# The type parameter does not correspond to an abstract type
315+
# so, there is nothing to substitute.
316+
return self
317+
return t
318+
314319
def __eq__(self, other):
315320
return (self.__class__ == other.__class__ and
316321
self.name == other.name and
@@ -359,10 +364,10 @@ def get_type_variables(self, factory):
359364
else:
360365
return {}
361366

362-
def substitute_type_args(self, type_map,
363-
cond=lambda t: t.has_type_variables()):
367+
def substitute_type(self, type_map,
368+
cond=lambda t: t.has_type_variables()):
364369
if self.bound is not None:
365-
new_bound = self.bound.substitute_type_args(type_map, cond)
370+
new_bound = self.bound.substitute_type(type_map, cond)
366371
return WildCardType(new_bound, variance=self.variance)
367372
t = type_map.get(self)
368373
if t is None or cond(t):
@@ -414,7 +419,7 @@ def is_primitive(self):
414419

415420

416421
def substitute_type(t, type_map):
417-
return t.substitute_type_args(type_map, lambda t: False)
422+
return t.substitute_type(type_map, lambda t: False)
418423

419424

420425
def perform_type_substitution(etype, type_map,
@@ -437,7 +442,7 @@ class X<T> : Y<Z<T>>()
437442
supertypes = []
438443
for t in etype.supertypes:
439444
if t.is_parameterized():
440-
supertypes.append(t.substitute_type_args(type_map))
445+
supertypes.append(t.substitute_type(type_map))
441446
else:
442447
supertypes.append(t)
443448
type_params = []
@@ -678,10 +683,10 @@ def get_type_variables(self, factory) -> Dict[TypeParameter, Set[Type]]:
678683
continue
679684
return type_vars
680685

681-
def substitute_type_args(self, type_map, cond=lambda t: t.has_type_variables()):
686+
def substitute_type(self, type_map, cond=lambda t: t.has_type_variables()):
682687
type_args = []
683688
for t_arg in self.type_args:
684-
type_args.append(t_arg.substitute_type_args(type_map, cond))
689+
type_args.append(t_arg.substitute_type(type_map, cond))
685690
new_type_map = {
686691
tp: type_args[i]
687692
for i, tp in enumerate(self.t_constructor.type_parameters)

src/ir/typescript_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,11 @@ def is_subtype(self, other):
459459
def two_way_subtyping(self, other):
460460
return other in set(self.types)
461461

462-
def substitute_type_args(self, type_map,
463-
cond=lambda t: t.has_type_variables()):
462+
def substitute_type(self, type_map,
463+
cond=lambda t: t.has_type_variables()):
464464
new_types = []
465465
for t in self.types:
466-
new_t = (t.substitute_type_args(type_map, cond)
466+
new_t = (t.substitute_type(type_map, cond)
467467
if t.has_type_variables()
468468
else t)
469469
new_types.append(new_t)

0 commit comments

Comments
 (0)