Skip to content

Commit c0df1fd

Browse files
committed
Prepare support for ns.optional.
See rescript-lang/syntax#588
1 parent 5258add commit c0df1fd

File tree

8 files changed

+51
-51
lines changed

8 files changed

+51
-51
lines changed

jscomp/ml/printtyp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ and tree_of_constructor cd =
926926
(name, args, Some ret)
927927

928928
and tree_of_label l =
929-
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "optional") in
929+
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
930930
let typ = match l.ld_type.desc with
931931
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
932932
| _ -> l.ld_type in

jscomp/ml/typecore.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
11551155
| _ -> false in
11561156
let process_optional_label (ld, pat) =
11571157
let exp_optional_attr =
1158-
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "optional")
1158+
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional")
11591159
in
11601160
let isFromPamatch = match pat.ppat_desc with
11611161
| Ppat_construct ({txt = Lident s}, _) ->
@@ -1881,7 +1881,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
18811881
| _ -> false in
18821882
let process_optional_label (id, ld, e) =
18831883
let exp_optional_attr =
1884-
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "optional")
1884+
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional")
18851885
in
18861886
if label_is_optional ld && not exp_optional_attr then
18871887
let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in

jscomp/ml/typedecl.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ let transl_declaration env sdecl id =
396396
let tcstrs, cstrs = List.split (List.map make_cstr scstrs) in
397397
Ttype_variant tcstrs, Type_variant cstrs
398398
| Ptype_record lbls ->
399-
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "optional") in
399+
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
400400
let optionalLabels =
401401
Ext_list.filter_map lbls
402402
(fun lbl -> if has_optional lbl.pld_attributes then Some lbl.pld_name.txt else None) in

jscomp/test/record_regression.res

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @@config({flags: ["-bs-diagnose"] })
22

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

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

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

3232
type config = {
3333
x: int,
34-
@optional y0: int,
35-
@optional y1: int,
36-
@optional y2: int,
37-
@optional y3: int,
38-
@optional y4: int,
39-
@optional y5: int,
40-
@optional y6: int,
41-
@optional y7: int,
42-
@optional y8: int,
43-
@optional y9: int,
44-
@optional y10: int,
45-
@optional y11: int,
46-
@optional y12: int,
47-
@optional y13: int,
48-
@optional y14: int,
49-
@optional y15: int,
50-
@optional y16: int,
51-
@optional y17: int,
52-
@optional y18: int,
53-
@optional y19: int,
54-
@optional y20: int,
55-
@optional y21: int,
56-
@optional y22: int,
57-
@optional y23: int,
34+
@ns.optional y0: int,
35+
@ns.optional y1: int,
36+
@ns.optional y2: int,
37+
@ns.optional y3: int,
38+
@ns.optional y4: int,
39+
@ns.optional y5: int,
40+
@ns.optional y6: int,
41+
@ns.optional y7: int,
42+
@ns.optional y8: int,
43+
@ns.optional y9: int,
44+
@ns.optional y10: int,
45+
@ns.optional y11: int,
46+
@ns.optional y12: int,
47+
@ns.optional y13: int,
48+
@ns.optional y14: int,
49+
@ns.optional y15: int,
50+
@ns.optional y16: int,
51+
@ns.optional y17: int,
52+
@ns.optional y18: int,
53+
@ns.optional y19: int,
54+
@ns.optional y20: int,
55+
@ns.optional y21: int,
56+
@ns.optional y22: int,
57+
@ns.optional y23: int,
5858
z: int,
5959
}
6060

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

6565
type small_config = {
6666
x: int,
67-
@optional y0: int,
68-
@optional y1: int,
67+
@ns.optional y0: int,
68+
@ns.optional y1: int,
6969
z: int,
7070
}
7171

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

8080
type partiallyOptional = {
81-
@optional aa: int,
81+
@ns.optional aa: int,
8282
bb: option<int>,
8383
}
8484

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

87-
let _ = {...po, aa: @optional None}
87+
let _ = {...po, aa: @ns.optional None}
8888

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

9191
// Trigger representation mismatch error.
9292
// module M: {
9393
// type partiallyOptional = {
94-
// @optional aa: int,
94+
// @ns.optional aa: int,
9595
// bb: option<int>,
9696
// }
9797
// } = {
9898
// type partiallyOptional = {
99-
// @optional aa: int,
100-
// @optional bb: int,
99+
// @ns.optional aa: int,
100+
// @ns.optional bb: int,
101101
// }
102102
// }

