@@ -2223,6 +2223,41 @@ let not_function env ty =
2223
2223
let ls, tvar = list_labels env ty in
2224
2224
ls = [] && not tvar
2225
2225
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
+
2226
2261
type lazy_args =
2227
2262
(Asttypes.Noloc .arg_label * (unit -> Typedtree .expression ) option ) list
2228
2263
@@ -2412,7 +2447,9 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
2412
2447
let args, ty_res, fully_applied =
2413
2448
match translate_unified_ops env funct sargs with
2414
2449
| 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
2416
2453
in
2417
2454
end_def () ;
2418
2455
unify_var env (newvar () ) funct.exp_type;
@@ -3447,8 +3484,11 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
3447
3484
| _ -> None )
3448
3485
| _ -> None
3449
3486
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
3452
3492
let result_type omitted ty_fun =
3453
3493
List. fold_left
3454
3494
(fun ty_fun (l , ty , lv ) -> newty2 lv (Tarrow (l, ty, ty_fun, Cok , None )))
0 commit comments