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