Skip to content

Commit ae25762

Browse files
committed
Use effective field name instead of checking actual field name and @as separately
1 parent 465a30f commit ae25762

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

compiler/ml/ast_untagged_variants.ml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -494,21 +494,17 @@ let check_tag_field_conflicts (cstrs : Types.constructor_declaration list) =
494494
| Cstr_record fields ->
495495
List.iter
496496
(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 ->
497+
(* Get the effective field name in JavaScript output *)
498+
let effective_field_name = match process_as_name field.ld_attributes with
499+
| Some as_name -> as_name (* Use @as name if present *)
500+
| None -> Ident.name field.ld_id (* Otherwise use field name *)
501+
in
502+
(* Check if effective field name conflicts with tag *)
503+
if effective_field_name = tag_name then
507504
raise
508505
(Error
509506
( cstr.cd_loc,
510-
TagFieldNameConflict (Ident.name cstr.cd_id, tag_name) ))
511-
| _ -> ())
507+
TagFieldNameConflict (Ident.name cstr.cd_id, tag_name) )))
512508
fields
513509
| _ -> ())
514510
cstrs

0 commit comments

Comments
 (0)