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