@@ -2223,6 +2223,41 @@ let not_function env ty =
22232223 let ls, tvar = list_labels env ty in
22242224 ls = [] && not tvar
22252225
2226+ let rec find_injectable_source_loc_arg t =
2227+ match t.desc with
2228+ | Tarrow (Labelled n, {desc = Tconstr (p, [] , _)}, _, _, _)
2229+ when Path. same p Predef. path_source_loc ->
2230+ Some n
2231+ | Tarrow (_ , _ , t , _ , _ ) -> find_injectable_source_loc_arg t
2232+ | _ -> None
2233+
2234+ let mk_source_loc_field ~parent_loc field_name ident_name =
2235+ ( Location. mknoloc (Longident. Lident field_name),
2236+ Ast_helper.Exp. ident
2237+ ~loc: {parent_loc with loc_ghost = true }
2238+ (Location. mknoloc (Longident. Lident ident_name)),
2239+ false )
2240+
2241+ let expand_injectable_args ~(apply_expr : Parsetree.expression ) ~exp_type
2242+ (sargs : sargs ) =
2243+ match find_injectable_source_loc_arg exp_type with
2244+ | None -> sargs
2245+ | Some injectable_source_loc_arg_label_name ->
2246+ let mk_source_loc_field =
2247+ mk_source_loc_field ~parent_loc: apply_expr.pexp_loc
2248+ in
2249+ sargs
2250+ @ [
2251+ ( Labelled (Location. mknoloc injectable_source_loc_arg_label_name),
2252+ Ast_helper.Exp. record
2253+ [
2254+ mk_source_loc_field " filename" " __FILE__" ;
2255+ mk_source_loc_field " module_" " __MODULE__" ;
2256+ mk_source_loc_field " pos" " __POS__" ;
2257+ ]
2258+ None );
2259+ ]
2260+
22262261type lazy_args =
22272262 (Asttypes.Noloc .arg_label * (unit -> Typedtree .expression ) option ) list
22282263
@@ -2412,7 +2447,9 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
24122447 let args, ty_res, fully_applied =
24132448 match translate_unified_ops env funct sargs with
24142449 | Some (targs , result_type ) -> (targs, result_type, true )
2415- | None -> type_application ?type_clash_context total_app env funct sargs
2450+ | None ->
2451+ type_application ~apply_expr: sexp ?type_clash_context total_app env
2452+ funct sargs
24162453 in
24172454 end_def () ;
24182455 unify_var env (newvar () ) funct.exp_type;
@@ -3447,8 +3484,11 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
34473484 | _ -> None )
34483485 | _ -> None
34493486
3450- and type_application ?type_clash_context total_app env funct (sargs : sargs ) :
3451- targs * Types. type_expr * bool =
3487+ and type_application ?type_clash_context ~apply_expr total_app env funct
3488+ (sargs : sargs ) : targs * Types.type_expr * bool =
3489+ let sargs =
3490+ expand_injectable_args ~apply_expr ~exp_type: funct.exp_type sargs
3491+ in
34523492 let result_type omitted ty_fun =
34533493 List. fold_left
34543494 (fun ty_fun (l , ty , lv ) -> newty2 lv (Tarrow (l, ty, ty_fun, Cok , None )))
0 commit comments