Skip to content

error message: private extension without body #6175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%%private
let a = 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to make the error message more approachable. Not so clear why a "does not have a body".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message highlights %private. It's not a that doesn't have a body, it's %%private.

image

Maybe %%private extension expects arguments?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes: private expects the definition as argument.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error: The '%%private' extension expects a definition as its argument.

Example usage:
%%private
let a = (x) => x + 2;

In this case, the '%%private' extension is missing a definition as its argument. Please provide a valid definition for the private extension to work as intended.

3 changes: 3 additions & 0 deletions jscomp/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down