From b2bddbe70b96bade505a9cbd8191351737f768b7 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 15 Apr 2023 12:10:42 +0200 Subject: [PATCH 1/3] add test showing that locs are wrong in record type spread with overlapping labels --- .../expected/record_type_spreads.res.expected | 11 +++++++++++ .../super_errors/fixtures/record_type_spreads.res | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 jscomp/build_tests/super_errors/expected/record_type_spreads.res.expected create mode 100644 jscomp/build_tests/super_errors/fixtures/record_type_spreads.res diff --git a/jscomp/build_tests/super_errors/expected/record_type_spreads.res.expected b/jscomp/build_tests/super_errors/expected/record_type_spreads.res.expected new file mode 100644 index 0000000000..035ea6ef11 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/record_type_spreads.res.expected @@ -0,0 +1,11 @@ + + We've found a bug for you! + /.../fixtures/record_type_spreads.res:3:12-20 + + 1 │ type t = {x: int, y: string} + 2 │ + 3 │ type t2 = {x: string, y: float} + 4 │ + 5 │ type t3 = {...t, ...t2} + + Two labels are named x \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/record_type_spreads.res b/jscomp/build_tests/super_errors/fixtures/record_type_spreads.res new file mode 100644 index 0000000000..7f0a675600 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/record_type_spreads.res @@ -0,0 +1,5 @@ +type t = {x: int, y: string} + +type t2 = {x: string, y: float} + +type t3 = {...t, ...t2} From 72d685c541dae890fdf7cfc3731ecd1060c21fe7 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 15 Apr 2023 12:14:33 +0200 Subject: [PATCH 2/3] fix loc of duplicate label error to be the loc of the type definition with the spreads, not one of the duplicate labels --- .../expected/record_type_spreads.res.expected | 9 ++++----- jscomp/ml/typedecl.ml | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/jscomp/build_tests/super_errors/expected/record_type_spreads.res.expected b/jscomp/build_tests/super_errors/expected/record_type_spreads.res.expected index 035ea6ef11..e1685b75c5 100644 --- a/jscomp/build_tests/super_errors/expected/record_type_spreads.res.expected +++ b/jscomp/build_tests/super_errors/expected/record_type_spreads.res.expected @@ -1,11 +1,10 @@ We've found a bug for you! - /.../fixtures/record_type_spreads.res:3:12-20 + /.../fixtures/record_type_spreads.res:5:1-23 - 1 │ type t = {x: int, y: string} - 2 │ - 3 │ type t2 = {x: string, y: float} + 3 │ type t2 = {x: string, y: float} 4 │ - 5 │ type t3 = {...t, ...t2} + 5 │ type t3 = {...t, ...t2} + 6 │ Two labels are named x \ No newline at end of file diff --git a/jscomp/ml/typedecl.ml b/jscomp/ml/typedecl.ml index b1cd3190e1..e564840266 100644 --- a/jscomp/ml/typedecl.ml +++ b/jscomp/ml/typedecl.ml @@ -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) From 2f3edd2e5a1b5a28c32806edbf864f33235d018e Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 15 Apr 2023 12:16:10 +0200 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a020c478be..90105deae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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