@@ -2575,7 +2575,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
2575
2575
(type_record_elem_list loc true env
2576
2576
(fun e k ->
2577
2577
k
2578
- (type_label_exp ~context: None true env loc ty_record
2578
+ (type_label_exp ~call_context: `Regular true env loc ty_record
2579
2579
(process_optional_label e)))
2580
2580
opath lid_sexp_list)
2581
2581
(fun x -> x)
@@ -2685,7 +2685,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
2685
2685
(type_record_elem_list loc closed env
2686
2686
(fun e k ->
2687
2687
k
2688
- (type_label_exp ~context: None true env loc ty_record
2688
+ (type_label_exp ~call_context: `Regular true env loc ty_record
2689
2689
(process_optional_label e)))
2690
2690
opath lid_sexp_list)
2691
2691
(fun x -> x)
@@ -2764,7 +2764,7 @@ and type_expect_ ~context ?in_function ?(recarg = Rejected) env sexp ty_expected
2764
2764
let record, label, opath = type_label_access env srecord lid in
2765
2765
let ty_record = if opath = None then newvar () else record.exp_type in
2766
2766
let label_loc, label, newval, _ =
2767
- type_label_exp ~context: ( Some SetRecordField ) false env loc ty_record
2767
+ type_label_exp ~call_context: ` SetRecordField false env loc ty_record
2768
2768
(lid, label, snewval, false )
2769
2769
in
2770
2770
unify_exp ~context: None env record ty_record;
@@ -3296,7 +3296,8 @@ and type_label_access env srecord lid =
3296
3296
(* Typing format strings for printing or reading.
3297
3297
These formats are used by functions in modules Printf, Format, and Scanf.
3298
3298
(Handling of * modifiers contributed by Thorsten Ohl.) *)
3299
- and type_label_exp ~context create env loc ty_expected (lid , label , sarg , opt ) =
3299
+ and type_label_exp ~(call_context : [`SetRecordField | `Regular] ) create env loc
3300
+ ty_expected (lid , label , sarg , opt ) =
3300
3301
(* Here also ty_expected may be at generic_level *)
3301
3302
begin_def () ;
3302
3303
let separate = Env. has_local_constraints env in
@@ -3323,7 +3324,15 @@ and type_label_exp ~context create env loc ty_expected (lid, label, sarg, opt) =
3323
3324
else raise (Error (lid.loc, env, Private_label (lid.txt, ty_expected)));
3324
3325
let arg =
3325
3326
let snap = if vars = [] then None else Some (Btype. snapshot () ) in
3326
- let arg = type_argument ~context env sarg ty_arg (instance env ty_arg) in
3327
+ let field_name = Longident. last lid.txt in
3328
+ let field_context =
3329
+ match call_context with
3330
+ | `SetRecordField -> Some (Error_message_utils. SetRecordField field_name)
3331
+ | `Regular -> Some (Error_message_utils. RecordField field_name)
3332
+ in
3333
+ let arg =
3334
+ type_argument ~context: field_context env sarg ty_arg (instance env ty_arg)
3335
+ in
3327
3336
end_def () ;
3328
3337
try
3329
3338
check_univars env (vars <> [] ) " field value" arg label.lbl_arg vars;
@@ -3333,10 +3342,10 @@ and type_label_exp ~context create env loc ty_expected (lid, label, sarg, opt) =
3333
3342
(* Try to retype without propagating ty_arg, cf PR#4862 *)
3334
3343
may Btype. backtrack snap;
3335
3344
begin_def () ;
3336
- let arg = type_exp ~context env sarg in
3345
+ let arg = type_exp ~context: field_context env sarg in
3337
3346
end_def () ;
3338
3347
generalize_expansive env arg.exp_type;
3339
- unify_exp ~context env arg ty_arg;
3348
+ unify_exp ~context: field_context env arg ty_arg;
3340
3349
check_univars env false " field value" arg label.lbl_arg vars;
3341
3350
arg
3342
3351
with
0 commit comments