Skip to content

Commit fa0fc36

Browse files
committed
ppx: handle Pexp_function
1 parent 8163498 commit fa0fc36

File tree

2 files changed

+49
-44
lines changed

2 files changed

+49
-44
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
@@ -586,6 +586,7 @@ let preprocess_literal_object mappper fields :
586586
let rec create_meth_ty exp =
587587
match exp.pexp_desc with
588588
| Pexp_fun (label, _, _, body) -> Arg.make ~label () :: create_meth_ty body
589+
| Pexp_function _ -> [ Arg.make () ]
589590
| _ -> []
590591
in
591592
let fun_ty = create_meth_ty body in

ppx/ppx_js/tests/gen.mlt

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,24 @@ let o () =
224224
{|
225225
let o () =
226226
(fun (type res) ->
227-
fun (type t12) ->
228-
fun (type t13) ->
229-
fun (t13 : res Js_of_ocaml.Js.t -> t12 -> t13)
230-
(_ :
231-
res Js_of_ocaml.Js.t ->
232-
(res Js_of_ocaml.Js.t -> t12 -> t13 Js_of_ocaml.Js.meth) ->
233-
res)
234-
: res Js_of_ocaml.Js.t->
235-
Js_of_ocaml.Js.Unsafe.obj
236-
[|("m1",
237-
(Js_of_ocaml.Js.Unsafe.inject
238-
(Js_of_ocaml.Js.wrap_meth_callback t13)))|])
227+
fun (type t13) ->
228+
fun (type t12) ->
229+
fun (type t14) ->
230+
fun (t14 : res Js_of_ocaml.Js.t -> t13 -> t12 -> t14)
231+
(_ :
232+
res Js_of_ocaml.Js.t ->
233+
(res Js_of_ocaml.Js.t ->
234+
t13 -> t12 -> t14 Js_of_ocaml.Js.meth)
235+
-> res)
236+
: res Js_of_ocaml.Js.t->
237+
Js_of_ocaml.Js.Unsafe.obj
238+
[|("m1",
239+
(Js_of_ocaml.Js.Unsafe.inject
240+
(Js_of_ocaml.Js.wrap_meth_callback t14)))|])
239241
(fun _ a -> function | b -> a + b)
240242
((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
241243
val o :
242-
unit -> < m1 : int -> (int -> int) Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
244+
unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
243245
<fun>
244246
|}]
245247

@@ -255,22 +257,24 @@ let o () =
255257
{|
256258
let o () =
257259
(fun (type res) ->
258-
fun (type t14) ->
260+
fun (type t16) ->
259261
fun (type t15) ->
260-
fun (t15 : res Js_of_ocaml.Js.t -> t14 -> t15)
261-
(_ :
262-
res Js_of_ocaml.Js.t ->
263-
(res Js_of_ocaml.Js.t -> t14 -> t15 Js_of_ocaml.Js.meth) ->
264-
res)
265-
: res Js_of_ocaml.Js.t->
266-
Js_of_ocaml.Js.Unsafe.obj
267-
[|("m1",
268-
(Js_of_ocaml.Js.Unsafe.inject
269-
(Js_of_ocaml.Js.wrap_meth_callback t15)))|])
262+
fun (type t17) ->
263+
fun (t17 : res Js_of_ocaml.Js.t -> t16 -> t15 -> t17)
264+
(_ :
265+
res Js_of_ocaml.Js.t ->
266+
(res Js_of_ocaml.Js.t ->
267+
t16 -> t15 -> t17 Js_of_ocaml.Js.meth)
268+
-> res)
269+
: res Js_of_ocaml.Js.t->
270+
Js_of_ocaml.Js.Unsafe.obj
271+
[|("m1",
272+
(Js_of_ocaml.Js.Unsafe.inject
273+
(Js_of_ocaml.Js.wrap_meth_callback t17)))|])
270274
(fun _ a -> function | 0 -> a | b -> a + b)
271275
((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
272276
val o :
273-
unit -> < m1 : int -> (int -> int) Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
277+
unit -> < m1 : int -> int -> int Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
274278
<fun>
275279
|}]
276280

