From f15ccf6b48c3455c3f76f548a2e3e2cdd8954b36 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 21 Aug 2025 22:19:49 +0200 Subject: [PATCH 1/2] pass and extend current_type_path in missing place, fixing issue with nested record fields + attributes --- compiler/syntax/src/res_core.ml | 21 +++++++++++++++------ tests/tests/src/nested_records.mjs | 8 ++++++++ tests/tests/src/nested_records.res | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index ab9d0d4cee..676bef687d 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -16,6 +16,11 @@ type inline_types_context = { params: (Parsetree.core_type * Asttypes.variance) list; } +let extend_current_type_name_path current_type_name_path field_name = + match current_type_name_path with + | None -> None + | Some path -> Some (path @ [field_name]) + module Recover = struct let default_expr () = let id = Location.mknoloc "rescript.exprhole" in @@ -4667,7 +4672,7 @@ and parse_string_field_declaration p = (* field-decl ::= * | [mutable] field-name : poly-typexpr * | attributes field-decl *) -and parse_field_declaration p = +and parse_field_declaration ?current_type_name_path ?inline_types_context p = let start_pos = p.Parser.start_pos in let attrs = parse_attributes p in let mut = @@ -4684,7 +4689,10 @@ and parse_field_declaration p = match p.Parser.token with | Colon -> Parser.next p; - parse_poly_type_expr p + let current_type_name_path = + extend_current_type_name_path current_type_name_path name.txt + in + parse_poly_type_expr ?current_type_name_path ?inline_types_context p | _ -> Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} [] in @@ -4718,9 +4726,7 @@ and parse_field_declaration_region ?current_type_name_path ?inline_types_context let lident, loc = parse_lident p in let name = Location.mkloc lident loc in let current_type_name_path = - match current_type_name_path with - | None -> None - | Some current_type_name_path -> Some (current_type_name_path @ [name.txt]) + extend_current_type_name_path current_type_name_path name.txt in let optional = parse_optional_label p in let typ = @@ -5379,7 +5385,10 @@ and parse_record_or_object_decl ?current_type_name_path ?inline_types_context p p | attr :: _ as attrs -> let first = - let field = parse_field_declaration p in + let field = + parse_field_declaration ?current_type_name_path + ?inline_types_context p + in Parser.optional p Comma |> ignore; { field with diff --git a/tests/tests/src/nested_records.mjs b/tests/tests/src/nested_records.mjs index 2664b1d9ae..acf48f9164 100644 --- a/tests/tests/src/nested_records.mjs +++ b/tests/tests/src/nested_records.mjs @@ -16,7 +16,15 @@ let options = { } }; +let location = { + location_area: { + name: "test", + url: "test" + } +}; + export { options, + location, } /* No side effect */ diff --git a/tests/tests/src/nested_records.res b/tests/tests/src/nested_records.res index ec507c813d..493a76f439 100644 --- a/tests/tests/src/nested_records.res +++ b/tests/tests/src/nested_records.res @@ -15,3 +15,18 @@ let options = { otherExtra: Some({test: true, anotherInlined: {record: true}}), }, } + +type location = { + @as("location_area") + locationArea: { + name: string, + url: string, + }, +} + +let location = { + locationArea: { + name: "test", + url: "test", + }, +} From 92c71524eb6e9280693695cb9d9edc6f5c64aeb5 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Thu, 21 Aug 2025 22:21:19 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf61f0caab..910f2e6c19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ #### :bug: Bug fix - Preserve `@as(...)` decorator on record fields when creating interface. https://github.com/rescript-lang/rescript/pull/7779 +- Fix parse error with nested record types and attributes on the field name that has the nested record type. https://github.com/rescript-lang/rescript/pull/7781 #### :memo: Documentation