Skip to content

Commit 465a30f

Browse files
committed
Check variants without a @tag decorator
1 parent 5bba7f8 commit 465a30f

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

compiler/ml/ast_untagged_variants.ml

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -484,30 +484,33 @@ let names_from_type_variant ?(is_untagged_def = false) ~env
484484
let 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

513516
type well_formedness_check = {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/duplicate_as_tag_inline_record.res:1:35-37
4+
5+
1 │ type animal = Cat({@as("catName") @as("catName2") name: string})
6+
2 │
7+
8+
duplicate @as
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type animal = Cat({@as("catName") @as("catName2") name: string})

0 commit comments

Comments
 (0)