瀏覽代碼

[typer] tentatively bind monomorphs before checking constraints

closes #9603
Simon Krajewski 5 年之前
父節點
當前提交
42cd68b21a
共有 2 個文件被更改,包括 21 次插入1 次删除
  1. 4 1
      src/core/tUnification.ml
  2. 17 0
      tests/unit/src/unit/issues/Issue9603.hx

+ 4 - 1
src/core/tUnification.ml

@@ -141,7 +141,10 @@ module Monomorph = struct
 				bind m t
 			end
 		| _ ->
-			check_constraints m t;
+			(* Due to recursive constraints like in #9603, we tentatively bind the monomorph to the type we're checking
+			   against before checking the constraints. *)
+			m.tm_type <- Some t;
+			Std.finally (fun () -> m.tm_type <- None) (fun () -> check_constraints m t) ();
 			do_bind m t
 		end
 

+ 17 - 0
tests/unit/src/unit/issues/Issue9603.hx

@@ -0,0 +1,17 @@
+package unit.issues;
+import unit.Test;
+
+function sort<T:{next:T}>(l:T) {}
+
+private class C {
+	public var next:C;
+
+	public function new() {}
+}
+
+class Issue9603 extends Test {
+	function test() {
+		sort(new C());
+		utest.Assert.pass();
+	}
+}