Skip to content
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

Add error messages for dangling doc comments/attributes and mutable i… #6206

Merged
merged 1 commit into from
Apr 26, 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 @@ -28,6 +28,7 @@

- Make "rescript format" work with node 10 again and set minimum required node version to 10 in package.json. https://github.com/rescript-lang/rescript-compiler/pull/6186
- Fix partial application for uncurried functions with labeled args https://github.com/rescript-lang/rescript-compiler/pull/6198
- Add error messages for dangling doc comments/attributes and mutable in record type definition. https://github.com/rescript-lang/rescript-compiler/pull/6206

# 11.0.0-alpha.4

Expand Down
13 changes: 12 additions & 1 deletion res_syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4498,7 +4498,18 @@ and parseFieldDeclarationRegion ?foundObjectField p =
let loc = mkLoc startPos typ.ptyp_loc.loc_end in
let attrs = if optional then optionalAttr :: attrs else attrs in
Some (Ast_helper.Type.field ~attrs ~loc ~mut name typ)
| _ -> None
| _ ->
if attrs <> [] then
Parser.err ~startPos p
(Diagnostics.message
"Attributes and doc comments can only be used at the beginning of a \
field declaration");
if mut = Mutable then
Parser.err ~startPos p
(Diagnostics.message
"The `mutable` qualifier can only be used at the beginning of a \
field declaration");
None

(* record-decl ::=
* | { field-decl }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Syntax error!
tests/parsing/errors/typeDef/recordDocComment.res:2:16-3:1

1 │ type a = {
2 │ foo: string, /** here */
3 │ }
4 │

Attributes and doc comments can only be used at the beginning of a field declaration

type nonrec a = {
foo: string }
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Syntax error!
tests/parsing/errors/typeDef/recordMutable.res:2:16-3:1

1 │ type d = {
2 │ foo: string, mutable
3 │ }
4 │

The `mutable` qualifier can only be used at the beginning of a field declaration

type nonrec d = {
foo: string }
3 changes: 3 additions & 0 deletions res_syntax/tests/parsing/errors/typeDef/recordDocComment.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type a = {
foo: string, /** here */
}
3 changes: 3 additions & 0 deletions res_syntax/tests/parsing/errors/typeDef/recordMutable.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type d = {
foo: string, mutable
}