diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aa9bf1fad..c338e7fb60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ #### :rocket: New Feature #### :bug: Bug fix +- Fix issue with ast conversion (for ppx use) on functions with attributes on first argument. https://github.com/rescript-lang/rescript/pull/7761 #### :memo: Documentation diff --git a/compiler/ml/ast_mapper_to0.ml b/compiler/ml/ast_mapper_to0.ml index 57101ff671..006c7d760e 100644 --- a/compiler/ml/ast_mapper_to0.ml +++ b/compiler/ml/ast_mapper_to0.ml @@ -101,7 +101,9 @@ module T = struct | Ptyp_arrow {arg; ret; arity} -> ( let lbl = Asttypes.to_noloc arg.lbl in let typ0 = - arrow ~loc ~attrs lbl (sub.typ sub arg.typ) (sub.typ sub ret) + arrow ~loc + ~attrs:(attrs @ sub.attributes sub arg.attrs) + lbl (sub.typ sub arg.typ) (sub.typ sub ret) in match arity with | None -> typ0 diff --git a/tests/syntax_tests/data/ast-mapping/FunWithAttribute.res b/tests/syntax_tests/data/ast-mapping/FunWithAttribute.res new file mode 100644 index 0000000000..5c94337667 --- /dev/null +++ b/tests/syntax_tests/data/ast-mapping/FunWithAttribute.res @@ -0,0 +1 @@ +type fn = (@as("something") ~foo: string) => int \ No newline at end of file diff --git a/tests/syntax_tests/data/ast-mapping/expected/FunWithAttribute.res.txt b/tests/syntax_tests/data/ast-mapping/expected/FunWithAttribute.res.txt new file mode 100644 index 0000000000..92b00b8bf9 --- /dev/null +++ b/tests/syntax_tests/data/ast-mapping/expected/FunWithAttribute.res.txt @@ -0,0 +1 @@ +type fn = (@as("something") ~foo: string) => int