Skip to content

Commit 816e61c

Browse files
committed
Fix ppx mapper and add example.
The arity attribute goes on the `Function$` ast node, not the `Pexp_fun` one.
1 parent ee7484d commit 816e61c

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

compiler/ml/ast_mapper_from0.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,7 @@ module E = struct
319319
| [] -> assert false
320320
in
321321
match arg1 with
322-
| Some
323-
({pexp_desc = Pexp_fun (l, eo, p, e, _); pexp_attributes = attrs} as
324-
e1) ->
322+
| Some ({pexp_desc = Pexp_fun (l, eo, p, e, _)} as e1) ->
325323
let arity = attributes_to_arity attrs in
326324
{e1 with pexp_desc = Pexp_fun (l, eo, p, e, Some arity)}
327325
| _ -> exp1)

compiler/ml/ast_mapper_to0.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,8 @@ module E = struct
303303
] );
304304
]
305305
in
306-
let e =
307-
{
308-
e with
309-
pexp_attributes = arity_to_attributes arity @ e.pexp_attributes;
310-
}
311-
in
312306
Ast_helper0.Exp.construct
307+
~attrs:(arity_to_attributes arity)
313308
(Location.mkloc (Longident.Lident "Function$") e.pexp_loc)
314309
(Some e))
315310
| Pexp_apply (e, l) ->

tests/tools_tests/ppx/TestPpx.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ module Arity = {
2929
external useState: (unit => 'state) => string = "useState"
3030

3131
let _ = useState(() => 0)
32+
33+
let fpromise = async (promise, _x) => await promise

tests/tools_tests/src/expected/TestPpx.res.jsout

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ let Arity = {
3535

3636
React.useState(() => 0);
3737

38+
async function fpromise(promise, _x) {
39+
return await promise;
40+
}
41+
3842
let a = "A";
3943

4044
let b = "B";
@@ -47,4 +51,5 @@ exports.M = M;
4751
exports.vv = vv;
4852
exports.OptionalFields = OptionalFields;
4953
exports.Arity = Arity;
54+
exports.fpromise = fpromise;
5055
/* Not a pure module */

0 commit comments

Comments
 (0)