Skip to content

Prepare support for ns.optional. #5483

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
Jun 27, 2022
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
2 changes: 1 addition & 1 deletion jscomp/ml/printtyp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ and tree_of_constructor cd =
(name, args, Some ret)

and tree_of_label l =
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "optional") in
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
let typ = match l.ld_type.desc with
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
| _ -> l.ld_type in
Expand Down
4 changes: 2 additions & 2 deletions jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
| _ -> false in
let process_optional_label (ld, pat) =
let exp_optional_attr =
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "optional")
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional")
in
let isFromPamatch = match pat.ppat_desc with
| Ppat_construct ({txt = Lident s}, _) ->
Expand Down Expand Up @@ -1881,7 +1881,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
| _ -> false in
let process_optional_label (id, ld, e) =
let exp_optional_attr =
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "optional")
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional")
in
if label_is_optional ld && not exp_optional_attr then
let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ let transl_declaration env sdecl id =
let tcstrs, cstrs = List.split (List.map make_cstr scstrs) in
Ttype_variant tcstrs, Type_variant cstrs
| Ptype_record lbls ->
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "optional") in
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
let optionalLabels =
Ext_list.filter_map lbls
(fun lbl -> if has_optional lbl.pld_attributes then Some lbl.pld_name.txt else None) in
Expand Down
66 changes: 33 additions & 33 deletions jscomp/test/record_regression.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @@config({flags: ["-bs-diagnose"] })

type t0 = {x: int, @optional y: int, @optional yy: option<int>, z: int}
type t0 = {x: int, @ns.optional y: int, @ns.optional yy: option<int>, z: int}

let f1 = {x: 3, z: 2}

Expand Down Expand Up @@ -31,30 +31,30 @@ let v2: r = {x: 3, y: None, z: 2}

type config = {
x: int,
@optional y0: int,
@optional y1: int,
@optional y2: int,
@optional y3: int,
@optional y4: int,
@optional y5: int,
@optional y6: int,
@optional y7: int,
@optional y8: int,
@optional y9: int,
@optional y10: int,
@optional y11: int,
@optional y12: int,
@optional y13: int,
@optional y14: int,
@optional y15: int,
@optional y16: int,
@optional y17: int,
@optional y18: int,
@optional y19: int,
@optional y20: int,
@optional y21: int,
@optional y22: int,
@optional y23: int,
@ns.optional y0: int,
@ns.optional y1: int,
@ns.optional y2: int,
@ns.optional y3: int,
@ns.optional y4: int,
@ns.optional y5: int,
@ns.optional y6: int,
@ns.optional y7: int,
@ns.optional y8: int,
@ns.optional y9: int,
@ns.optional y10: int,
@ns.optional y11: int,
@ns.optional y12: int,
@ns.optional y13: int,
@ns.optional y14: int,
@ns.optional y15: int,
@ns.optional y16: int,
@ns.optional y17: int,
@ns.optional y18: int,
@ns.optional y19: int,
@ns.optional y20: int,
@ns.optional y21: int,
@ns.optional y22: int,
@ns.optional y23: int,
z: int,
}

Expand All @@ -64,8 +64,8 @@ let h: config = {...v, y1: 22}

type small_config = {
x: int,
@optional y0: int,
@optional y1: int,
@ns.optional y0: int,
@ns.optional y1: int,
z: int,
}

Expand All @@ -78,25 +78,25 @@ let h11 = (v1): small_config => {
}

type partiallyOptional = {
@optional aa: int,
@ns.optional aa: int,
bb: option<int>,
}

let po = {aa: 3, bb: Some(4)}

let _ = {...po, aa: @optional None}
let _ = {...po, aa: @ns.optional None}

let setAA = (ao: option<int>) => {aa: @optional ao, bb: None}
let setAA = (ao: option<int>) => {aa: @ns.optional ao, bb: None}

// Trigger representation mismatch error.
// module M: {
// type partiallyOptional = {
// @optional aa: int,
// @ns.optional aa: int,
// bb: option<int>,
// }
// } = {
// type partiallyOptional = {
// @optional aa: int,
// @optional bb: int,
// @ns.optional aa: int,
// @ns.optional bb: int,
// }
// }
4 changes: 2 additions & 2 deletions jscomp/test/res_debug.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let f = (window, a, b) => {

type r = {
x: int,
@optional y: int,
@ns.optional y: int,
z : int
}

Expand All @@ -47,7 +47,7 @@ let v1 : r = { x : 3
let testMatch = v =>
switch v {
| {y} => y
| {y: @optional None} => 42
| {y: @ns.optional None} => 42
}

let h = '😊'
Expand Down
8 changes: 4 additions & 4 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33357,7 +33357,7 @@ and tree_of_constructor cd =
(name, args, Some ret)

and tree_of_label l =
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "optional") in
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
let typ = match l.ld_type.desc with
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
| _ -> l.ld_type in
Expand Down Expand Up @@ -36187,7 +36187,7 @@ let transl_declaration env sdecl id =
let tcstrs, cstrs = List.split (List.map make_cstr scstrs) in
Ttype_variant tcstrs, Type_variant cstrs
| Ptype_record lbls ->
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "optional") in
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
let optionalLabels =
Ext_list.filter_map lbls
(fun lbl -> if has_optional lbl.pld_attributes then Some lbl.pld_name.txt else None) in
Expand Down Expand Up @@ -40056,7 +40056,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
| _ -> false in
let process_optional_label (ld, pat) =
let exp_optional_attr =
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "optional")
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional")
in
let isFromPamatch = match pat.ppat_desc with
| Ppat_construct ({txt = Lident s}, _) ->
Expand Down Expand Up @@ -40782,7 +40782,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
| _ -> false in
let process_optional_label (id, ld, e) =
let exp_optional_attr =
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "optional")
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional")
in
if label_is_optional ld && not exp_optional_attr then
let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in
Expand Down
Loading