diff --git a/CHANGELOG.md b/CHANGELOG.md index f4269b52cd..a020c478be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/ml/typedecl.ml b/jscomp/ml/typedecl.ml index 77fc421d95..b1cd3190e1 100644 --- a/jscomp/ml/typedecl.ml +++ b/jscomp/ml/typedecl.ml @@ -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 @@ -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; diff --git a/jscomp/test/DotDotDot.js b/jscomp/test/DotDotDot.js index c2634c6cd8..011f4ba327 100644 --- a/jscomp/test/DotDotDot.js +++ b/jscomp/test/DotDotDot.js @@ -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 */ diff --git a/jscomp/test/DotDotDot.res b/jscomp/test/DotDotDot.res index 657d264ff6..101b8594f2 100644 --- a/jscomp/test/DotDotDot.res +++ b/jscomp/test/DotDotDot.res @@ -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}