浏览代码

fixed recursive typedef check causing type loading issues (close #4825)

Nicolas Cannasse 9 年之前
父节点
当前提交
b8adcff95f
共有 1 个文件被更改,包括 12 次插入6 次删除
  1. 12 6
      src/typing/typeload.ml

+ 12 - 6
src/typing/typeload.ml

@@ -3195,13 +3195,19 @@ let init_module_type ctx context_init do_init (decl,p) =
 		check_global_metadata ctx (fun m -> t.t_meta <- m :: t.t_meta) t.t_module.m_path t.t_path None;
 		let ctx = { ctx with type_params = t.t_params } in
 		let tt = load_complex_type ctx p d.d_data in
-		(*
-			we exceptionnaly allow follow here because we don't care the type we get as long as it's not our own
-		*)
-		(match d.d_data with
-		| CTExtend _ -> ()
+		let tt = (match d.d_data with
+		| CTExtend _ -> tt
+		| CTPath { tpackage = ["haxe";"macro"]; tname = "MacroType" } ->
+			(* we need to follow MacroType immediately since it might define other module types that we will load afterwards *)
+			if t.t_type == follow tt then error "Recursive typedef is not allowed" p;
+			tt
 		| _ ->
-			if t.t_type == follow tt then error "Recursive typedef is not allowed" p);
+			TLazy (exc_protect ctx (fun r ->
+				if t.t_type == follow tt then error "Recursive typedef is not allowed" p;
+				r := (fun() -> tt);
+				tt
+			) "typedef_rec_check")
+		) in
 		(match t.t_type with
 		| TMono r ->
 			(match !r with