Răsfoiți Sursa

Disallow defining types into existing modules (#11845)

* disallow defining types into existing modules

* only disallow for foreign modules
Simon Krajewski 9 luni în urmă
părinte
comite
ec7c9bad91
1 a modificat fișierele cu 7 adăugiri și 1 ștergeri
  1. 7 1
      src/typing/macroContext.ml

+ 7 - 1
src/typing/macroContext.ml

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