diff --git a/toy-impl/inference.py b/toy-impl/inference.py index 9eab2e5..9be17ad 100644 --- a/toy-impl/inference.py +++ b/toy-impl/inference.py @@ -32,6 +32,8 @@ def find_subst(ctx: dict[str, Type], else: if a not in b.constraints: return f"{b} cannot take value of {a}" + if a == b: + return sub if b in a.get_vars(): return "Recursive type is not supported" sub[b.name] = a diff --git a/toy-impl/test_subst.py b/toy-impl/test_subst.py index 575dc20..c852ec9 100644 --- a/toy-impl/test_subst.py +++ b/toy-impl/test_subst.py @@ -53,6 +53,7 @@ try_case(ListType(i32), ListType(i32), {}) try_case(TupleType([X, X]), TupleType([X, Y]), {}) try_case(TupleType([X, X]), TupleType([Y, Y]), {}) try_case(TupleType([X, Y]), TupleType([X, X]), {}) +try_case(TupleType([X, X]), TupleType([X, X]), {}) try_case(TupleType([X, Y]), X, {}) try_case(TupleType([i32, Y]), X, {})