Skip to content

Commit

Permalink
Fix ppx mapper and add example.
Browse files Browse the repository at this point in the history
The arity attribute goes on the `Function$` ast node, not the `Pexp_fun` one.
  • Loading branch information
cristianoc committed Dec 15, 2024
1 parent e0dd14e commit 1328fa1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 1 addition & 3 deletions compiler/ml/ast_mapper_from0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ module E = struct
| [] -> assert false
in
match arg1 with
| Some
({pexp_desc = Pexp_fun (l, eo, p, e, _); pexp_attributes = attrs} as
e1) ->
| Some ({pexp_desc = Pexp_fun (l, eo, p, e, _)} as e1) ->
let arity = attributes_to_arity attrs in
{e1 with pexp_desc = Pexp_fun (l, eo, p, e, Some arity)}
| _ -> exp1)
Expand Down
7 changes: 1 addition & 6 deletions compiler/ml/ast_mapper_to0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,8 @@ module E = struct
] );
]
in
let e =
{
e with
pexp_attributes = arity_to_attributes arity @ e.pexp_attributes;
}
in
Ast_helper0.Exp.construct
~attrs:(arity_to_attributes arity)
(Location.mkloc (Longident.Lident "Function$") e.pexp_loc)
(Some e))
| Pexp_apply (e, l) ->
Expand Down
2 changes: 2 additions & 0 deletions tests/tools_tests/ppx/TestPpx.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ module Arity = {
external useState: (unit => 'state) => string = "useState"

let _ = useState(() => 0)

let fpromise = async (promise, _x) => await promise
5 changes: 5 additions & 0 deletions tests/tools_tests/src/expected/TestPpx.res.jsout
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ let Arity = {

React.useState(() => 0);

async function fpromise(promise, _x) {
return await promise;
}

let a = "A";

let b = "B";
Expand All @@ -47,4 +51,5 @@ exports.M = M;
exports.vv = vv;
exports.OptionalFields = OptionalFields;
exports.Arity = Arity;
exports.fpromise = fpromise;
/* Not a pure module */

0 comments on commit 1328fa1

Please sign in to comment.