@@ -13,12 +13,13 @@ module Tools_error = struct
1313 | `UnresolvedForwardPath
1414 (* * The module signature depends upon a forward path *)
1515 | `UnresolvedPath of
16- [ `Module of Cpath .module_ | `ModuleType of Cpath .module_type ]
16+ [ `Module of Cpath .module_ * simple_module_lookup_error
17+ | `ModuleType of Cpath .module_type * simple_module_type_lookup_error ]
1718 (* * The path to the module or module type could not be resolved *)
1819 | `UnexpandedTypeOf of Component.ModuleType .type_of_desc
1920 (* * The `module type of` expression could not be expanded *) ]
2021
21- type simple_module_lookup_error =
22+ and simple_module_lookup_error =
2223 [ `Local of Env. t * Ident. path_module
2324 (* * Internal error: Found local path during lookup *)
2425 | `Unresolved_apply (* * [`Apply] argument is not [`Resolved] *)
@@ -37,7 +38,8 @@ module Tools_error = struct
3738 | `UnresolvedForwardPath
3839 (* * The module signature depends upon a forward path *)
3940 | `UnresolvedPath of
40- [ `Module of Cpath. module_ | `ModuleType of Cpath. module_type ]
41+ [ `Module of Cpath. module_ * simple_module_lookup_error
42+ | `ModuleType of Cpath. module_type * simple_module_type_lookup_error ]
4143 | `Parent of parent_lookup_error ]
4244
4345 and simple_module_type_lookup_error =
@@ -77,19 +79,20 @@ module Tools_error = struct
7779 | simple_module_type_lookup_error
7880 | simple_module_type_expr_of_module_error
7981 | simple_module_lookup_error
80- | signature_of_module_error ]
82+ | signature_of_module_error
83+ | parent_lookup_error ]
8184
8285 let rec pp : Format.formatter -> any -> unit =
8386 fun fmt err ->
8487 match err with
8588 | `OpaqueModule -> Format. fprintf fmt " OpaqueModule"
8689 | `UnresolvedForwardPath -> Format. fprintf fmt " Unresolved forward path"
87- | `UnresolvedPath (`Module p ) ->
88- Format. fprintf fmt " Unresolved module path %a" Component.Fmt. module_path
89- p
90- | `UnresolvedPath (`ModuleType p ) ->
91- Format. fprintf fmt " Unresolved module type path %a"
92- Component.Fmt. module_type_path p
90+ | `UnresolvedPath (`Module ( p , e ) ) ->
91+ Format. fprintf fmt " Unresolved module path %a (%a) " Component.Fmt. module_path
92+ p pp (e :> any )
93+ | `UnresolvedPath (`ModuleType ( p , e ) ) ->
94+ Format. fprintf fmt " Unresolved module type path %a (%a) "
95+ Component.Fmt. module_type_path p pp (e :> any )
9396 | `LocalMT (_ , id ) -> Format. fprintf fmt " Local id found: %a" Ident. fmt id
9497 | `Local (_ , id ) -> Format. fprintf fmt " Local id found: %a" Ident. fmt id
9598 | `LocalType (_ , id ) -> Format. fprintf fmt " Local id found: %a" Ident. fmt id
@@ -111,16 +114,10 @@ module Tools_error = struct
111114 (m :> Odoc_model.Paths.Identifier.t )
112115 | `ApplyNotFunctor -> Format. fprintf fmt " Apply module is not a functor"
113116 | `Class_replaced -> Format. fprintf fmt " Class replaced"
114- | `Parent p -> pp_parent fmt p
117+ | `Parent p -> pp fmt (p :> any )
115118 | `UnexpandedTypeOf t ->
116119 Format. fprintf fmt " Unexpanded `module type of` expression: %a"
117120 Component.Fmt. module_type_type_of_desc t
118-
119-
120- and pp_parent : Format.formatter -> parent_lookup_error -> unit =
121- fun fmt err ->
122- match err with
123- | `Parent p -> pp_parent fmt p
124121 | `Parent_sig e -> Format. fprintf fmt " Parent_sig: %a" pp (e :> any )
125122 | `Parent_module_type e ->
126123 Format. fprintf fmt " Parent_module_type: %a" pp (e :> any )
@@ -129,6 +126,35 @@ module Tools_error = struct
129126 | `Fragment_root -> Format. fprintf fmt " Fragment root"
130127end
131128
129+ (* Ugh. we need to determine whether this was down to an unexpanded module type error. This is horrendous. *)
130+ let is_unexpanded_module_type_of =
131+ let open Tools_error in
132+ let rec inner : any -> bool = function
133+ | `Local _ -> false
134+ | `Find_failure -> false
135+ | `Lookup_failure _ -> false
136+ | `Unresolved_apply -> false
137+ | `Lookup_failure_root _ -> false
138+ | `Parent p -> inner (p :> any )
139+ | `Parent_sig p -> inner (p :> any )
140+ | `Parent_module_type p -> inner (p :> any )
141+ | `Parent_expr p -> inner (p :> any )
142+ | `Parent_module p -> inner (p :> any )
143+ | `Fragment_root -> false
144+ | `OpaqueModule -> false
145+ | `UnresolvedForwardPath -> false
146+ | `UnexpandedTypeOf _ -> true (* woo *)
147+ | `LocalMT _ -> false
148+ | `Lookup_failureMT _ -> false
149+ | `ApplyNotFunctor -> false
150+ | `UnresolvedPath (`Module (_ , e )) -> inner (e :> any )
151+ | `UnresolvedPath (`ModuleType (_ , e )) -> inner (e :> any )
152+ | `Lookup_failureT _ -> false
153+ | `LocalType _ -> false
154+ | `Class_replaced -> false
155+ in inner
156+
157+
132158(* * To use as [Lookup_failures.kind]. *)
133159let rec kind_of_module_cpath = function
134160 | `Root _ -> Some `Root
@@ -145,8 +171,8 @@ let rec kind_of_module_type_cpath = function
145171 | _ -> None
146172
147173let rec kind_of_error = function
148- | `UnresolvedPath (`Module cp ) -> kind_of_module_cpath cp
149- | `UnresolvedPath (`ModuleType cp ) -> kind_of_module_type_cpath cp
174+ | `UnresolvedPath (`Module ( cp , _ ) ) -> kind_of_module_cpath cp
175+ | `UnresolvedPath (`ModuleType ( cp , _ ) ) -> kind_of_module_type_cpath cp
150176 | `Lookup_failure (`Root _ ) | `Lookup_failure_root _ -> Some `Root
151177 | `Parent (`Parent_sig e ) -> kind_of_error (e :> Tools_error.any )
152178 | `Parent (`Parent_module_type e ) -> kind_of_error (e :> Tools_error.any )
0 commit comments