@@ -4674,29 +4674,30 @@ and type_expect_
46744674 let ty = newvar() in
46754675 (* remember original level *)
46764676 begin_def () ;
4677- Typetexp. narrow () ;
4678- let modl, md_shape = ! type_module env smodl in
4679- Mtype. lower_nongen (get_level ty) modl.mod_type;
4680- let pres =
4681- match modl.mod_type with
4682- | Mty_alias _ -> Mp_absent
4683- | _ -> Mp_present
4684- in
4685- let scope = create_scope () in
4686- let md =
4687- { md_type = modl.mod_type; md_attributes = [] ; md_loc = name.loc;
4688- md_uid = Uid. mk ~current_unit: (Env. get_unit_name () ); }
4689- in
4690- let (id, new_env) =
4691- match name.txt with
4692- | None -> None , env
4693- | Some name ->
4694- let id, env =
4695- Env. enter_module_declaration ~scope ~shape: md_shape name pres md env
4696- in
4697- Some id, env
4698- in
4699- Typetexp. widen () ;
4677+ let modl, pres, id, new_env = Typetexp. narrow_in begin fun () ->
4678+ let modl, md_shape = ! type_module env smodl in
4679+ Mtype. lower_nongen (get_level ty) modl.mod_type;
4680+ let pres =
4681+ match modl.mod_type with
4682+ | Mty_alias _ -> Mp_absent
4683+ | _ -> Mp_present
4684+ in
4685+ let scope = create_scope () in
4686+ let md =
4687+ { md_type = modl.mod_type; md_attributes = [] ; md_loc = name.loc;
4688+ md_uid = Uid. mk ~current_unit: (Env. get_unit_name () ); }
4689+ in
4690+ let (id, new_env) =
4691+ match name.txt with
4692+ | None -> None , env
4693+ | Some name ->
4694+ let id, env =
4695+ Env. enter_module_declaration ~scope ~shape: md_shape name pres md env
4696+ in
4697+ Some id, env
4698+ in
4699+ modl, pres, id, new_env
4700+ end in
47004701 (* ideally, we should catch Expr_type_clash errors
47014702 in type_expect triggered by escaping identifiers from the local module
47024703 and refine them into Scoping_let_module errors
@@ -6075,33 +6076,33 @@ and type_unpacks ?(in_function : (Location.t * type_expr * bool) option)
60756076 let extended_env, tunpacks =
60766077 List. fold_left (fun (env , tunpacks ) unpack ->
60776078 begin_def () ;
6078- Typetexp. narrow () ;
6079- let modl, md_shape =
6080- ! type_module env
6081- Ast_helper. (
6082- Mod. unpack ~loc: unpack.tu_loc
6083- (Exp. ident ~loc: unpack.tu_name.loc
6084- (mkloc (Longident. Lident unpack.tu_name.txt)
6085- unpack.tu_name.loc)))
6086- in
6087- Mtype. lower_nongen (get_level ty) modl.mod_type;
6088- let pres =
6089- match modl.mod_type with
6090- | Mty_alias _ -> Mp_absent
6091- | _ -> Mp_present
6092- in
6093- let scope = create_scope () in
6094- let md =
6095- { md_type = modl.mod_type; md_attributes = [] ;
6096- md_loc = unpack.tu_name.loc;
6097- md_uid = unpack.tu_uid; }
6098- in
6099- let (id, env) =
6100- Env. enter_module_declaration ~scope ~shape: md_shape
6101- unpack.tu_name.txt pres md env
6102- in
6103- Typetexp. widen () ;
6104- env, (id, unpack.tu_name, pres, modl) :: tunpacks
6079+ Typetexp. narrow_in begin fun () ->
6080+ let modl, md_shape =
6081+ ! type_module env
6082+ Ast_helper. (
6083+ Mod. unpack ~loc: unpack.tu_loc
6084+ (Exp. ident ~loc: unpack.tu_name.loc
6085+ (mkloc (Longident. Lident unpack.tu_name.txt)
6086+ unpack.tu_name.loc)))
6087+ in
6088+ Mtype. lower_nongen (get_level ty) modl.mod_type;
6089+ let pres =
6090+ match modl.mod_type with
6091+ | Mty_alias _ -> Mp_absent
6092+ | _ -> Mp_present
6093+ in
6094+ let scope = create_scope () in
6095+ let md =
6096+ { md_type = modl.mod_type; md_attributes = [] ;
6097+ md_loc = unpack.tu_name.loc;
6098+ md_uid = unpack.tu_uid; }
6099+ in
6100+ let (id, env) =
6101+ Env. enter_module_declaration ~scope ~shape: md_shape
6102+ unpack.tu_name.txt pres md env
6103+ in
6104+ env, (id, unpack.tu_name, pres, modl) :: tunpacks
6105+ end
61056106 ) (env, [] ) unpacks
61066107 in
61076108 (* ideally, we should catch Expr_type_clash errors
0 commit comments