Nicolas Cannasse 8 years ago
parent
commit
e1b729245d
2 changed files with 31 additions and 2 deletions
  1. 11 2
      src/typing/type.ml
  2. 20 0
      tests/unit/compiler_loops/Issue5189.hx

+ 11 - 2
src/typing/type.ml

@@ -2195,8 +2195,17 @@ and unify_with_variance f t1 t2 =
 	| t,TAbstract(a,pl) ->
 	| t,TAbstract(a,pl) ->
 		type_eq EqBothDynamic t (apply_params a.a_params pl a.a_this);
 		type_eq EqBothDynamic t (apply_params a.a_params pl a.a_this);
 		if not (List.exists (fun t2 -> allows_variance_to t (apply_params a.a_params pl t2)) a.a_from) then error [cannot_unify t1 t2]
 		if not (List.exists (fun t2 -> allows_variance_to t (apply_params a.a_params pl t2)) a.a_from) then error [cannot_unify t1 t2]
-	| TAnon a1,TAnon a2 ->
-		unify_anons t1 t2 a1 a2
+	| (TAnon a1 as t1), (TAnon a2 as t2) ->
+		if not (List.exists (fun (a,b) -> fast_eq a t1 && fast_eq b t2) (!unify_stack)) then begin
+			try
+				unify_stack := (t1,t2) :: !unify_stack;
+				unify_anons t1 t2 a1 a2;
+				unify_stack := List.tl !unify_stack;
+			with
+				Unify_error l ->
+					unify_stack := List.tl !unify_stack;
+					error l
+		end
 	| _ ->
 	| _ ->
 		error [cannot_unify t1 t2]
 		error [cannot_unify t1 t2]
 
 

+ 20 - 0
tests/unit/compiler_loops/Issue5189.hx

@@ -0,0 +1,20 @@
+typedef TT_A = {
+    a : Int,
+    b : String,
+    c : Array<TT_A>
+}
+
+typedef TT_B = {
+    a : Int,
+    b : String,
+    c : Array<TT_B>,
+    d : Float
+}
+class Main {
+
+    static var tt_a : TT_A = { a:1, b:"", c: []};
+
+    static function main(){
+        var ttb:TT_B = tt_a;
+    }
+}