@@ -27,14 +27,17 @@ let lazy_env =
2727 Compat. init_path () ;
2828 Ocaml_common.Compmisc. initial_env () )
2929
30- let string_of_lid lid =
31- let rec print lid acc =
32- match lid with
33- | Longident. Lident s -> s :: acc
34- | Longident. Ldot (lid , id ) -> print lid (" ." :: id :: acc)
35- | Longident. Lapply (la , lb ) -> print la (" (" :: print lb (" )" :: acc))
36- in
37- String. concat " " (print lid [] )
30+ let string_of_lid' lid = Format. asprintf " %a" Pprintast. longident lid
31+ let string_of_lid lid = Format. asprintf " %a" Astlib.Pprintast. longident lid
32+
33+ (* Remove locations *)
34+ let rec longident_without_loc =
35+ let proj x = Compat. longident_proj x in
36+ let conv x = longident_without_loc (proj x) in
37+ function
38+ | Longident. Ldot (x ,y ) -> Astlib.Longident. Ldot (conv x, proj y)
39+ | Longident. Lapply (f ,x ) -> Astlib.Longident. Lapply (conv f, conv x)
40+ | Longident. Lident x -> Astlib.Longident. Lident x
3841
3942let try_find_module ~loc env lid =
4043 (* Note: we are careful to call `Env.lookup_module` and not
@@ -68,7 +71,7 @@ let try_find_module_type ~loc env lid =
6871 | None ->
6972 Location. raise_errorf ~loc
7073 " [%%import]: cannot access the signature of the abstract module %s"
71- (string_of_lid lid)
74+ (string_of_lid' lid)
7275 | Some module_type -> module_type )
7376 with Not_found -> None
7477
@@ -93,12 +96,16 @@ let open_module_type ~loc env lid module_type =
9396let locate_sig ~loc env lid =
9497 let head, path =
9598 match Ppxlib.Longident. flatten_exn lid with
96- | head :: path -> (Longident. Lident head, path)
99+ | head :: path -> (head, path)
97100 | _ -> assert false
101+ | exception Invalid_argument _ ->
102+ Location. raise_errorf ~loc
103+ " [%%import] cannot import a functor application %s"
104+ (string_of_lid lid)
98105 in
106+ let chead = Longident. Lident head in
99107 let head_module_type =
100- match
101- (try_find_module ~loc env head, lazy (try_find_module_type ~loc env head))
108+ match (try_find_module ~loc env chead, lazy (try_find_module_type ~loc env chead))
102109 with
103110 | Some mty , _ -> mty
104111 | None , (lazy (Some mty )) -> mty
@@ -124,10 +131,10 @@ let locate_sig ~loc env lid =
124131 let sub_module_type =
125132 loop (List. map Compat. migrate_signature_item sig_items)
126133 in
127- (Longident. Ldot (lid, path_item), sub_module_type)
134+ (Astlib. Longident.Ldot (lid,path_item), sub_module_type)
128135 in
129136 let _lid, sub_module_type =
130- List. fold_left get_sub_module_type (head, head_module_type) path
137+ List. fold_left get_sub_module_type (Astlib.Longident. Lident head, head_module_type) path
131138 in
132139 open_module_type ~loc env lid sub_module_type
133140
@@ -164,7 +171,7 @@ let get_modtype_decl ~loc sig_items parent_lid elem =
164171 elem (string_of_lid parent_lid)
165172 | Some decl -> decl
166173
167- let longident_of_path = Untypeast. lident_of_path
174+ let longident_of_path x = longident_without_loc ( Untypeast. lident_of_path x)
168175
169176let mknoloc (txt : 'a ) : 'a Ppxlib.Location.loc =
170177 {txt; loc = Ppxlib.Location. none}
@@ -187,8 +194,7 @@ let rec core_type_of_type_expr ~subst (type_expr : Ocaml_common.Types.type_expr)
187194 | _ -> lhs
188195 in
189196 Ppxlib.Ast_helper.Typ. arrow label lhs (core_type_of_type_expr ~subst rhs)
190- | Ttuple xs ->
191- Ppxlib.Ast_helper.Typ. tuple (List. map (core_type_of_type_expr ~subst ) xs)
197+ | Ttuple xs -> Compat. tuple (core_type_of_type_expr ~subst ) xs
192198 | Tconstr (path , args , _ ) -> (
193199 let lid = longident_of_path path in
194200 let args = List. map (core_type_of_type_expr ~subst ) args in
@@ -387,11 +393,11 @@ let type_declaration ~tool_name ~input_name (type_decl : Ppxlib.type_declaration
387393 Location. raise_errorf ~loc
388394 " [%%import] cannot import a functor application %s"
389395 (string_of_lid lid)
390- | Lident _ as head_id ->
396+ | Lident hid ->
391397 (* In this case, we know for sure that the user intends this lident
392398 as a type name, so we use Typetexp.find_type and let the failure
393399 cases propagate to the user. *)
394- Compat. find_type env ~loc head_id |> snd
400+ Compat. find_type env ~loc ( Lident hid) |> snd
395401 | Ldot (parent_id , elem ) ->
396402 let sig_items = locate_sig ~loc env parent_id in
397403 get_type_decl ~loc sig_items parent_id elem
@@ -484,11 +490,11 @@ let module_type ~tool_name ~input_name (package_type : Ppxlib.package_type) =
484490 Location. raise_errorf ~loc
485491 " [%%import] cannot import a functor application %s"
486492 (string_of_lid lid)
487- | Longident. Lident _ as head_id ->
493+ | Longident. Lident head_id ->
488494 (* In this case, we know for sure that the user intends this lident
489495 as a module type name, so we use Typetexp.find_type and
490496 let the failure cases propagate to the user. *)
491- Compat. find_modtype env ~loc head_id |> snd
497+ Compat. find_modtype env ~loc ( Lident head_id) |> snd
492498 | Longident. Ldot (parent_id , elem ) ->
493499 let sig_items = locate_sig ~loc env parent_id in
494500 get_modtype_decl ~loc sig_items parent_id elem
0 commit comments