From 7e1cd78e34ccce8f77ae0a48a05d4cfc38f3db03 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 11 Aug 2025 16:44:15 +0200 Subject: [PATCH 1/3] Fix issue with ast conversion on functions with attributes on arguments. Fixes https://github.com/rescript-lang/rescript/issues/7753 --- tests/syntax_tests/data/ast-mapping/FunWithAttribute.res | 1 + .../data/ast-mapping/expected/FunWithAttribute.res.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/syntax_tests/data/ast-mapping/FunWithAttribute.res create mode 100644 tests/syntax_tests/data/ast-mapping/expected/FunWithAttribute.res.txt 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..2a2559745c --- /dev/null +++ b/tests/syntax_tests/data/ast-mapping/expected/FunWithAttribute.res.txt @@ -0,0 +1 @@ +type fn = (~foo: string) => int From 4c3c8806e64233279e80656ab4457bd1aac81242 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 11 Aug 2025 16:47:19 +0200 Subject: [PATCH 2/3] Adapt conversion from old parsetree Now that function attributes and first-argument attributes are split, they need to be re-joined in the old parse tree. This means that after a ppx, both will be on the first argument. --- compiler/ml/ast_mapper_to0.ml | 4 +++- .../data/ast-mapping/expected/FunWithAttribute.res.txt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) 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/expected/FunWithAttribute.res.txt b/tests/syntax_tests/data/ast-mapping/expected/FunWithAttribute.res.txt index 2a2559745c..92b00b8bf9 100644 --- a/tests/syntax_tests/data/ast-mapping/expected/FunWithAttribute.res.txt +++ b/tests/syntax_tests/data/ast-mapping/expected/FunWithAttribute.res.txt @@ -1 +1 @@ -type fn = (~foo: string) => int +type fn = (@as("something") ~foo: string) => int From 856879b23085b31c413c95e8145a2e251846c149 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 11 Aug 2025 17:10:48 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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