Skip to content

Commit 2034d8e

Browse files
committed
Add check for duplicate labels.
1 parent 9eb6a83 commit 2034d8e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

jscomp/ml/typedecl.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ let transl_declaration env sdecl id =
470470
in
471471
process_lbls ([], []) lbls lbls'
472472
| _ -> lbls, lbls' in
473+
let rec check_duplicates (lbls : Typedtree.label_declaration list) seen = match lbls with
474+
| [] -> ()
475+
| lbl::rest ->
476+
let name = lbl.ld_id.name in
477+
if StringSet.mem name seen then raise(Error(lbl.ld_loc, Duplicate_label name));
478+
check_duplicates rest (StringSet.add name seen) in
479+
check_duplicates lbls StringSet.empty;
473480
Ttype_record lbls, Type_record(lbls', rep)
474481
| Ptype_open -> Ttype_open, Type_open
475482
in

0 commit comments

Comments
 (0)