Skip to content

Commit c83f57a

Browse files
committed
fix #4572
1 parent 98aa244 commit c83f57a

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
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
)

jscomp/test/build.ninja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ build test/gpr_4442_test.cmi test/gpr_4442_test.cmj : cc test/gpr_4442_test.ml |
328328
build test/gpr_4491_test.cmi test/gpr_4491_test.cmj : cc test/gpr_4491_test.ml | $stdlib
329329
build test/gpr_4494_test.cmi test/gpr_4494_test.cmj : cc test/gpr_4494_test.ml | $stdlib
330330
build test/gpr_4519_test.cmi test/gpr_4519_test.cmj : cc test/gpr_4519_test.ml | test/mt.cmj $stdlib
331+
build test/gpr_4572_test.cmi test/gpr_4572_test.cmj : cc test/gpr_4572_test.ml | $stdlib
331332
build test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib
332333
build test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib
333334
build test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.ml | $stdlib

0 commit comments

Comments
 (0)