Skip to content

Fix record type spread loc #6157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- Fix broken formatting in uncurried mode for functions with _ placeholder args. https://github.com/rescript-lang/rescript-compiler/pull/6148
- 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
- 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

# 11.0.0-alpha.3

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

We've found a bug for you!
/.../fixtures/record_type_spreads.res:5:1-23

3 │ type t2 = {x: string, y: float}
4 │
5 │ type t3 = {...t, ...t2}
6 │

Two labels are named x
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type t = {x: int, y: string}

type t2 = {x: string, y: float}

type t3 = {...t, ...t2}
8 changes: 4 additions & 4 deletions jscomp/ml/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,15 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
in
process_lbls ([], []) lbls lbls'
| _ -> Some (lbls, lbls') in
let rec check_duplicates (lbls : Typedtree.label_declaration list) seen = match lbls with
let rec check_duplicates loc (lbls : Typedtree.label_declaration list) seen = match lbls with
| [] -> ()
| lbl::rest ->
let name = lbl.ld_id.name in
if StringSet.mem name seen then raise(Error(lbl.ld_loc, Duplicate_label name));
check_duplicates rest (StringSet.add name seen) in
if StringSet.mem name seen then raise(Error(loc, Duplicate_label name));
check_duplicates loc rest (StringSet.add name seen) in
(match lbls_opt with
| Some (lbls, lbls') ->
check_duplicates lbls StringSet.empty;
check_duplicates sdecl.ptype_loc lbls StringSet.empty;
let optionalLabels =
Ext_list.filter_map lbls (fun lbl ->
if has_optional lbl.ld_attributes then Some lbl.ld_name.txt else None)
Expand Down