@@ -484,30 +484,33 @@ let names_from_type_variant ?(is_untagged_def = false) ~env
484484let check_tag_field_conflicts (cstrs : Types.constructor_declaration list ) =
485485 List. iter
486486 (fun (cstr : Types.constructor_declaration ) ->
487- match process_tag_name cstr.cd_attributes with
488- | Some tag_name -> (
489- match cstr.cd_args with
490- | Cstr_record fields ->
491- List. iter
492- (fun (field : Types.label_declaration ) ->
493- (* Check if field name conflicts with tag *)
494- let field_name = Ident. name field.ld_id in
495- if field_name = tag_name then
496- raise
497- (Error
498- ( cstr.cd_loc,
499- TagFieldNameConflict (Ident. name cstr.cd_id, tag_name) ));
500- (* Check if @as name conflicts with tag *)
501- match process_as_name field.ld_attributes with
502- | Some as_name when as_name = tag_name ->
503- raise
504- (Error
505- ( cstr.cd_loc,
506- TagFieldNameConflict (Ident. name cstr.cd_id, tag_name) ))
507- | _ -> () )
508- fields
509- | _ -> () )
510- | None -> () )
487+ (* Get the effective tag name - either explicit @tag or constructor name *)
488+ let tag_name =
489+ match process_tag_name cstr.cd_attributes with
490+ | Some explicit_tag -> explicit_tag
491+ | None -> Ident. name cstr.cd_id (* Default to constructor name *)
492+ in
493+ match cstr.cd_args with
494+ | Cstr_record fields ->
495+ List. iter
496+ (fun (field : Types.label_declaration ) ->
497+ (* Check if field name conflicts with tag *)
498+ let field_name = Ident. name field.ld_id in
499+ if field_name = tag_name then
500+ raise
501+ (Error
502+ ( cstr.cd_loc,
503+ TagFieldNameConflict (Ident. name cstr.cd_id, tag_name) ));
504+ (* Check if @as name conflicts with tag *)
505+ match process_as_name field.ld_attributes with
506+ | Some as_name when as_name = tag_name ->
507+ raise
508+ (Error
509+ ( cstr.cd_loc,
510+ TagFieldNameConflict (Ident. name cstr.cd_id, tag_name) ))
511+ | _ -> () )
512+ fields
513+ | _ -> () )
511514 cstrs
512515
513516type well_formedness_check = {
0 commit comments