@@ -286,16 +290,16 @@ let o () =
286290
{|
287291
let o () =
288292
(fun (type res) ->
289-
fun (type t16) ->
290-
fun (t16 : res Js_of_ocaml.Js.t -> t16)
293+
fun (type t18) ->
294+
fun (t18 : res Js_of_ocaml.Js.t -> t18)
291295
(_ :
292296
res Js_of_ocaml.Js.t ->
293-
(res Js_of_ocaml.Js.t -> t16 Js_of_ocaml.Js.meth) -> res)
297+
(res Js_of_ocaml.Js.t -> t18 Js_of_ocaml.Js.meth) -> res)
294298
: res Js_of_ocaml.Js.t->
295299
Js_of_ocaml.Js.Unsafe.obj
296300
[|("m1",
297301
(Js_of_ocaml.Js.Unsafe.inject
298-
(Js_of_ocaml.Js.wrap_meth_callback t16)))|])
302+
(Js_of_ocaml.Js.wrap_meth_callback t18)))|])
299303
(fun _ (type b) a -> function | 0 -> a | b -> a + b)
300304
((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
301305
val o :
@@ -315,18 +319,18 @@ let o () =
315319
{|
316320
let o () =
317321
(fun (type res) ->
318-
fun (type t17) ->
319-
fun (type t18) ->
320-
fun (t18 : res Js_of_ocaml.Js.t -> t17 -> t18)
322+
fun (type t19) ->
323+
fun (type t20) ->
324+
fun (t20 : res Js_of_ocaml.Js.t -> t19 -> t20)
321325
(_ :
322326
res Js_of_ocaml.Js.t ->
323-
(res Js_of_ocaml.Js.t -> t17 -> t18 Js_of_ocaml.Js.meth) ->
327+
(res Js_of_ocaml.Js.t -> t19 -> t20 Js_of_ocaml.Js.meth) ->
324328
res)
325329
: res Js_of_ocaml.Js.t->
326330
Js_of_ocaml.Js.Unsafe.obj
327331
[|("m1",
328332
(Js_of_ocaml.Js.Unsafe.inject
329-
(Js_of_ocaml.Js.wrap_meth_callback t18)))|])
333+
(Js_of_ocaml.Js.wrap_meth_callback t20)))|])
330334
(fun _ a (type b) -> function | 0 -> a | b -> a + b)
331335
((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
332336
val o :
@@ -343,21 +347,21 @@ let o () =
343347
[%%expect {|
344348
let o () =
345349
(fun (type res) ->
346-
fun (type t19) ->
347-
fun (type t20) ->
348-
fun (t20 : res Js_of_ocaml.Js.t -> t19 -> t20)
350+
fun (type t21) ->
351+
fun (type t22) ->
352+
fun (t22 : res Js_of_ocaml.Js.t -> t21 -> t22)
349353
(_ :
350354
res Js_of_ocaml.Js.t ->
351-
(res Js_of_ocaml.Js.t -> t19 -> t20 Js_of_ocaml.Js.meth) ->
355+
(res Js_of_ocaml.Js.t -> t21 -> t22 Js_of_ocaml.Js.meth) ->
352356
res)
353357
: res Js_of_ocaml.Js.t->
354358
Js_of_ocaml.Js.Unsafe.obj
355359
[|("m1",
356360
(Js_of_ocaml.Js.Unsafe.inject
357-
(Js_of_ocaml.Js.wrap_meth_callback t20)))|])
361+
(Js_of_ocaml.Js.wrap_meth_callback t22)))|])
358362
(fun _ a -> ignore a) ((fun self m1 -> object method m1 = m1 self end)
359363
[@merlin.hide ]);;
360-
val o : unit -> < m1 : 't19 -> unit Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
364+
val o : unit -> < m1 : 't21 -> unit Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =
361365
<fun>
362366
|}]
363367

@@ -369,16 +373,16 @@ let o () =
369373
[%%expect {|
370374
let o () =
371375
(fun (type res) ->
372-
fun (type t21) ->
373-
fun (t21 : res Js_of_ocaml.Js.t -> t21)
376+
fun (type t23) ->
377+
fun (t23 : res Js_of_ocaml.Js.t -> t23)
374378
(_ :
375379
res Js_of_ocaml.Js.t ->
376-
(res Js_of_ocaml.Js.t -> t21 Js_of_ocaml.Js.meth) -> res)
380+
(res Js_of_ocaml.Js.t -> t23 Js_of_ocaml.Js.meth) -> res)
377381
: res Js_of_ocaml.Js.t->
378382
Js_of_ocaml.Js.Unsafe.obj
379383
[|("m1",
380384
(Js_of_ocaml.Js.Unsafe.inject
381-
(Js_of_ocaml.Js.wrap_meth_callback t21)))|])
385+
(Js_of_ocaml.Js.wrap_meth_callback t23)))|])
382386
(fun _ (type a) (a : a) -> ignore a)
383387
((fun self m1 -> object method m1 = m1 self end)[@merlin.hide ]);;
384388
val o : unit -> < m1 : ('a -> unit) Js_of_ocaml.Js.meth > Js_of_ocaml.Js.t =

0 commit comments

Comments
 (0)