Skip to content

Commit 3b136e8

Browse files
authored
Fix record type spread loc (rescript-lang#6157)
1 parent eddfbb7 commit 3b136e8

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- Fix broken formatting in uncurried mode for functions with _ placeholder args. https://github.com/rescript-lang/rescript-compiler/pull/6148
1818
- Fix issue where spreading record types with optional labels would not have their labels preserved as optional. https://github.com/rescript-lang/rescript-compiler/pull/6154
19+
- Fix error location to be the type with the spreads when spreading record types with duplicate labels. https://github.com/rescript-lang/rescript-compiler/pull/6157
1920

2021
# 11.0.0-alpha.3
2122

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/record_type_spreads.res:5:1-23
4+
5+
3 │ type t2 = {x: string, y: float}
6+
4 │
7+
5 │ type t3 = {...t, ...t2}
8+
6 │
9+
10+
Two labels are named x
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type t = {x: int, y: string}
2+
3+
type t2 = {x: string, y: float}
4+
5+
type t3 = {...t, ...t2}

jscomp/ml/typedecl.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -463,15 +463,15 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
463463
in
464464
process_lbls ([], []) lbls lbls'
465465
| _ -> Some (lbls, lbls') in
466-
let rec check_duplicates (lbls : Typedtree.label_declaration list) seen = match lbls with
466+
let rec check_duplicates loc (lbls : Typedtree.label_declaration list) seen = match lbls with
467467
| [] -> ()
468468
| lbl::rest ->
469469
let name = lbl.ld_id.name in
470-
if StringSet.mem name seen then raise(Error(lbl.ld_loc, Duplicate_label name));
471-
check_duplicates rest (StringSet.add name seen) in
470+
if StringSet.mem name seen then raise(Error(loc, Duplicate_label name));
471+
check_duplicates loc rest (StringSet.add name seen) in
472472
(match lbls_opt with
473473
| Some (lbls, lbls') ->
474-
check_duplicates lbls StringSet.empty;
474+
check_duplicates sdecl.ptype_loc lbls StringSet.empty;
475475
let optionalLabels =
476476
Ext_list.filter_map lbls (fun lbl ->
477477
if has_optional lbl.ld_attributes then Some lbl.ld_name.txt else None)

0 commit comments

Comments
 (0)