Skip to content

Commit 5e98f65

Browse files
committed
Fix update of chains of bounded type parameters
1 parent 52d4a80 commit 5e98f65

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/ir/type_utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,12 @@ def update_type_var_bound_rec(t_param: tp.TypeParameter,
522522
return
523523
try:
524524
current_t = type_var_map[bound]
525-
if t.is_subtype(current_t):
526-
# The current assignment for the type variable corresponding to
527-
# the upper bound of 't_param' is supertype of 't'. So we don't
528-
# have to update anything.
529-
return
530-
t_args[indexes[bound]] = t
531-
type_var_map[bound] = t
525+
if not t.is_subtype(current_t):
526+
t_args[indexes[bound]] = t
527+
type_var_map[bound] = t
528+
# The current assignment for the type variable corresponding to
529+
# the upper bound of 't_param' is supertype of 't'. So we don't
530+
# have to update anything.
532531
except KeyError:
533532
# This KeyError happens only if a given type parameter has bound
534533
# corresponding to a type variable of a type constructor. In this

tests/test_type_utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,24 @@ def test_instantiate_type_constructor_with_type_var_map():
10621062
type_param3: type_var
10631063
}
10641064

1065+
# Case 4: T1, T2 : T1, T3: T2 (type map = {T3: String})
1066+
type_param1 = tp.TypeParameter("T1")
1067+
type_param2 = tp.TypeParameter("T2", bound=type_param1)
1068+
type_param3 = tp.TypeParameter("T3", bound=type_param2)
1069+
type_map = {type_param3: kt.String}
1070+
types = [kt.Number]
1071+
t_con = tp.TypeConstructor("Con", [type_param1, type_param2, type_param3])
1072+
ptype, params = tutils.instantiate_type_constructor(
1073+
t_con, types=types, type_var_map=type_map)
1074+
assert ptype.type_args == [kt.String,
1075+
kt.String,
1076+
kt.String]
1077+
assert params == {
1078+
type_param1: kt.String,
1079+
type_param2: kt.String,
1080+
type_param3: kt.String
1081+
}
1082+
10651083

10661084
def test_unify_types():
10671085
factory = kt.KotlinBuiltinFactory()

0 commit comments

Comments
 (0)