Fix module name propagation

This commit is contained in:
Louis Gesbert 2023-10-13 16:13:02 +02:00
parent f25e38a6d7
commit 3b0e576a24
2 changed files with 16 additions and 15 deletions

View File

@ -76,7 +76,6 @@ let rec all_scopes code_item_list =
let to_expr p main_scope =
let _, main_scope_body = find_scope main_scope [] p.code_items in
let res =
Scope.unfold p.decl_ctx p.code_items
(Scope.get_body_mark main_scope_body)

View File

@ -263,19 +263,21 @@ and expand_includes (source_file : string) (commands : Ast.law_structure list) :
let rprg =
List.fold_left
(fun acc command ->
match command with
| Ast.ModuleDef id -> (
match acc.Ast.program_module_name with
| None ->
{
acc with
Ast.program_module_name = Some id;
Ast.program_items = command :: acc.Ast.program_items;
}
| Some id2 ->
let join_module_names name_opt =
match acc.Ast.program_module_name, name_opt with
| opt, None | None, opt -> opt
| Some id1, Some id2 ->
Message.raise_multispanned_error
[None, Mark.get id; None, Mark.get id2]
"Multiple definitions of the module name")
[None, Mark.get id1; None, Mark.get id2]
"Multiple definitions of the module name"
in
match command with
| Ast.ModuleDef id ->
{
acc with
Ast.program_module_name = join_module_names (Some id);
Ast.program_items = command :: acc.Ast.program_items;
}
| Ast.ModuleUse (id, _alias) ->
{
acc with
@ -303,7 +305,7 @@ and expand_includes (source_file : string) (commands : Ast.law_structure list) :
Uid.Module.format (Uid.Module.of_string id)
in
{
Ast.program_module_name = None;
Ast.program_module_name = acc.program_module_name;
Ast.program_source_files =
List.rev_append includ_program.program_source_files
acc.Ast.program_source_files;
@ -325,7 +327,7 @@ and expand_includes (source_file : string) (commands : Ast.law_structure list) :
expand_includes source_file commands'
in
{
Ast.program_module_name;
Ast.program_module_name = join_module_names program_module_name;
Ast.program_source_files =
List.rev_append new_sources acc.Ast.program_source_files;
Ast.program_items =