Skip to content

Record definition spread issues #6154

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 8 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 @@ -15,6 +15,7 @@
#### :bug: Bug Fix

- 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

# 11.0.0-alpha.3

Expand Down
17 changes: 9 additions & 8 deletions jscomp/ml/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,6 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
else typ in
{lbl with pld_type = typ }) in
let lbls, lbls' = transl_labels env true lbls in
let rep =
if unbox then Record_unboxed false
else
if optionalLabels <> []
then Record_optional_labels optionalLabels
else Record_regular
in
let lbls_opt = match lbls, lbls' with
| {ld_name = {txt = "..."}; ld_type} :: _, _ :: _ ->
let rec extract t = match t.desc with
Expand Down Expand Up @@ -479,7 +472,15 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
(match lbls_opt with
| Some (lbls, lbls') ->
check_duplicates lbls StringSet.empty;
Ttype_record lbls, Type_record(lbls', rep), sdecl
let optionalLabels =
Ext_list.filter_map lbls (fun lbl ->
if has_optional lbl.ld_attributes then Some lbl.ld_name.txt else None)
in
Ttype_record lbls, Type_record(lbls', if unbox then
Record_unboxed false
else if optionalLabels <> [] then
Record_optional_labels optionalLabels
else Record_regular), sdecl
| None ->
(* Could not find record type decl for ...t: assume t is an object type and this is syntax ambiguity *)
typeRecordAsObject := true;
Expand Down
6 changes: 6 additions & 0 deletions jscomp/test/DotDotDot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ var v2 = {
w: 2.0
};

var x = {
name: "test",
x: "test"
};

exports.v = v;
exports.v2 = v2;
exports.x = x;
exports.MultipleDotDotDots = MultipleDotDotDots;
/* No side effect */
5 changes: 5 additions & 0 deletions jscomp/test/DotDotDot.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ type svgProps = {
y?: string,
}

let x: svgProps = {x: "test", name: "test"}

// uncomment this to reveal a parser error
// type copiedSvgProps = {...svgProps}

module MultipleDotDotDots = {
type t1 = {x: int}
type t2 = {y: string}
Expand Down