@@ -264,13 +264,29 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
264264 let async_saved = ! async_context in
265265 let result = expr_mapper ~async_context ~in_function_def self e in
266266 async_context := async_saved;
267- match Ast_attributes. has_await_payload e.pexp_attributes with
267+ let is_module, has_await =
268+ match e.pexp_desc with
269+ | Pexp_letmodule (_, {pmod_desc = Pmod_ident _; pmod_attributes}, _)
270+ | Pexp_letmodule
271+ ( _,
272+ {
273+ pmod_desc =
274+ Pmod_constraint
275+ ({pmod_desc = Pmod_ident _}, {pmty_desc = Pmty_ident _});
276+ pmod_attributes;
277+ },
278+ _ ) ->
279+ (true , Ast_attributes. has_await_payload pmod_attributes)
280+ | _ -> (false , Ast_attributes. has_await_payload e.pexp_attributes)
281+ in
282+ match has_await with
268283 | None -> result
269284 | Some _ ->
270285 if ! async_context = false then
271286 Location. raise_errorf ~loc: e.pexp_loc
272287 " Await on expression not in an async context" ;
273- Ast_await. create_await_expression result
288+ if is_module = false then Ast_await. create_await_expression result
289+ else result
274290
275291let typ_mapper (self : mapper ) (typ : Parsetree.core_type ) =
276292 Ast_core_type_class_type. typ_mapper self typ
@@ -604,6 +620,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
604620 | Pexp_let (_ , vbs , expr ) -> aux expr @ spelunk_vbs acc vbs
605621 | Pexp_ifthenelse (_ , then_expr , Some else_expr ) ->
606622 aux then_expr @ aux else_expr
623+ | Pexp_construct (_ , Some expr ) -> aux expr
607624 | Pexp_fun (_ , _ , _ , expr ) | Pexp_newtype (_ , expr ) -> aux expr
608625 | _ -> acc
609626 in
0 commit comments