Skip to content

Commit ba3f473

Browse files
committed
ppx: handle Pexp_newtype
1 parent fa0fc36 commit ba3f473

File tree

2 files changed

+50
-41
lines changed

2 files changed

+50
-41
lines changed

ppx/ppx_js/lib_internal/ppx_js_internal.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ let preprocess_literal_object mappper fields :
587587
match exp.pexp_desc with
588588
| Pexp_fun (label, _, _, body) -> Arg.make ~label () :: create_meth_ty body
589589
| Pexp_function _ -> [ Arg.make () ]
590+
| Pexp_newtype (_, body) -> create_meth_ty body
590591
| _ -> []
591592
in
592593
let fun_ty = create_meth_ty body in

ppx/ppx_js/tests/gen.mlt

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,24 @@ let o () =
290290
{|
291291
let o () =
292292
(fun (type res) ->
293-
fun (type t18) ->
294-
fun (t18 : res Js_of_ocaml.Js.t -> t18)
295-
(_ :
296-
res Js_of_ocaml.Js.t ->
297-
(res Js_of_ocaml.Js.t -> t18 Js_of_ocaml.Js.meth) -> res)
298-
: res Js_of_ocaml.Js.t->
299-
Js_of_ocaml.Js.Unsafe.obj
300-
[|("m1",
301-
(Js_of_ocaml.Js.Unsafe.inject
302-
(Js_of_ocaml.Js.wrap_meth_callback t18)))|])
293+
fun (type t19) ->
294+
fun (type t18) ->
295+
fun (type t20) ->
296+
fun (t20 : res Js_of_ocaml.Js.t -> t19 -> t18 -> t20)
297+
(_ :
298+
res Js_of_ocaml.Js.t ->
299+
(res Js_of_ocaml.Js.t ->
300+
t19 -> t18 -> t20 Js_of_ocaml.Js.meth)
301+
-> res)
302+
: res Js_of_ocaml.Js.t->
303+
Js_of_ocaml.Js.Unsafe.obj
304+
[|("m1",
305+
(Js_of_ocaml.Js.Unsafe.inject
306+
(Js_of_ocaml.Js.wrap_meth_callback t20)))|])
303307
(fun _ (type b) a -> function | 0 -> a | b -> a + b)
304308
((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
305309
val o :
306-
unit -> < m1 : (int -> int -> int) Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
310+
unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
307311
<fun>
308312
|}]
309313

@@ -319,22 +323,24 @@ let o () =
319323
{|
320324
let o () =
321325
(fun (type res) ->
322-
fun (type t19) ->
323-
fun (type t20) ->
324-
fun (t20 : res Js_of_ocaml.Js.t -> t19 -> t20)
325-
(_ :
326-
res Js_of_ocaml.Js.t ->
327-
(res Js_of_ocaml.Js.t -> t19 -> t20 Js_of_ocaml.Js.meth) ->
328-
res)
329-
: res Js_of_ocaml.Js.t->
330-
Js_of_ocaml.Js.Unsafe.obj
331-
[|("m1",
332-
(Js_of_ocaml.Js.Unsafe.inject
333-
(Js_of_ocaml.Js.wrap_meth_callback t20)))|])
326+
fun (type t22) ->
327+
fun (type t21) ->
328+
fun (type t23) ->
329+
fun (t23 : res Js_of_ocaml.Js.t -> t22 -> t21 -> t23)
330+
(_ :
331+
res Js_of_ocaml.Js.t ->
332+
(res Js_of_ocaml.Js.t ->
333+
t22 -> t21 -> t23 Js_of_ocaml.Js.meth)
334+
-> res)
335+
: res Js_of_ocaml.Js.t->
336+
Js_of_ocaml.Js.Unsafe.obj
337+
[|("m1",
338+
(Js_of_ocaml.Js.Unsafe.inject
339+
(Js_of_ocaml.Js.wrap_meth_callback t23)))|])
334340
(fun _ a (type b) -> function | 0 -> a | b -> a + b)
335341
((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
336342
val o :
337-
unit -> < m1 : int -> (int -> int) Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
343+
unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
338344
<fun>
339345
|}]
340346

@@ -347,21 +353,21 @@ let o () =
347353
[%%expect {|
348354
let o () =
349355
(fun (type res) ->
350-
fun (type t21) ->
351-
fun (type t22) ->
352-
fun (t22 : res Js_of_ocaml.Js.t -> t21 -> t22)
356+
fun (type t24) ->
357+
fun (type t25) ->
358+
fun (t25 : res Js_of_ocaml.Js.t -> t24 -> t25)
353359
(_ :
354360
res Js_of_ocaml.Js.t ->
355-
(res Js_of_ocaml.Js.t -> t21 -> t22 Js_of_ocaml.Js.meth) ->
361+
(res Js_of_ocaml.Js.t -> t24 -> t25 Js_of_ocaml.Js.meth) ->
356362
res)
357363
: res Js_of_ocaml.Js.t->
358364
Js_of_ocaml.Js.Unsafe.obj
359365
[|("m1",
360366
(Js_of_ocaml.Js.Unsafe.inject
361-
(Js_of_ocaml.Js.wrap_meth_callback t22)))|])
367+
(Js_of_ocaml.Js.wrap_meth_callback t25)))|])
362368
(fun _ a -> ignore a) ((fun self m1 -> object method m1 = m1 self end)
363369
[@merlin.hide ]);;
364-
val o : unit -> < m1 : 't21 -> unit Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
370+
val o : unit -> < m1 : 't24 -> unit Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
365371
<fun>
366372
|}]
367373

@@ -373,18 +379,20 @@ let o () =
373379
[%%expect {|
374380
let o () =
375381
(fun (type res) ->
376-
fun (type t23) ->
377-
fun (t23 : res Js_of_ocaml.Js.t -> t23)
378-
(_ :
379-
res Js_of_ocaml.Js.t ->
380-
(res Js_of_ocaml.Js.t -> t23 Js_of_ocaml.Js.meth) -> res)
381-
: res Js_of_ocaml.Js.t->
382-
Js_of_ocaml.Js.Unsafe.obj
383-
[|("m1",
384-
(Js_of_ocaml.Js.Unsafe.inject
385-
(Js_of_ocaml.Js.wrap_meth_callback t23)))|])
382+
fun (type t26) ->
383+
fun (type t27) ->
384+
fun (t27 : res Js_of_ocaml.Js.t -> t26 -> t27)
385+
(_ :
386+
res Js_of_ocaml.Js.t ->
387+
(res Js_of_ocaml.Js.t -> t26 -> t27 Js_of_ocaml.Js.meth) ->
388+
res)
389+
: res Js_of_ocaml.Js.t->
390+
Js_of_ocaml.Js.Unsafe.obj
391+
[|("m1",
392+
(Js_of_ocaml.Js.Unsafe.inject
393+
(Js_of_ocaml.Js.wrap_meth_callback t27)))|])
386394
(fun _ (type a) (a : a) -> ignore a)
387395
((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
388-
val o : unit -> < m1 : ('a -> unit) Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
396+
val o : unit -> < m1 : 't26 -> unit Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
389397
<fun>
390398
|}]

0 commit comments

Comments
 (0)