Skip to content

Commit 629ccdc

Browse files
authored
Merge pull request #4585 from BuckleScript/fix_4572
fix #4572
2 parents 98aa244 + 33c8f1e commit 629ccdc

File tree

6 files changed

+88
-69
lines changed

6 files changed

+88
-69
lines changed

jscomp/syntax/ast_derive_js_mapper.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ let eraseTypeStr =
7272
)
7373
let unsafeIndex = "_index"
7474
let unsafeIndexGet =
75+
let any = Typ.any () in
7576
Str.primitive
7677
(Val.mk ~prim:[""] {loc = noloc; txt = unsafeIndex} ~attrs:[Ast_attributes.bs_get_index]
77-
(Ast_compatible.arrow (Typ.var "b") (Ast_compatible.arrow (Typ.var "a") (Typ.var "c")))
78+
(Ast_compatible.arrow any (Ast_compatible.arrow any any))
7879
)
7980
let unsafeIndexGetExp = (Exp.ident {loc = noloc; txt = Lident unsafeIndex})
8081
(* JavaScript has allowed trailing commas in array literals since the beginning,

jscomp/syntax/ast_external_process.ml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,24 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
100100
(if ptyp.ptyp_desc = Ptyp_any then
101101
let ptyp_attrs = ptyp.ptyp_attributes in
102102
let result = Ast_attributes.iter_process_bs_string_or_int_as ptyp_attrs in
103-
(* when ppx start dropping attributes
104-
we should warn, there is a trade off whether
105-
we should warn dropped non bs attribute or not
106-
*)
107-
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
108103
match result with
109104
| None ->
110-
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
111-
| Some (Int i) -> (* (_[@bs.as ])*)
112-
(* This type is used in bs.obj only to construct obj type*)
113-
Arg_cst(External_arg_spec.cst_int i)
114-
| Some (Str i)->
115-
Arg_cst (External_arg_spec.cst_string i)
116-
| Some (Js_literal_str s) ->
117-
Arg_cst (External_arg_spec.cst_obj_literal s)
105+
spec_of_ptyp nolabel ptyp
106+
| Some cst -> (* (_[@bs.as ])*)
107+
(* when ppx start dropping attributes
108+
we should warn, there is a trade off whether
109+
we should warn dropped non bs attribute or not
110+
*)
111+
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
112+
begin match cst with
113+
| Int i ->
114+
(* This type is used in bs.obj only to construct obj type*)
115+
Arg_cst(External_arg_spec.cst_int i)
116+
| Str i->
117+
Arg_cst (External_arg_spec.cst_string i)
118+
| Js_literal_str s ->
119+
Arg_cst (External_arg_spec.cst_obj_literal s)
120+
end
118121
else (* ([`a|`b] [@bs.string]) *)
119122
spec_of_ptyp nolabel ptyp
120123
)

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -404951,9 +404951,10 @@ let eraseTypeStr =
404951404951
)
404952404952
let unsafeIndex = "_index"
404953404953
let unsafeIndexGet =
404954+
let any = Typ.any () in
404954404955
Str.primitive
404955404956
(Val.mk ~prim:[""] {loc = noloc; txt = unsafeIndex} ~attrs:[Ast_attributes.bs_get_index]
404956-
(Ast_compatible.arrow (Typ.var "b") (Ast_compatible.arrow (Typ.var "a") (Typ.var "c")))
404957+
(Ast_compatible.arrow any (Ast_compatible.arrow any any))
404957404958
)
404958404959
let unsafeIndexGetExp = (Exp.ident {loc = noloc; txt = Lident unsafeIndex})
404959404960
(* JavaScript has allowed trailing commas in array literals since the beginning,
@@ -406021,21 +406022,24 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
406021406022
(if ptyp.ptyp_desc = Ptyp_any then
406022406023
let ptyp_attrs = ptyp.ptyp_attributes in
406023406024
let result = Ast_attributes.iter_process_bs_string_or_int_as ptyp_attrs in
406024-
(* when ppx start dropping attributes
406025-
we should warn, there is a trade off whether
406026-
we should warn dropped non bs attribute or not
406027-
*)
406028-
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
406029406025
match result with
406030406026
| None ->
406031-
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
406032-
| Some (Int i) -> (* (_[@bs.as ])*)
406033-
(* This type is used in bs.obj only to construct obj type*)
406034-
Arg_cst(External_arg_spec.cst_int i)
406035-
| Some (Str i)->
406036-
Arg_cst (External_arg_spec.cst_string i)
406037-
| Some (Js_literal_str s) ->
406038-
Arg_cst (External_arg_spec.cst_obj_literal s)
406027+
spec_of_ptyp nolabel ptyp
406028+
| Some cst -> (* (_[@bs.as ])*)
406029+
(* when ppx start dropping attributes
406030+
we should warn, there is a trade off whether
406031+
we should warn dropped non bs attribute or not
406032+
*)
406033+
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
406034+
begin match cst with
406035+
| Int i ->
406036+
(* This type is used in bs.obj only to construct obj type*)
406037+
Arg_cst(External_arg_spec.cst_int i)
406038+
| Str i->
406039+
Arg_cst (External_arg_spec.cst_string i)
406040+
| Js_literal_str s ->
406041+
Arg_cst (External_arg_spec.cst_obj_literal s)
406042+
end
406039406043
else (* ([`a|`b] [@bs.string]) *)
406040406044
spec_of_ptyp nolabel ptyp
406041406045
)

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -404951,9 +404951,10 @@ let eraseTypeStr =
404951404951
)
404952404952
let unsafeIndex = "_index"
404953404953
let unsafeIndexGet =
404954+
let any = Typ.any () in
404954404955
Str.primitive
404955404956
(Val.mk ~prim:[""] {loc = noloc; txt = unsafeIndex} ~attrs:[Ast_attributes.bs_get_index]
404956-
(Ast_compatible.arrow (Typ.var "b") (Ast_compatible.arrow (Typ.var "a") (Typ.var "c")))
404957+
(Ast_compatible.arrow any (Ast_compatible.arrow any any))
404957404958
)
404958404959
let unsafeIndexGetExp = (Exp.ident {loc = noloc; txt = Lident unsafeIndex})
404959404960
(* JavaScript has allowed trailing commas in array literals since the beginning,
@@ -406021,21 +406022,24 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
406021406022
(if ptyp.ptyp_desc = Ptyp_any then
406022406023
let ptyp_attrs = ptyp.ptyp_attributes in
406023406024
let result = Ast_attributes.iter_process_bs_string_or_int_as ptyp_attrs in
406024-
(* when ppx start dropping attributes
406025-
we should warn, there is a trade off whether
406026-
we should warn dropped non bs attribute or not
406027-
*)
406028-
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
406029406025
match result with
406030406026
| None ->
406031-
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
406032-
| Some (Int i) -> (* (_[@bs.as ])*)
406033-
(* This type is used in bs.obj only to construct obj type*)
406034-
Arg_cst(External_arg_spec.cst_int i)
406035-
| Some (Str i)->
406036-
Arg_cst (External_arg_spec.cst_string i)
406037-
| Some (Js_literal_str s) ->
406038-
Arg_cst (External_arg_spec.cst_obj_literal s)
406027+
spec_of_ptyp nolabel ptyp
406028+
| Some cst -> (* (_[@bs.as ])*)
406029+
(* when ppx start dropping attributes
406030+
we should warn, there is a trade off whether
406031+
we should warn dropped non bs attribute or not
406032+
*)
406033+
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
406034+
begin match cst with
406035+
| Int i ->
406036+
(* This type is used in bs.obj only to construct obj type*)
406037+
Arg_cst(External_arg_spec.cst_int i)
406038+
| Str i->
406039+
Arg_cst (External_arg_spec.cst_string i)
406040+
| Js_literal_str s ->
406041+
Arg_cst (External_arg_spec.cst_obj_literal s)
406042+
end
406039406043
else (* ([`a|`b] [@bs.string]) *)
406040406044
spec_of_ptyp nolabel ptyp
406041406045
)

lib/4.06.1/unstable/native_ppx.ml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18569,21 +18569,24 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
1856918569
(if ptyp.ptyp_desc = Ptyp_any then
1857018570
let ptyp_attrs = ptyp.ptyp_attributes in
1857118571
let result = Ast_attributes.iter_process_bs_string_or_int_as ptyp_attrs in
18572-
(* when ppx start dropping attributes
18573-
we should warn, there is a trade off whether
18574-
we should warn dropped non bs attribute or not
18575-
*)
18576-
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
1857718572
match result with
1857818573
| None ->
18579-
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
18580-
| Some (Int i) -> (* (_[@bs.as ])*)
18581-
(* This type is used in bs.obj only to construct obj type*)
18582-
Arg_cst(External_arg_spec.cst_int i)
18583-
| Some (Str i)->
18584-
Arg_cst (External_arg_spec.cst_string i)
18585-
| Some (Js_literal_str s) ->
18586-
Arg_cst (External_arg_spec.cst_obj_literal s)
18574+
spec_of_ptyp nolabel ptyp
18575+
| Some cst -> (* (_[@bs.as ])*)
18576+
(* when ppx start dropping attributes
18577+
we should warn, there is a trade off whether
18578+
we should warn dropped non bs attribute or not
18579+
*)
18580+
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
18581+
begin match cst with
18582+
| Int i ->
18583+
(* This type is used in bs.obj only to construct obj type*)
18584+
Arg_cst(External_arg_spec.cst_int i)
18585+
| Str i->
18586+
Arg_cst (External_arg_spec.cst_string i)
18587+
| Js_literal_str s ->
18588+
Arg_cst (External_arg_spec.cst_obj_literal s)
18589+
end
1858718590
else (* ([`a|`b] [@bs.string]) *)
1858818591
spec_of_ptyp nolabel ptyp
1858918592
)

lib/4.06.1/whole_compiler.ml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407499,9 +407499,10 @@ let eraseTypeStr =
407499407499
)
407500407500
let unsafeIndex = "_index"
407501407501
let unsafeIndexGet =
407502+
let any = Typ.any () in
407502407503
Str.primitive
407503407504
(Val.mk ~prim:[""] {loc = noloc; txt = unsafeIndex} ~attrs:[Ast_attributes.bs_get_index]
407504-
(Ast_compatible.arrow (Typ.var "b") (Ast_compatible.arrow (Typ.var "a") (Typ.var "c")))
407505+
(Ast_compatible.arrow any (Ast_compatible.arrow any any))
407505407506
)
407506407507
let unsafeIndexGetExp = (Exp.ident {loc = noloc; txt = Lident unsafeIndex})
407507407508
(* JavaScript has allowed trailing commas in array literals since the beginning,
@@ -408569,21 +408570,24 @@ let refine_arg_type ~(nolabel:bool) (ptyp : Ast_core_type.t)
408569408570
(if ptyp.ptyp_desc = Ptyp_any then
408570408571
let ptyp_attrs = ptyp.ptyp_attributes in
408571408572
let result = Ast_attributes.iter_process_bs_string_or_int_as ptyp_attrs in
408572-
(* when ppx start dropping attributes
408573-
we should warn, there is a trade off whether
408574-
we should warn dropped non bs attribute or not
408575-
*)
408576-
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
408577408573
match result with
408578408574
| None ->
408579-
Bs_syntaxerr.err ptyp.ptyp_loc Invalid_underscore_type_in_external
408580-
| Some (Int i) -> (* (_[@bs.as ])*)
408581-
(* This type is used in bs.obj only to construct obj type*)
408582-
Arg_cst(External_arg_spec.cst_int i)
408583-
| Some (Str i)->
408584-
Arg_cst (External_arg_spec.cst_string i)
408585-
| Some (Js_literal_str s) ->
408586-
Arg_cst (External_arg_spec.cst_obj_literal s)
408575+
spec_of_ptyp nolabel ptyp
408576+
| Some cst -> (* (_[@bs.as ])*)
408577+
(* when ppx start dropping attributes
408578+
we should warn, there is a trade off whether
408579+
we should warn dropped non bs attribute or not
408580+
*)
408581+
Bs_ast_invariant.warn_discarded_unused_attributes ptyp_attrs;
408582+
begin match cst with
408583+
| Int i ->
408584+
(* This type is used in bs.obj only to construct obj type*)
408585+
Arg_cst(External_arg_spec.cst_int i)
408586+
| Str i->
408587+
Arg_cst (External_arg_spec.cst_string i)
408588+
| Js_literal_str s ->
408589+
Arg_cst (External_arg_spec.cst_obj_literal s)
408590+
end
408587408591
else (* ([`a|`b] [@bs.string]) *)
408588408592
spec_of_ptyp nolabel ptyp
408589408593
)

0 commit comments

Comments
 (0)