diff --git a/compiler/shared_ast/program.ml b/compiler/shared_ast/program.ml index 2dd81cd3..dc807647 100644 --- a/compiler/shared_ast/program.ml +++ b/compiler/shared_ast/program.ml @@ -122,6 +122,10 @@ let rename_ids let module PathMap = Map.Make (Uid.Path) in let pctxmap = PathMap.singleton [] ctx in let pctxmap, structs_map, fields_map, ctx_structs = + (* Warning: the folding order matters here, if a module contains e.g. two + fields with the same name. This fold relies on UIDs, and is thus + dependent on the definition order. Another possibility would be to fold + lexicographically, but the result would be "less intuitive" *) StructName.Map.fold (fun name fields (pctxmap, structs_map, fields_map, ctx_structs) -> let path = StructName.path name in diff --git a/compiler/surface/parser_driver.ml b/compiler/surface/parser_driver.ml index c317db7b..bdd0540a 100644 --- a/compiler/surface/parser_driver.ml +++ b/compiler/surface/parser_driver.ml @@ -476,7 +476,8 @@ let get_interface program = (* Non-metadata blocks are ignored *) req, acc in - List.fold_left filter ([], []) program.Ast.program_items + let req, acc = List.fold_left filter ([], []) program.Ast.program_items in + List.rev req, List.rev acc (** {1 API} *)