@@ -611,6 +611,14 @@ let extract_option_type env ty =
611
611
Tconstr (path , [ty ], _ ) when Path. same path Predef. path_option -> ty
612
612
| _ -> assert false
613
613
614
+ let src_pos loc attrs env =
615
+ { exp_desc = Texp_src_pos
616
+ ; exp_loc = loc
617
+ ; exp_extra = []
618
+ ; exp_type = instance Predef. type_lexing_position
619
+ ; exp_attributes = attrs
620
+ ; exp_env = env }
621
+
614
622
type record_extraction_result =
615
623
| Record_type of Path .t * Path .t * Types .label_declaration list * record_representation
616
624
| Not_a_record_type
@@ -5720,12 +5728,7 @@ and type_expect_
5720
5728
| _ -> raise (Error (loc, env, Probe_is_enabled_format ))
5721
5729
end
5722
5730
| Pexp_extension ({ txt = "src_pos" ; _ } , _ ) ->
5723
- rue {
5724
- exp_desc = Texp_src_pos ;
5725
- exp_loc = loc; exp_extra = [] ;
5726
- exp_type = instance Predef. type_lexing_position;
5727
- exp_attributes = sexp.pexp_attributes;
5728
- exp_env = env }
5731
+ rue (src_pos loc sexp.pexp_attributes env)
5729
5732
| Pexp_extension ext ->
5730
5733
raise (Error_forward (Builtin_attributes. error_of_extension ext))
5731
5734
@@ -6353,7 +6356,7 @@ and type_argument ?explanation ?recarg env (mode : expected_mode) sarg
6353
6356
in
6354
6357
match may_coerce with
6355
6358
Some (safe_expect , lv ) ->
6356
- (* apply optional arguments when expected type is "" *)
6359
+ (* apply omittable arguments when expected type is "" *)
6357
6360
(* we must be very careful about not breaking the semantics *)
6358
6361
if ! Clflags. principal then begin_def () ;
6359
6362
let exp_mode = Value_mode. newvar_below mode.mode in
@@ -6372,7 +6375,9 @@ and type_argument ?explanation ?recarg env (mode : expected_mode) sarg
6372
6375
(* CR layouts v5: change value assumption below when we allow
6373
6376
non-values in structures. *)
6374
6377
make_args ((l, Arg (ty, Sort. value)) :: args) ty_fun
6375
- (* TODO vding: Add a case for Position arguments? *)
6378
+ | Tarrow ((l ,_marg ,_mret ),_ ,ty_fun ,_ ) when is_position l ->
6379
+ let arg = src_pos (Location. ghostify sarg.pexp_loc) [] env in
6380
+ make_args ((l, Arg (arg, Sort. value)) :: args) ty_fun
6376
6381
| Tarrow ((l ,_ ,_ ),_ ,ty_res' ,_ ) when l = Nolabel || ! Clflags. classic ->
6377
6382
List. rev args, ty_fun, no_labels ty_res'
6378
6383
| Tvar _ -> List. rev args, ty_fun, false
@@ -6558,15 +6563,9 @@ and type_apply_arg env ~app_loc ~funct ~index ~position ~partial_app (lbl, arg)
6558
6563
let arg = option_none env (instance ty_arg) Location. none in
6559
6564
(lbl, Arg (arg, Value_mode. global, sort_arg))
6560
6565
| Position _ ->
6561
- let arg = {
6562
- exp_desc = Texp_src_pos ;
6563
- exp_loc = Location. ghostify app_loc;
6564
- exp_extra = [] ;
6565
- exp_type = instance Predef. type_lexing_position;
6566
- exp_attributes = [] ;
6567
- exp_env = env }
6568
- (* CR src_pos: Confirm that global value mode is correct *)
6569
- in (lbl, Arg (arg, Value_mode. global, sort_arg))
6566
+ let arg = src_pos (Location. ghostify app_loc) [] env in
6567
+ (* CR src_pos: Confirm that global value mode is correct *)
6568
+ (lbl, Arg (arg, Value_mode. global, sort_arg))
6570
6569
| Labelled _ | Nolabel -> assert false )
6571
6570
| Omitted _ as arg -> (lbl, arg)
6572
6571
0 commit comments