浏览代码

make sure monomorphs are bound to Dynamic in `build_instance` (closes #4666)

Simon Krajewski 10 年之前
父节点
当前提交
fdd0cf071a
共有 4 个文件被更改,包括 26 次插入1 次删除
  1. 3 1
      codegen.ml
  2. 11 0
      tests/unit/src/unit/issues/Issue4666.hx
  3. 7 0
      tests/unit/src/unit/issues/misc/Issue4666Macro.hx
  4. 5 0
      type.ml

+ 3 - 1
codegen.ml

@@ -660,7 +660,9 @@ let build_instance ctx mtype p =
 			let r = exc_protect ctx (fun r ->
 				let t = mk_mono() in
 				r := (fun() -> t);
-				unify_raise ctx (f()) t p;
+				let tf = (f()) in
+				unify_raise ctx tf t p;
+				link_dynamic t tf;
 				t
 			) s in
 			delay ctx PForce (fun() -> ignore ((!r)()));

+ 11 - 0
tests/unit/src/unit/issues/Issue4666.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+@:genericBuild(unit.issues.misc.Issue4666Macro.getType())
+private class C { }
+
+class Issue4666 extends Test {
+	public function test() {
+		var c:C;
+		unit.TestType.typedAs(c, (null:Dynamic));
+	}
+}

+ 7 - 0
tests/unit/src/unit/issues/misc/Issue4666Macro.hx

@@ -0,0 +1,7 @@
+package unit.issues.misc;
+
+class Issue4666Macro {
+	static public function getType() {
+		return macro : Dynamic;
+	}
+}

+ 5 - 0
type.ml

@@ -1235,6 +1235,11 @@ let rec link e a b =
 		true
 	end
 
+let link_dynamic a b = match follow a,follow b with
+	| TMono r,TDynamic _ -> r := Some b
+	| TDynamic _,TMono r -> r := Some a
+	| _ -> ()
+
 let rec fast_eq a b =
 	if a == b then
 		true