From 9db9d0ffe9763126f8b0ce2420bf8ac5c0a0ff24 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Tue, 18 Apr 2023 04:46:49 -0300 Subject: [PATCH 1/2] add error message private extension without body --- .../expected/private_without_body.res.expected | 9 +++++++++ .../super_errors/fixtures/private_without_body.res | 2 ++ jscomp/frontend/bs_builtin_ppx.ml | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 jscomp/build_tests/super_errors/expected/private_without_body.res.expected create mode 100644 jscomp/build_tests/super_errors/fixtures/private_without_body.res diff --git a/jscomp/build_tests/super_errors/expected/private_without_body.res.expected b/jscomp/build_tests/super_errors/expected/private_without_body.res.expected new file mode 100644 index 0000000000..fe4bc7763e --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/private_without_body.res.expected @@ -0,0 +1,9 @@ + + We've found a bug for you! + /.../fixtures/private_without_body.res:1:1-9 + + 1 │ %%private + 2 │ let a = 2 + 3 │ + + %%private extension expects a body \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/private_without_body.res b/jscomp/build_tests/super_errors/fixtures/private_without_body.res new file mode 100644 index 0000000000..cadfcfd3a3 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/private_without_body.res @@ -0,0 +1,2 @@ +%%private +let a = 2 diff --git a/jscomp/frontend/bs_builtin_ppx.ml b/jscomp/frontend/bs_builtin_ppx.ml index 1001a097ac..a84f09e297 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -474,6 +474,8 @@ let rec structure_mapper (self : mapper) (stru : Ast_structure.t) = :: next -> ( match payload with | PStr work -> + if List.length work = 0 then + Location.raise_errorf ~loc "%%%%private extension expects a body"; aux (Ext_list.rev_map_append work acc (fun x -> self.structure_item self x)) From b114b53161349c6a9d575b547ac2c7a66895af78 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Tue, 18 Apr 2023 16:30:47 -0300 Subject: [PATCH 2/2] update error msg --- CHANGELOG.md | 1 + .../super_errors/expected/private_without_body.res.expected | 2 +- jscomp/frontend/bs_builtin_ppx.ml | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 765c686257..d92e2f55f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Fixed subtype checking for record types with "@as" attributes: The subtype relationship now takes into account the compatibility of "@as" attributes between corresponding fields, ensuring correctness in runtime representation. https://github.com/rescript-lang/rescript-compiler/issues/6158 - Emit directive above header comment. https://github.com/rescript-lang/rescript-compiler/pull/6172 +- Add error message to private extension. https://github.com/rescript-lang/rescript-compiler/pull/6175 #### :nail_care: Polish diff --git a/jscomp/build_tests/super_errors/expected/private_without_body.res.expected b/jscomp/build_tests/super_errors/expected/private_without_body.res.expected index fe4bc7763e..e044450570 100644 --- a/jscomp/build_tests/super_errors/expected/private_without_body.res.expected +++ b/jscomp/build_tests/super_errors/expected/private_without_body.res.expected @@ -6,4 +6,4 @@ 2 │ let a = 2 3 │ - %%private extension expects a body \ No newline at end of file + %%private extension expects a definition as its argument. Example: %%private(let a = "Hello") \ No newline at end of file diff --git a/jscomp/frontend/bs_builtin_ppx.ml b/jscomp/frontend/bs_builtin_ppx.ml index a84f09e297..c61c09f981 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -475,7 +475,8 @@ let rec structure_mapper (self : mapper) (stru : Ast_structure.t) = match payload with | PStr work -> if List.length work = 0 then - Location.raise_errorf ~loc "%%%%private extension expects a body"; + Location.raise_errorf ~loc + {|%%%%private extension expects a definition as its argument. Example: %%%%private(let a = "Hello")|}; aux (Ext_list.rev_map_append work acc (fun x -> self.structure_item self x))