@@ -57,7 +57,6 @@ type error =
5757 string * Longident .t * (Path .t * Path .t ) * (Path .t * Path .t ) list
5858 | Undefined_method of type_expr * string * string list option
5959 | Private_type of type_expr
60- | Private_label of Longident .t * type_expr
6160 | Not_subtype of
6261 Ctype .type_pairs * Ctype .type_pairs * Ctype .subtype_context option
6362 | Too_many_arguments of bool * type_expr
@@ -316,6 +315,13 @@ let extract_concrete_record env ty =
316315 match extract_concrete_typedecl env ty with
317316 | p0 , p , {type_kind = Type_record (fields , repr )} -> (p0, p, fields, repr)
318317 | _ -> raise Not_found
318+
319+ let is_private_record_field env label =
320+ match extract_concrete_typedecl env label.lbl_res with
321+ | _ , _ , {type_kind = Type_record _ ; type_private = Private } -> true
322+ | _ -> false
323+ | exception Not_found -> false
324+
319325let extract_concrete_variant env ty =
320326 match extract_concrete_typedecl env ty with
321327 | p0 , p , {type_kind = Type_variant cstrs } -> (p0, p, cstrs)
@@ -2952,6 +2958,9 @@ and type_expect_ ?deprecated_context ~context ?in_function ?(recarg = Rejected)
29522958 unify_exp ~context: None env record ty_record;
29532959 if label.lbl_mut = Immutable then
29542960 raise (Error (loc, env, Label_not_mutable lid.txt));
2961+ if label.lbl_private = Private && is_private_record_field env label then
2962+ Location. prerr_warning lid.loc
2963+ (Warnings. Bs_private_record_mutation (Longident. last lid.txt));
29552964 Builtin_attributes. check_deprecated_mutable lid.loc label.lbl_attributes
29562965 (Longident. last lid.txt);
29572966 rue
@@ -3636,24 +3645,8 @@ and type_label_exp ~call_context create env loc ty_expected
36363645 end_def () ;
36373646 (* Generalize information merged from ty_expected *)
36383647 generalize_structure ty_arg);
3639- (if label.lbl_private = Private then
3640- if create then raise (Error (loc, env, Private_type ty_expected))
3641- else
3642- let allow_private_assignment =
3643- match extract_concrete_typedecl env label.lbl_res with
3644- | ( _,
3645- _,
3646- {
3647- type_kind = Type_record _;
3648- type_private = Private ;
3649- type_attributes;
3650- } ) ->
3651- Builtin_attributes. has_allow_mutation type_attributes
3652- | _ -> false
3653- | exception Not_found -> false
3654- in
3655- if not allow_private_assignment then
3656- raise (Error (lid.loc, env, Private_label (lid.txt, ty_expected))));
3648+ if label.lbl_private = Private && create then
3649+ raise (Error (loc, env, Private_type ty_expected));
36573650 let arg =
36583651 let snap = if vars = [] then None else Some (Btype. snapshot () ) in
36593652 let field_name = Longident. last lid.txt in
@@ -4842,9 +4835,6 @@ let report_error env loc ppf error =
48424835 " In this type, the locally bound module name %s escapes its scope" id
48434836 | Private_type ty ->
48444837 fprintf ppf " Cannot create values of the private type %a" type_expr ty
4845- | Private_label (lid , ty ) ->
4846- fprintf ppf " Cannot assign field %a of the private type %a" longident lid
4847- type_expr ty
48484838 | Not_a_variant_type lid ->
48494839 fprintf ppf " The type %a@ is not a variant type" longident lid
48504840 | Incoherent_label_order ->
0 commit comments