From e018399368547cb1e24b49ed695ede5f2c66cf87 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 3 Apr 2024 17:35:19 +0200 Subject: [PATCH] Apply @:using after running build macro Allows build macro to provide such metadata --- src/typing/typeloadFields.ml | 40 ++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/typing/typeloadFields.ml b/src/typing/typeloadFields.ml index 55860c9ef63..8c75e07f5ca 100644 --- a/src/typing/typeloadFields.ml +++ b/src/typing/typeloadFields.ml @@ -401,24 +401,6 @@ let build_module_def ctx mt meta fvars fbuild = | MError | MMacroInMacro -> raise_typing_error "Build failure" p | MSuccess e -> fbuild e) ) :: f_build - | Meta.Using,el,p -> (fun () -> - List.iter (fun e -> - try - let path = List.rev (string_pos_list_of_expr_path_raise e) in - let types,filter_classes = ImportHandling.handle_using ctx path (pos e) in - let ti = - match mt with - | TClassDecl { cl_kind = KAbstractImpl a } -> t_infos (TAbstractDecl a) - | _ -> t_infos mt - in - (* Delay for #10107, but use delay_late to make sure base classes run before their children do. *) - delay_late ctx.g PConnectField (fun () -> - ti.mt_using <- (filter_classes types) @ ti.mt_using - ) - with Exit -> - raise_typing_error "dot path expected" (pos e) - ) el; - ) :: f_build | _ -> f_build in @@ -445,6 +427,28 @@ let build_module_def ctx mt meta fvars fbuild = None in List.iter (fun f -> f()) (List.rev f_build); + let apply_using = function + | Meta.Using,el,p -> + List.iter (fun e -> + try + let path = List.rev (string_pos_list_of_expr_path_raise e) in + let types,filter_classes = ImportHandling.handle_using ctx path (pos e) in + let ti = + match mt with + | TClassDecl { cl_kind = KAbstractImpl a } -> t_infos (TAbstractDecl a) + | _ -> t_infos mt + in + (* Delay for #10107, but use delay_late to make sure base classes run before their children do. *) + delay_late ctx.g PConnectField (fun () -> + ti.mt_using <- (filter_classes types) @ ti.mt_using + ) + with Exit -> + raise_typing_error "dot path expected" (pos e) + ) el; + | _ -> + () + in + List.iter apply_using ctx.c.curclass.cl_meta; (match f_enum with None -> () | Some f -> f()) let create_class_context c p =