Skip to content

Commit c3ab4fd

Browse files
committed
simplify check of private assignment
1 parent bc684ac commit c3ab4fd

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

compiler/ml/typecore.ml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,6 @@ let extract_concrete_record env ty =
316316
match extract_concrete_typedecl env ty with
317317
| p0, p, {type_kind = Type_record (fields, repr)} -> (p0, p, fields, repr)
318318
| _ -> raise Not_found
319-
320-
let private_record_allows_mutation env label =
321-
match extract_concrete_typedecl env label.lbl_res with
322-
| _, _, {type_kind = Type_record _; type_private = Private; type_attributes}
323-
->
324-
Builtin_attributes.has_allow_mutation type_attributes
325-
| _ -> false
326-
| exception Not_found -> false
327-
328319
let extract_concrete_variant env ty =
329320
match extract_concrete_typedecl env ty with
330321
| p0, p, {type_kind = Type_variant cstrs} -> (p0, p, cstrs)
@@ -3645,15 +3636,24 @@ and type_label_exp ~call_context create env loc ty_expected
36453636
end_def ();
36463637
(* Generalize information merged from ty_expected *)
36473638
generalize_structure ty_arg);
3648-
let allow_private_assignment =
3649-
match call_context with
3650-
| `SetRecordField when not create ->
3651-
private_record_allows_mutation env label
3652-
| _ -> false
3653-
in
3654-
if label.lbl_private = Private && not allow_private_assignment then
3655-
if create then raise (Error (loc, env, Private_type ty_expected))
3656-
else raise (Error (lid.loc, env, Private_label (lid.txt, ty_expected)));
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))));
36573657
let arg =
36583658
let snap = if vars = [] then None else Some (Btype.snapshot ()) in
36593659
let field_name = Longident.last lid.txt in

0 commit comments

Comments
 (0)