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 new file mode 100644 index 0000000000..e044450570 --- /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 definition as its argument. Example: %%private(let a = "Hello") \ 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..c61c09f981 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -474,6 +474,9 @@ 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 definition as its argument. Example: %%%%private(let a = "Hello")|}; aux (Ext_list.rev_map_append work acc (fun x -> self.structure_item self x))