Restore proper error message when opening a functor.
parent
a2bc899a7e
commit
1cad974131
|
@ -1745,13 +1745,7 @@ let rec add_signature sg env =
|
|||
|
||||
(* Open a signature path *)
|
||||
|
||||
let open_signature slot root env0 =
|
||||
let comps =
|
||||
match get_components (find_module_descr root env0) with
|
||||
| Structure_comps c -> c
|
||||
| Functor_comps _ -> assert false
|
||||
in
|
||||
|
||||
let add_components slot root env0 comps =
|
||||
let add_l w comps env0 =
|
||||
Tbl.fold
|
||||
(fun name ->
|
||||
|
@ -1815,10 +1809,18 @@ let open_signature slot root env0 =
|
|||
modules;
|
||||
}
|
||||
|
||||
let open_signature slot root env0 =
|
||||
match get_components (find_module_descr root env0) with
|
||||
| Functor_comps _ -> None
|
||||
| Structure_comps comps -> Some (add_components slot root env0 comps)
|
||||
|
||||
|
||||
(* Open a signature from a file *)
|
||||
|
||||
let open_pers_signature name env =
|
||||
open_signature None (Pident(Ident.create_persistent name)) env
|
||||
match open_signature None (Pident(Ident.create_persistent name)) env with
|
||||
| Some env -> env
|
||||
| None -> assert false (* a compilation unit cannot refer to a functor *)
|
||||
|
||||
let open_signature ?(loc = Location.none) ?(toplevel = false) ovf root env =
|
||||
if not toplevel && ovf = Asttypes.Fresh && not loc.Location.loc_ghost
|
||||
|
|
|
@ -153,11 +153,12 @@ val add_item: signature_item -> t -> t
|
|||
val add_signature: signature -> t -> t
|
||||
|
||||
(* Insertion of all fields of a signature, relative to the given path.
|
||||
Used to implement open. *)
|
||||
|
||||
Used to implement open. Returns None if the path refers to a functor,
|
||||
not a structure. *)
|
||||
val open_signature:
|
||||
?loc:Location.t -> ?toplevel:bool -> Asttypes.override_flag -> Path.t ->
|
||||
t -> t
|
||||
t -> t option
|
||||
|
||||
val open_pers_signature: string -> t -> t
|
||||
|
||||
(* Insertion by name *)
|
||||
|
|
|
@ -63,7 +63,10 @@ let rec env_from_summary sum subst =
|
|||
| Env_open(s, path) ->
|
||||
let env = env_from_summary s subst in
|
||||
let path' = Subst.module_path subst path in
|
||||
Env.open_signature Asttypes.Override path' env
|
||||
begin match Env.open_signature Asttypes.Override path' env with
|
||||
| Some env -> env
|
||||
| None -> assert false
|
||||
end
|
||||
| Env_functor_arg(Env_module(s, id, desc), id') when Ident.same id id' ->
|
||||
Env.add_module_declaration ~check:false
|
||||
id (Subst.module_declaration subst desc)
|
||||
|
|
|
@ -84,8 +84,12 @@ let extract_sig_open env loc mty =
|
|||
|
||||
let type_open_ ?toplevel ovf env loc lid =
|
||||
let path = Typetexp.lookup_module ~load:true env lid.loc lid.txt in
|
||||
(* TODO: handle same errors as in extract_sig_open *)
|
||||
path, Env.open_signature ~loc ?toplevel ovf path env
|
||||
match Env.open_signature ~loc ?toplevel ovf path env with
|
||||
| Some env -> path, env
|
||||
| None ->
|
||||
let md = Env.find_module path env in
|
||||
ignore (extract_sig_open env lid.loc md.md_type);
|
||||
assert false
|
||||
|
||||
let type_open ?toplevel env sod =
|
||||
let (path, newenv) =
|
||||
|
|
Loading…
Reference in New Issue