Skip to content

Commit 1b55a5a

Browse files
committed
Add error messages for dangling doc comments/attributes and mutable in record type definition.
Fixes #6111
1 parent 29e27e4 commit 1b55a5a

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
- 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
3030
- Fix partial application for uncurried functions with labeled args https://github.com/rescript-lang/rescript-compiler/pull/6198
31+
- Add error messages for dangling doc comments/attributes and mutable in record type definition. https://github.com/rescript-lang/rescript-compiler/pull/6206
3132

3233
# 11.0.0-alpha.4
3334

res_syntax/src/res_core.ml

+12-1
Original file line numberDiff line numberDiff line change
@@ -4498,7 +4498,18 @@ and parseFieldDeclarationRegion ?foundObjectField p =
44984498
let loc = mkLoc startPos typ.ptyp_loc.loc_end in
44994499
let attrs = if optional then optionalAttr :: attrs else attrs in
45004500
Some (Ast_helper.Type.field ~attrs ~loc ~mut name typ)
4501-
| _ -> None
4501+
| _ ->
4502+
if attrs <> [] then
4503+
Parser.err ~startPos p
4504+
(Diagnostics.message
4505+
"Attributes and doc comments can only be used at the beginning of a \
4506+
field declaration");
4507+
if mut = Mutable then
4508+
Parser.err ~startPos p
4509+
(Diagnostics.message
4510+
"The `mutable` qualifier can only be used at the beginning of a \
4511+
field declaration");
4512+
None
45024513

45034514
(* record-decl ::=
45044515
* | { field-decl }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Syntax error!
3+
tests/parsing/errors/typeDef/recordDocComment.res:2:16-3:1
4+
5+
1 │ type a = {
6+
2 │ foo: string, /** here */
7+
3 │ }
8+
4 │
9+
10+
Attributes and doc comments can only be used at the beginning of a field declaration
11+
12+
type nonrec a = {
13+
foo: string }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Syntax error!
3+
tests/parsing/errors/typeDef/recordMutable.res:2:16-3:1
4+
5+
1 │ type d = {
6+
2 │ foo: string, mutable
7+
3 │ }
8+
4 │
9+
10+
The `mutable` qualifier can only be used at the beginning of a field declaration
11+
12+
type nonrec d = {
13+
foo: string }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type a = {
2+
foo: string, /** here */
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
type d = {
2+
foo: string, mutable
3+
}

0 commit comments

Comments
 (0)