Browse Source

fix type_eq loop for recursive typedefs (#9428)

Aleksandr Kuzmenko 5 years ago
parent
commit
37c475beb8

+ 2 - 2
src/core/tUnification.ml

@@ -307,11 +307,11 @@ let rec type_eq uctx a b =
 	| TType (t1,tl1), TType (t2,tl2) when (t1 == t2 || (param = EqCoreType && t1.t_path = t2.t_path)) && List.length tl1 = List.length tl2 ->
 		type_eq_params uctx a b tl1 tl2
 	| TType (t,tl) , _ when can_follow a ->
-		type_eq uctx (apply_params t.t_params tl t.t_type) b
+		try_apply_params_rec t.t_params tl t.t_type (fun a -> type_eq uctx a b)
 	| _ , TType (t,tl) when can_follow b ->
 		rec_stack eq_stack (a,b)
 			(fun (a2,b2) -> fast_eq a a2 && fast_eq b b2)
-			(fun() -> type_eq uctx a (apply_params t.t_params tl t.t_type))
+			(fun() -> try_apply_params_rec t.t_params tl t.t_type (type_eq uctx a))
 			(fun l -> error (cannot_unify a b :: l))
 	| TEnum (e1,tl1) , TEnum (e2,tl2) ->
 		if e1 != e2 && not (param = EqCoreType && e1.e_path = e2.e_path) then error [cannot_unify a b];

+ 13 - 0
tests/misc/compiler_loops/projects/Issue9428/TypedefTypedef.hx

@@ -0,0 +1,13 @@
+typedef Rec1<T> = {
+	function then<TResult>():Rec1<TResult>;
+}
+
+typedef Rec2<T> = {
+	function then<TOut>():Rec2<TOut>;
+}
+
+class TypedefTypedef {
+	static function main() {
+		var r:Rec1<Void> = (null:Rec2<Void>);
+	}
+}

+ 1 - 0
tests/misc/compiler_loops/projects/Issue9428/typedefTypedef.hxml

@@ -0,0 +1 @@
+-main TypedefTypedef