From 0cee83faa0f27f57bc47e21ae12a5bb9515683a2 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Wed, 29 Nov 2023 10:17:47 +0100 Subject: [PATCH] Fix issue where an inline record with attributes did not parse. This did not parse without a `,` after the field: ```res type inlineWithAttrs = | A({@as("VALUE") value: string}) ``` Fixes https://github.com/rescript-lang/rescript-compiler/issues/6497 --- jscomp/syntax/src/res_core.ml | 11 +++++++---- .../grammar/expressions/expected/record.res.txt | 5 ++++- .../tests/parsing/grammar/expressions/record.res | 4 +++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index b2d2b012309..d27f61a03a2 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -4675,12 +4675,15 @@ and parseConstrDeclArgs p = let attrs = if optional then optionalAttr :: attrs else attrs in - Parser.expect Comma p; {field with Parsetree.pld_attributes = attrs} in - first - :: parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations - ~closing:Rbrace ~f:parseFieldDeclarationRegion p + if p.token = Rbrace then [first] + else ( + Parser.expect Comma p; + first + :: parseCommaDelimitedRegion + ~grammar:Grammar.FieldDeclarations ~closing:Rbrace + ~f:parseFieldDeclarationRegion p) in Parser.expect Rbrace p; Parser.optional p Comma |> ignore; diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/record.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/record.res.txt index 03791249e92..a15646a13db 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/record.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/record.res.txt @@ -42,4 +42,7 @@ type nonrec multipleWithAttrs = { x: int ; y: string [@res.optional ][@attr ]} type nonrec singleWithAttrs = { - y: string [@res.optional ][@attr ]} \ No newline at end of file + y: string [@res.optional ][@attr ]} +type nonrec inlineWithAttrs = + | A of { + value: string [@as {js|VALUE|js}]} \ No newline at end of file diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/record.res b/jscomp/syntax/tests/parsing/grammar/expressions/record.res index 8a29bfa92c7..8a78964ae75 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/record.res +++ b/jscomp/syntax/tests/parsing/grammar/expressions/record.res @@ -49,4 +49,6 @@ type ttt = {x:int, y?: string} type multipleWithAttrs = {x:int, @attr y?: string} -type singleWithAttrs = {@attr y?: string} \ No newline at end of file +type singleWithAttrs = {@attr y?: string} + +type inlineWithAttrs = | A({@as("VALUE") value: string}) \ No newline at end of file