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 5 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
23 changes: 14 additions & 9 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 All @@ -462,7 +455,13 @@ let transl_declaration ~typeRecordAsObject env sdecl id =
| {ld_name = {txt = "..."}; ld_type} :: rest, _ :: rest' ->
(match Ctype.extract_concrete_typedecl env (extract ld_type.ctyp_type) with
(_p0, _p, {type_kind=Type_record (fields, _repr)}) ->
process_lbls (fst acc @ (fields |> List.map mkLbl), snd acc @ fields) rest rest'
process_lbls (fst acc @ (fields |> List.map(fun (lbl: Types.label_declaration) ->
let typ = lbl.ld_type in
let typ =
if has_optional lbl.ld_attributes then
(Ctype.newconstr (Path.Pident (Ident.create "option")) [typ])
else typ in
{lbl with ld_type = typ }) |> List.map mkLbl), snd acc @ fields) rest rest'
| _ -> assert false
| exception _ -> None)
| lbl::rest, lbl'::rest' -> process_lbls (fst acc @ [lbl], snd acc @ [lbl']) rest rest'
Expand All @@ -479,7 +478,13 @@ 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