Skip to content

Fix mutable nested record #7470

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 3 commits into from
May 14, 2025
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 @@ -37,6 +37,7 @@
- Fix printer removing private for empty record. https://github.com/rescript-lang/rescript/pull/7448
- Fix: handle dynamic imports with module aliases. https://github.com/rescript-lang/rescript/pull/7452
- Fix missing unescaping when accessing prop with exotic name. https://github.com/rescript-lang/rescript/pull/7469
- Fix syntax error with mutable nested record. https://github.com/rescript-lang/rescript/pull/7470

#### :house: Internal

Expand Down
16 changes: 16 additions & 0 deletions Example.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type foo = {bar: int}

type a = {
k: {"x": int},
mutable f: int,
g: {
@as("ad") g1: int,
mutable g2: int
}
}

type b = {
...foo,
mutable f: int,
g: string
}
5 changes: 3 additions & 2 deletions compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4228,8 +4228,9 @@ and parse_record_or_object_type ?current_type_name_path ?inline_types_context
Asttypes.Closed
| _ -> Asttypes.Closed
in
match (p.token, inline_types_context, current_type_name_path) with
| Lident _, Some inline_types_context, Some current_type_name_path ->
match (inline_types_context, current_type_name_path) with
| Some inline_types_context, Some current_type_name_path
when Grammar.is_record_decl_start p.token ->
let labels =
parse_comma_delimited_region ~grammar:Grammar.RecordDecl ~closing:Rbrace
~f:
Expand Down
2 changes: 1 addition & 1 deletion compiler/syntax/src/res_grammar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ let is_field_decl_start = function
| _ -> false

let is_record_decl_start = function
| Token.At | Mutable | Lident _ | DotDotDot | String _ -> true
| Token.At | Mutable | Lident _ | DotDotDot -> true
| _ -> false

let is_typ_expr_start = function
Expand Down
6 changes: 6 additions & 0 deletions tests/tests/src/nested_records_with_type_params.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

let options = {
extra: {
extraField: {
theField: true
},
name: "test",
superExtra: {
age: 2222
Expand All @@ -18,6 +21,9 @@ let options = {

let opts2 = {
extra: {
extraField: {
theField: true
},
name: "test",
superExtra: {
age: "1234"
Expand Down
3 changes: 3 additions & 0 deletions tests/tests/src/nested_records_with_type_params.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type options<'age> = {
extra?: {
mutable extraField: {theField: bool},
name: string,
superExtra?: {age: 'age},
otherExtra: option<{test: bool, anotherInlined: {record: bool}}>,
Expand All @@ -8,6 +9,7 @@ type options<'age> = {

let options = {
extra: {
extraField: {theField: true},
name: "test",
superExtra: {
age: 2222,
Expand All @@ -18,6 +20,7 @@ let options = {

let opts2: options<string> = {
extra: {
extraField: {theField: true},
name: "test",
superExtra: {
age: "1234",
Expand Down