@@ -33,14 +33,17 @@ let lazy_env =
3333 Compat. init_path () ;
3434 Ocaml_common.Compmisc. initial_env () )
3535
36- let string_of_lid lid =
37- let rec print lid acc =
38- match lid with
39- | Longident. Lident s -> s :: acc
40- | Longident. Ldot (lid , id ) -> print lid (" ." :: id :: acc)
41- | Longident. Lapply (la , lb ) -> print la (" (" :: print lb (" )" :: acc))
42- in
43- String. concat " " (print lid [] )
36+ let string_of_lid' lid = Format. asprintf " %a" Pprintast. longident lid
37+ let string_of_lid lid = Format. asprintf " %a" Astlib.Pprintast. longident lid
38+
39+ (* Remove locations *)
40+ let rec longident_without_loc =
41+ let proj x = Compat. longident_proj x in
42+ let conv x = longident_without_loc (proj x) in
43+ function
44+ | Longident. Ldot (x ,y ) -> Astlib.Longident. Ldot (conv x, proj y)
45+ | Longident. Lapply (f ,x ) -> Astlib.Longident. Lapply (conv f, conv x)
46+ | Longident. Lident x -> Astlib.Longident. Lident x
4447
4548let try_find_module ~loc env lid =
4649 (* Note: we are careful to call `Env.lookup_module` and not
@@ -75,7 +78,7 @@ let try_find_module_type ~loc env lid =
7578 let error =
7679 Printf. sprintf
7780 " [%%import]: cannot access the signature of the abstract module %s"
78- (string_of_lid lid)
81+ (string_of_lid' lid)
7982 in
8083 raise_error ~loc error
8184 | Some module_type -> module_type )
@@ -106,7 +109,7 @@ let locate_sig ~loc env lid =
106109 let head, path =
107110 try
108111 match Ppxlib.Longident. flatten_exn lid with
109- | head :: path -> (Longident. Lident head, path)
112+ | head :: path -> (head, path)
110113 | _ -> assert false
111114 with Invalid_argument _ ->
112115 let error =
@@ -115,9 +118,9 @@ let locate_sig ~loc env lid =
115118 in
116119 raise_error ~loc error
117120 in
121+ let chead = Longident. Lident head in
118122 let head_module_type =
119- match
120- (try_find_module ~loc env head, lazy (try_find_module_type ~loc env head))
123+ match (try_find_module ~loc env chead, lazy (try_find_module_type ~loc env chead))
121124 with
122125 | Some mty , _ -> mty
123126 | None , (lazy (Some mty )) -> mty
@@ -147,10 +150,10 @@ let locate_sig ~loc env lid =
147150 let sub_module_type =
148151 loop (List. map Compat. migrate_signature_item sig_items)
149152 in
150- (Longident. Ldot (lid, path_item), sub_module_type)
153+ (Astlib. Longident.Ldot (lid,path_item), sub_module_type)
151154 in
152155 let _lid, sub_module_type =
153- List. fold_left get_sub_module_type (head, head_module_type) path
156+ List. fold_left get_sub_module_type (Astlib.Longident. Lident head, head_module_type) path
154157 in
155158 open_module_type ~loc env lid sub_module_type
156159
@@ -193,7 +196,7 @@ let get_modtype_decl ~loc sig_items parent_lid elem =
193196 raise_error ~loc error
194197 | Some decl -> decl
195198
196- let longident_of_path = Untypeast. lident_of_path
199+ let longident_of_path x = longident_without_loc ( Untypeast. lident_of_path x)
197200
198201let mknoloc (txt : 'a ) : 'a Ppxlib.Location.loc =
199202 {txt; loc = Ppxlib.Location. none}
@@ -216,8 +219,7 @@ let rec core_type_of_type_expr ~subst (type_expr : Ocaml_common.Types.type_expr)
216219 | _ -> lhs
217220 in
218221 Ppxlib.Ast_helper.Typ. arrow label lhs (core_type_of_type_expr ~subst rhs)
219- | Ttuple xs ->
220- Ppxlib.Ast_helper.Typ. tuple (List. map (core_type_of_type_expr ~subst ) xs)
222+ | Ttuple xs -> Compat. tuple (core_type_of_type_expr ~subst ) xs
221223 | Tconstr (path , args , _ ) -> (
222224 let lid = longident_of_path path in
223225 let args = List. map (core_type_of_type_expr ~subst ) args in
@@ -426,11 +428,11 @@ let type_declaration ~tool_name ~input_name (type_decl : Ppxlib.type_declaration
426428 (string_of_lid lid)
427429 in
428430 raise_error ~loc error
429- | Lident _ as head_id ->
431+ | Lident hid ->
430432 (* In this case, we know for sure that the user intends this lident
431433 as a type name, so we use Typetexp.find_type and let the failure
432434 cases propagate to the user. *)
433- Compat. find_type env ~loc head_id |> snd
435+ Compat. find_type env ~loc ( Lident hid) |> snd
434436 | Ldot (parent_id , elem ) ->
435437 let sig_items = locate_sig ~loc env parent_id in
436438 get_type_decl ~loc sig_items parent_id elem
@@ -531,11 +533,11 @@ let module_type ~tool_name ~input_name (package_type : Ppxlib.package_type) =
531533 (string_of_lid lid)
532534 in
533535 raise_error ~loc error
534- | Longident. Lident _ as head_id ->
536+ | Longident. Lident head_id ->
535537 (* In this case, we know for sure that the user intends this lident
536538 as a module type name, so we use Typetexp.find_type and
537539 let the failure cases propagate to the user. *)
538- Compat. find_modtype env ~loc head_id |> snd
540+ Compat. find_modtype env ~loc ( Lident head_id) |> snd
539541 | Longident. Ldot (parent_id , elem ) ->
540542 let sig_items = locate_sig ~loc env parent_id in
541543 get_modtype_decl ~loc sig_items parent_id elem
0 commit comments