@@ -27,7 +27,7 @@ type native_repr_kind = Unboxed | Untagged
2727type error =
2828 Repeated_parameter
2929 | Duplicate_constructor of string
30- | Duplicate_label of string
30+ | Duplicate_label of string * string option
3131 | Recursive_abbrev of string
3232 | Cycle_in_def of string * type_expr
3333 | Definition_mismatch of type_expr * Includecore .type_mismatch list
@@ -207,17 +207,17 @@ let make_params env params =
207207 in
208208 List. map make_param params
209209
210- let transl_labels env closed lbls =
210+ let transl_labels ? recordName env closed lbls =
211211 if ! Config. bs_only then
212212 match ! Builtin_attributes. check_duplicated_labels lbls with
213213 | None -> ()
214- | Some {loc;txt =name } -> raise (Error (loc,Duplicate_label name))
214+ | Some {loc;txt =name } -> raise (Error (loc,Duplicate_label ( name, recordName) ))
215215 else (
216216 let all_labels = ref StringSet. empty in
217217 List. iter
218218 (fun {pld_name = {txt =name ; loc} } ->
219219 if StringSet. mem name ! all_labels then
220- raise(Error (loc, Duplicate_label name));
220+ raise(Error (loc, Duplicate_label ( name, recordName) ));
221221 all_labels := StringSet. add name ! all_labels)
222222 lbls);
223223 let mk {pld_name =name ;pld_mutable =mut ;pld_type =arg ;pld_loc =loc ;
@@ -501,7 +501,7 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
501501 {typ with ptyp_desc = Ptyp_constr ({txt = Lident " option" ; loc= typ.ptyp_loc}, [typ])}
502502 else typ in
503503 {lbl with pld_type = typ }) in
504- let lbls, lbls' = transl_labels env true lbls in
504+ let lbls, lbls' = transl_labels ~record Name:(sdecl.ptype_name.txt) env true lbls in
505505 let lbls_opt = match Record_type_spread. has_type_spread lbls with
506506 | true ->
507507 let rec extract t = match t.desc with
@@ -545,7 +545,7 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
545545 | [] -> ()
546546 | lbl ::rest ->
547547 let name = lbl.ld_id.name in
548- if StringSet. mem name seen then raise(Error (loc, Duplicate_label name));
548+ if StringSet. mem name seen then raise(Error (loc, Duplicate_label ( name, Some sdecl.ptype_name.txt) ));
549549 check_duplicates loc rest (StringSet. add name seen) in
550550 (match lbls_opt with
551551 | Some (lbls , lbls' ) ->
@@ -1998,8 +1998,10 @@ let report_error ppf = function
19981998 fprintf ppf " A type parameter occurs several times"
19991999 | Duplicate_constructor s ->
20002000 fprintf ppf " Two constructors are named %s" s
2001- | Duplicate_label s ->
2002- fprintf ppf " Two labels are named %s" s
2001+ | Duplicate_label (s , None) ->
2002+ fprintf ppf " The field @{<info>%s@} is defined several times in this record. Fields can only be added once to a record." s
2003+ | Duplicate_label (s , Some recordName ) ->
2004+ fprintf ppf " The field @{<info>%s@} is defined several times in the record @{<info>%s@}. Fields can only be added once to a record." s recordName
20032005 | Recursive_abbrev s ->
20042006 fprintf ppf " The type abbreviation %s is cyclic" s
20052007 | Cycle_in_def (s , ty ) ->
0 commit comments