From ef73ace6d6e8c03b4b2638897fb881766cf6f776 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 15 Apr 2023 19:14:19 +0200 Subject: [PATCH 1/2] Fix parsing of single record spread. --- jscomp/test/DotDotDot.res | 4 ++-- res_syntax/src/res_core.ml | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/jscomp/test/DotDotDot.res b/jscomp/test/DotDotDot.res index 101b8594f2..0a0cf79e94 100644 --- a/jscomp/test/DotDotDot.res +++ b/jscomp/test/DotDotDot.res @@ -20,14 +20,14 @@ type globalProps = { } type anchorProps = { - \"...": globalProps, + ...globalProps, download?: string, href?: string, target?: [#_self | #_blank | #_parent | #_top], } // globalProps only case? -type divProps = {\"...": globalProps} +type divProps = {...globalProps} type svgProps = { ...globalProps, diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index 1f6f5e9a90..f066f5527e 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -4975,15 +4975,20 @@ and parseRecordOrObjectDecl p = (* start of object type spreading, e.g. `type u = {...a, "u": int}` *) Parser.next p; let typ = parseTypExpr p in - let () = - match p.token with - | Rbrace -> - (* {...x}, spread without extra fields *) - Parser.next p - | _ -> Parser.expect Comma p - in match p.token with + | Rbrace -> + (* {...x}, spread without extra fields *) + Parser.next p; + let loc = mkLoc startPos p.prevEndPos in + let dotField = + Ast_helper.Type.field ~loc + {txt = "..."; loc = mkLoc dotdotdotStart dotdotdotEnd} + typ + in + let kind = Parsetree.Ptype_record [dotField] in + (None, Public, kind) | _ -> + Parser.expect Comma p; let loc = mkLoc startPos p.prevEndPos in let dotField = Ast_helper.Type.field ~loc From 9d754fbc692ac3988735600898d65a33f2af299e Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 15 Apr 2023 19:15:36 +0200 Subject: [PATCH 2/2] Update spread.res.txt --- .../parsing/errors/other/expected/spread.res.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/res_syntax/tests/parsing/errors/other/expected/spread.res.txt b/res_syntax/tests/parsing/errors/other/expected/spread.res.txt index 768a71e62b..29664d21d6 100644 --- a/res_syntax/tests/parsing/errors/other/expected/spread.res.txt +++ b/res_syntax/tests/parsing/errors/other/expected/spread.res.txt @@ -62,19 +62,6 @@ Solution: you need to pull out each field you want explicitly. Explanation: a list spread at the tail is efficient, but a spread in the middle would create new lists; out of performance concern, our pattern matching currently guarantees to never create new intermediate data. - Syntax error! - tests/parsing/errors/other/spread.res:9:16-10:4 - - 7 │ let list{...x, ...y} = myList - 8 │ - 9 │ type t = {...a} - 10 │ type t = Foo({...a}) - 11 │ type t = option - 12 │ - - Did you forget a `}` here? - - Syntax error! tests/parsing/errors/other/spread.res:10:20