浏览代码

Fix defineModule into curmod

Rudy Ges 7 月之前
父节点
当前提交
f9dfd111bb
共有 1 个文件被更改,包括 6 次插入4 次删除
  1. 6 4
      src/typing/macroContext.ml

+ 6 - 4
src/typing/macroContext.ml

@@ -500,14 +500,16 @@ let make_macro_api ctx mctx p =
 			let types = imports @ usings @ types in
 			let types = imports @ usings @ types in
 			let mpath = Ast.parse_path m in
 			let mpath = Ast.parse_path m in
 			begin try
 			begin try
-				let m_extra = !TypeloadCacheHook.find_module_extra_hook ctx.com mpath in
-				if mpath != ctx.m.curmod.m_path then begin
+				let m = try Some (ctx.com.module_lut#find mpath) with Not_found -> None in
+				if Option.is_some m && Option.get m == ctx.m.curmod then
+					ignore(TypeloadModule.type_types_into_module ctx.com ctx.g ctx.m.curmod types pos)
+				else begin
+					let m_extra = match m with Some m -> m.m_extra | None -> !TypeloadCacheHook.find_module_extra_hook ctx.com mpath in
 					let pos = { pfile = (Path.UniqueKey.lazy_path m_extra.m_file); pmin = 0; pmax = 0 } in
 					let pos = { pfile = (Path.UniqueKey.lazy_path m_extra.m_file); pmin = 0; pmax = 0 } in
 					raise_typing_error_ext (make_error ~sub:[
 					raise_typing_error_ext (make_error ~sub:[
 						make_error ~depth:1 (Custom "Previously defined here") pos
 						make_error ~depth:1 (Custom "Previously defined here") pos
 					] (Custom (Printf.sprintf "Cannot redefine module %s" (s_type_path mpath))) p);
 					] (Custom (Printf.sprintf "Cannot redefine module %s" (s_type_path mpath))) p);
-				end else
-					ignore(TypeloadModule.type_types_into_module ctx.com ctx.g ctx.m.curmod types pos)
+				end
 			with Not_found ->
 			with Not_found ->
 				let mnew = TypeloadModule.type_module ctx.com ctx.g mpath (ctx.com.file_keys#generate_virtual mpath ctx.com.compilation_step) types pos in
 				let mnew = TypeloadModule.type_module ctx.com ctx.g mpath (ctx.com.file_keys#generate_virtual mpath ctx.com.compilation_step) types pos in
 				mnew.m_extra.m_kind <- MFake;
 				mnew.m_extra.m_kind <- MFake;