@@ -2223,42 +2223,36 @@ 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
2226+ type injectable_source_loc_arg = ValuePath | Pos
22332227
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 )
2228+ let rec find_injectable_source_loc_args ?(found = [] ) t =
2229+ match t.desc with
2230+ | Tarrow (Labelled n, {desc = Tconstr (p, [] , _)}, next, _, _)
2231+ when Path. same p Predef. path_source_loc_pos ->
2232+ (Pos , n) :: find_injectable_source_loc_args ~found next
2233+ | Tarrow (Labelled n, {desc = Tconstr (p, [] , _)}, next, _, _)
2234+ when Path. same p Predef. path_source_loc_value_path ->
2235+ (ValuePath , n) :: find_injectable_source_loc_args ~found next
2236+ | Tarrow (_ , _ , t , _ , _ ) -> find_injectable_source_loc_args t
2237+ | _ -> found
22402238
22412239let expand_injectable_args ~(apply_expr : Parsetree.expression ) ~exp_type
22422240 (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
2241+ match find_injectable_source_loc_args exp_type with
2242+ | [] -> sargs
2243+ | injectable_args ->
2244+ (* TODO: Error on args already being supplied *)
22492245 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- mk_source_loc_field " modulePath" " __MODULE_PATH__" ;
2258- mk_source_loc_field " valuePath" " __VALUE_PATH__" ;
2259- ]
2260- None );
2261- ]
2246+ @ (injectable_args
2247+ |> List. map (fun (t , n ) ->
2248+ ( Labelled (Location. mknoloc n),
2249+ Ast_helper.Exp. ident
2250+ ~loc: {apply_expr.pexp_loc with loc_ghost = true }
2251+ (Location. mknoloc
2252+ (Longident. Lident
2253+ (match t with
2254+ | ValuePath -> " __SOURCE_LOC_VALUE_PATH__"
2255+ | Pos -> " __SOURCE_LOC_POS__" ))) )))
22622256
22632257type lazy_args =
22642258 (Asttypes.Noloc .arg_label * (unit -> Typedtree .expression ) option ) list
0 commit comments