Skip to content

Commit aac80b8

Browse files
committed
fix loc of duplicate label error to be the loc of the type definition with the spreads, not one of the duplicate labels
1 parent 8395cbd commit aac80b8

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11

22
We've found a bug for you!
3-
/.../fixtures/record_type_spreads.res:3:12-20
3+
/.../fixtures/record_type_spreads.res:5:1-23
44

5-
1 │ type t = {x: int, y: string}
6-
2 │
7-
3 │ type t2 = {x: string, y: float}
5+
3 │ type t2 = {x: string, y: float}
86
4 │
9-
5 │ type t3 = {...t, ...t2}
7+
5 │ type t3 = {...t, ...t2}
8+
6 │
109

1110
Two labels are named x

jscomp/ml/typedecl.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,15 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
470470
in
471471
process_lbls ([], []) lbls lbls'
472472
| _ -> Some (lbls, lbls') in
473-
let rec check_duplicates (lbls : Typedtree.label_declaration list) seen = match lbls with
473+
let rec check_duplicates loc (lbls : Typedtree.label_declaration list) seen = match lbls with
474474
| [] -> ()
475475
| lbl::rest ->
476476
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
477+
if StringSet.mem name seen then raise(Error(loc, Duplicate_label name));
478+
check_duplicates loc rest (StringSet.add name seen) in
479479
(match lbls_opt with
480480
| Some (lbls, lbls') ->
481-
check_duplicates lbls StringSet.empty;
481+
check_duplicates sdecl.ptype_loc lbls StringSet.empty;
482482
Ttype_record lbls, Type_record(lbls', rep), sdecl
483483
| None ->
484484
(* Could not find record type decl for ...t: assume t is an object type and this is syntax ambiguity *)

0 commit comments

Comments
 (0)