Skip to content

Commit 6375a55

Browse files
Fix parsing of arrow type with objects in constructor declaration args (rescript-lang#410)
Fixes rescript-lang/syntax#409 The parser should parse `type queryDelta = Compute({"blocked_ids": unit} => unit)` without parens surrounding the object type-expr `{"blocked_ids": unit}`. The parens are optional in this case. In other places like `{"blocked_ids": unit} => unit`, this was already the case.
1 parent 6e22913 commit 6375a55

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

syntax/src/res_core.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4396,7 +4396,11 @@ and parseConstrDeclArgs p =
43964396
) in
43974397
Parser.expect Rbrace p;
43984398
let loc = mkLoc startPos p.prevEndPos in
4399-
let typ = Ast_helper.Typ.object_ ~loc ~attrs:[] fields closedFlag in
4399+
let typ =
4400+
Ast_helper.Typ.object_ ~loc ~attrs:[] fields closedFlag
4401+
|> parseTypeAlias p
4402+
in
4403+
let typ = parseArrowTypeRest ~es6Arrow:true ~startPos typ p in
44004404
Parser.optional p Comma |> ignore;
44014405
let moreArgs =
44024406
parseCommaDelimitedRegion

syntax/tests/parsing/grammar/typedefinition/constructorDeclaration.res

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,8 @@ type node <_, 'value> =
8686
updateF: 'value => 'value,
8787
mutable updatedTime: float,
8888
}): node<derived, 'value>
89+
90+
type delta = Compute({"blocked_ids": unit} => unit)
91+
type queryDelta =
92+
| Compute({"blocked_ids": unit} => unit)
93+
| Compute({"blocked_ids": unit} => unit, {"allowed_ids": unit} => unit)

syntax/tests/parsing/grammar/typedefinition/expected/constructorDeclaration.res.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,10 @@ type nonrec (_, 'value) node =
8484
parent: (_, 'value) node ;
8585
root: (root, 'value) node ;
8686
updateF: 'value -> 'value ;
87-
mutable updatedTime: float } -> (derived, 'value) node
87+
mutable updatedTime: float } -> (derived, 'value) node
88+
type nonrec delta =
89+
| Compute of (< blocked_ids: unit > -> unit)
90+
type nonrec queryDelta =
91+
| Compute of (< blocked_ids: unit > -> unit)
92+
| Compute of (< blocked_ids: unit > -> unit) *
93+
(< allowed_ids: unit > -> unit)

0 commit comments

Comments
 (0)