@@ -190,6 +190,7 @@ type error =
190190 | Not_an_extension_constructor
191191 | Invalid_atomic_loc_payload
192192 | Label_not_atomic of Longident .t
193+ | Atomic_in_pattern of Longident .t
193194 | Literal_overflow of string
194195 | Unknown_literal of string * char
195196 | Illegal_letrec_pat
@@ -986,6 +987,10 @@ let solve_Ppat_construct ~refine tps penv loc constr no_existentials
986987
987988let solve_Ppat_record_field ~refine loc penv label label_lid record_ty =
988989 with_local_level_generalize_structure begin fun () ->
990+ (* [not refine] holds when the pattern comes from the user,
991+ rather than a counter-example to exhaustivity. *)
992+ if not refine && label.lbl_atomic = Atomic then
993+ raise (Error (loc, !! penv, Atomic_in_pattern label_lid.txt)) ;
989994 let (_, ty_arg, ty_res) = instance_label ~fixed: false label in
990995 begin try
991996 unify_pat_types_refine ~refine loc penv ty_res (instance record_ty)
@@ -7037,6 +7042,13 @@ let report_error ~loc env = function
70377042 | Label_not_atomic lid ->
70387043 Location. errorf ~loc " The record field %a is not atomic"
70397044 (Style. as_inline_code longident) lid
7045+ | Atomic_in_pattern lid ->
7046+ Location. errorf ~loc
7047+ " Atomic fields (here %a) are forbidden in patterns, as it is difficult \
7048+ to reason about when the atomic read will happen during pattern \
7049+ matching: the field may be read zero, one or several times depending \
7050+ on the patterns around it."
7051+ (Style. as_inline_code longident) lid
70407052 | Literal_overflow ty ->
70417053 Location. errorf ~loc
70427054 " Integer literal exceeds the range of representable integers of type %a"
0 commit comments