jscomp/test/res_debug.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let f = (window, a, b) => {
2929

3030
type r = {
3131
x: int,
32-
@optional y: int,
32+
@ns.optional y: int,
3333
z : int
3434
}
3535

@@ -47,7 +47,7 @@ let v1 : r = { x : 3
4747
let testMatch = v =>
4848
switch v {
4949
| {y} => y
50-
| {y: @optional None} => 42
50+
| {y: @ns.optional None} => 42
5151
}
5252

5353
let h = '😊'

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33357,7 +33357,7 @@ and tree_of_constructor cd =
3335733357
(name, args, Some ret)
3335833358

3335933359
and tree_of_label l =
33360-
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "optional") in
33360+
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
3336133361
let typ = match l.ld_type.desc with
3336233362
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
3336333363
| _ -> l.ld_type in
@@ -36187,7 +36187,7 @@ let transl_declaration env sdecl id =
3618736187
let tcstrs, cstrs = List.split (List.map make_cstr scstrs) in
3618836188
Ttype_variant tcstrs, Type_variant cstrs
3618936189
| Ptype_record lbls ->
36190-
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "optional") in
36190+
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
3619136191
let optionalLabels =
3619236192
Ext_list.filter_map lbls
3619336193
(fun lbl -> if has_optional lbl.pld_attributes then Some lbl.pld_name.txt else None) in
@@ -40056,7 +40056,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
4005640056
| _ -> false in
4005740057
let process_optional_label (ld, pat) =
4005840058
let exp_optional_attr =
40059-
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "optional")
40059+
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional")
4006040060
in
4006140061
let isFromPamatch = match pat.ppat_desc with
4006240062
| Ppat_construct ({txt = Lident s}, _) ->
@@ -40782,7 +40782,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4078240782
| _ -> false in
4078340783
let process_optional_label (id, ld, e) =
4078440784
let exp_optional_attr =
40785-
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "optional")
40785+
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional")
4078640786
in
4078740787
if label_is_optional ld && not exp_optional_attr then
4078840788
let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33357,7 +33357,7 @@ and tree_of_constructor cd =
3335733357
(name, args, Some ret)
3335833358

3335933359
and tree_of_label l =
33360-
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "optional") in
33360+
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
3336133361
let typ = match l.ld_type.desc with
3336233362
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
3336333363
| _ -> l.ld_type in
@@ -36187,7 +36187,7 @@ let transl_declaration env sdecl id =
3618736187
let tcstrs, cstrs = List.split (List.map make_cstr scstrs) in
3618836188
Ttype_variant tcstrs, Type_variant cstrs
3618936189
| Ptype_record lbls ->
36190-
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "optional") in
36190+
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
3619136191
let optionalLabels =
3619236192
Ext_list.filter_map lbls
3619336193
(fun lbl -> if has_optional lbl.pld_attributes then Some lbl.pld_name.txt else None) in
@@ -40056,7 +40056,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
4005640056
| _ -> false in
4005740057
let process_optional_label (ld, pat) =
4005840058
let exp_optional_attr =
40059-
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "optional")
40059+
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional")
4006040060
in
4006140061
let isFromPamatch = match pat.ppat_desc with
4006240062
| Ppat_construct ({txt = Lident s}, _) ->
@@ -40782,7 +40782,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
4078240782
| _ -> false in
4078340783
let process_optional_label (id, ld, e) =
4078440784
let exp_optional_attr =
40785-
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "optional")
40785+
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional")
4078640786
in
4078740787
if label_is_optional ld && not exp_optional_attr then
4078840788
let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in

lib/4.06.1/whole_compiler.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207888,7 +207888,7 @@ and tree_of_constructor cd =
207888207888
(name, args, Some ret)
207889207889

207890207890
and tree_of_label l =
207891-
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "optional") in
207891+
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
207892207892
let typ = match l.ld_type.desc with
207893207893
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
207894207894
| _ -> l.ld_type in
@@ -210718,7 +210718,7 @@ let transl_declaration env sdecl id =
210718210718
let tcstrs, cstrs = List.split (List.map make_cstr scstrs) in
210719210719
Ttype_variant tcstrs, Type_variant cstrs
210720210720
| Ptype_record lbls ->
210721-
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "optional") in
210721+
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
210722210722
let optionalLabels =
210723210723
Ext_list.filter_map lbls
210724210724
(fun lbl -> if has_optional lbl.pld_attributes then Some lbl.pld_name.txt else None) in
@@ -214587,7 +214587,7 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env
214587214587
| _ -> false in
214588214588
let process_optional_label (ld, pat) =
214589214589
let exp_optional_attr =
214590-
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "optional")
214590+
Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional")
214591214591
in
214592214592
let isFromPamatch = match pat.ppat_desc with
214593214593
| Ppat_construct ({txt = Lident s}, _) ->
@@ -215313,7 +215313,7 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected =
215313215313
| _ -> false in
215314215314
let process_optional_label (id, ld, e) =
215315215315
let exp_optional_attr =
215316-
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "optional")
215316+
Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional")
215317215317
in
215318215318
if label_is_optional ld && not exp_optional_attr then
215319215319
let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in

0 commit comments

Comments
 (0)