From de6b1491cfd4ee972e1b64ab680b48749e04eb9d Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Wed, 14 May 2025 14:21:37 +0800 Subject: [PATCH 1/3] Check for more tokens --- compiler/syntax/src/res_core.ml | 4 ++-- compiler/syntax/src/res_grammar.ml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 54c974bd72..d8c8fcf66b 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -4228,8 +4228,8 @@ 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: diff --git a/compiler/syntax/src/res_grammar.ml b/compiler/syntax/src/res_grammar.ml index cfd7525a90..456767c5bc 100644 --- a/compiler/syntax/src/res_grammar.ml +++ b/compiler/syntax/src/res_grammar.ml @@ -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 From a6ab861d38acf402949717288e609af90230050f Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Wed, 14 May 2025 14:41:59 +0800 Subject: [PATCH 2/3] Add test --- compiler/syntax/src/res_core.ml | 3 ++- tests/tests/src/nested_records_with_type_params.mjs | 6 ++++++ tests/tests/src/nested_records_with_type_params.res | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index d8c8fcf66b..897d7f12f4 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -4229,7 +4229,8 @@ and parse_record_or_object_type ?current_type_name_path ?inline_types_context | _ -> Asttypes.Closed in 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 -> + | 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: diff --git a/tests/tests/src/nested_records_with_type_params.mjs b/tests/tests/src/nested_records_with_type_params.mjs index 5530eeee12..5c224909ea 100644 --- a/tests/tests/src/nested_records_with_type_params.mjs +++ b/tests/tests/src/nested_records_with_type_params.mjs @@ -3,6 +3,9 @@ let options = { extra: { + extraField: { + theField: true + }, name: "test", superExtra: { age: 2222 @@ -18,6 +21,9 @@ let options = { let opts2 = { extra: { + extraField: { + theField: true + }, name: "test", superExtra: { age: "1234" diff --git a/tests/tests/src/nested_records_with_type_params.res b/tests/tests/src/nested_records_with_type_params.res index 7427c75a6b..14e3fd92c4 100644 --- a/tests/tests/src/nested_records_with_type_params.res +++ b/tests/tests/src/nested_records_with_type_params.res @@ -1,5 +1,6 @@ type options<'age> = { extra?: { + mutable extraField: {theField: bool}, name: string, superExtra?: {age: 'age}, otherExtra: option<{test: bool, anotherInlined: {record: bool}}>, @@ -8,6 +9,7 @@ type options<'age> = { let options = { extra: { + extraField: {theField: true}, name: "test", superExtra: { age: 2222, @@ -18,6 +20,7 @@ let options = { let opts2: options = { extra: { + extraField: {theField: true}, name: "test", superExtra: { age: "1234", From d64a396bd1e59557affda99d1ee229567f7580c9 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Wed, 14 May 2025 14:50:31 +0800 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 1 + Example.res | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 Example.res diff --git a/CHANGELOG.md b/CHANGELOG.md index 42f8ffe797..1cbaf0399c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Example.res b/Example.res new file mode 100644 index 0000000000..0821f114fc --- /dev/null +++ b/Example.res @@ -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 +}