Skip to content

Commit

Permalink
Disallow defining types into existing modules (#11845)
Browse files Browse the repository at this point in the history
* disallow defining types into existing modules

* only disallow for foreign modules
  • Loading branch information
Simn authored Nov 27, 2024
1 parent cf6b36c commit ec7c9ba
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ec7c9ba

Please sign in to comment.