Skip to content

Commit fd26d3a

Browse files
authored
Fix mutable nested record (#7470)
* Check for more tokens * Add test * Update CHANGELOG
1 parent a838193 commit fd26d3a

File tree

6 files changed

+30
-3
lines changed

6 files changed

+30
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- Fix printer removing private for empty record. https://github.com/rescript-lang/rescript/pull/7448
3838
- Fix: handle dynamic imports with module aliases. https://github.com/rescript-lang/rescript/pull/7452
3939
- Fix missing unescaping when accessing prop with exotic name. https://github.com/rescript-lang/rescript/pull/7469
40+
- Fix syntax error with mutable nested record. https://github.com/rescript-lang/rescript/pull/7470
4041

4142
#### :house: Internal
4243

Example.res

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
type foo = {bar: int}
2+
3+
type a = {
4+
k: {"x": int},
5+
mutable f: int,
6+
g: {
7+
@as("ad") g1: int,
8+
mutable g2: int
9+
}
10+
}
11+
12+
type b = {
13+
...foo,
14+
mutable f: int,
15+
g: string
16+
}

compiler/syntax/src/res_core.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4228,8 +4228,9 @@ and parse_record_or_object_type ?current_type_name_path ?inline_types_context
42284228
Asttypes.Closed
42294229
| _ -> Asttypes.Closed
42304230
in
4231-
match (p.token, inline_types_context, current_type_name_path) with
4232-
| Lident _, Some inline_types_context, Some current_type_name_path ->
4231+
match (inline_types_context, current_type_name_path) with
4232+
| Some inline_types_context, Some current_type_name_path
4233+
when Grammar.is_record_decl_start p.token ->
42334234
let labels =
42344235
parse_comma_delimited_region ~grammar:Grammar.RecordDecl ~closing:Rbrace
42354236
~f:

compiler/syntax/src/res_grammar.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ let is_field_decl_start = function
195195
| _ -> false
196196

197197
let is_record_decl_start = function
198-
| Token.At | Mutable | Lident _ | DotDotDot | String _ -> true
198+
| Token.At | Mutable | Lident _ | DotDotDot -> true
199199
| _ -> false
200200

201201
let is_typ_expr_start = function

tests/tests/src/nested_records_with_type_params.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
let options = {
55
extra: {
6+
extraField: {
7+
theField: true
8+
},
69
name: "test",
710
superExtra: {
811
age: 2222
@@ -18,6 +21,9 @@ let options = {
1821

1922
let opts2 = {
2023
extra: {
24+
extraField: {
25+
theField: true
26+
},
2127
name: "test",
2228
superExtra: {
2329
age: "1234"

tests/tests/src/nested_records_with_type_params.res

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
type options<'age> = {
22
extra?: {
3+
mutable extraField: {theField: bool},
34
name: string,
45
superExtra?: {age: 'age},
56
otherExtra: option<{test: bool, anotherInlined: {record: bool}}>,
@@ -8,6 +9,7 @@ type options<'age> = {
89

910
let options = {
1011
extra: {
12+
extraField: {theField: true},
1113
name: "test",
1214
superExtra: {
1315
age: 2222,
@@ -18,6 +20,7 @@ let options = {
1820

1921
let opts2: options<string> = {
2022
extra: {
23+
extraField: {theField: true},
2124
name: "test",
2225
superExtra: {
2326
age: "1234",

0 commit comments

Comments
 (0)