From 49062100c609daa8404b96fbd57dcd9a415c7c19 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 28 Oct 2022 06:22:17 +0200 Subject: [PATCH 1/2] Fix issue where async as an id cannot be used with application and labelled arguments. Fixes https://github.com/rescript-lang/syntax/issues/707 --- CHANGELOG.md | 2 ++ src/res_core.ml | 12 ++++++++---- tests/printer/expr/asyncAwait.res | 5 ++++- tests/printer/expr/expected/asyncAwait.res.txt | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b6984cf..6bddeab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,8 @@ - Fix issue where printing nested pipe discards await https://github.com/rescript-lang/syntax/issues/687 - Fix issue where the JSX key type is not an optional string https://github.com/rescript-lang/syntax/pull/693 - Fix issue where the JSX fragment withouth children build error https://github.com/rescript-lang/syntax/pull/704 +- Fix issue where async as an id cannot be used with application and labelled arguments https://github.com/rescript-lang/syntax/issues/707 + #### :eyeglasses: Spec Compliance diff --git a/src/res_core.ml b/src/res_core.ml index b38430df..d535487d 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -232,9 +232,13 @@ let rec goToClosing closingToken state = (* Madness *) let isEs6ArrowExpression ~inTernary p = Parser.lookahead p (fun state -> - (match state.Parser.token with - | Lident "async" -> Parser.next state - | _ -> ()); + let async = + match state.Parser.token with + | Lident "async" -> + Parser.next state; + true + | _ -> false + in match state.Parser.token with | Lident _ | Underscore -> ( Parser.next state; @@ -275,7 +279,7 @@ let isEs6ArrowExpression ~inTernary p = | EqualGreater -> true | _ -> false) | Dot (* uncurried *) -> true - | Tilde -> true + | Tilde when not async -> true | Backtick -> false (* (` always indicates the start of an expr, can't be es6 parameter *) diff --git a/tests/printer/expr/asyncAwait.res b/tests/printer/expr/asyncAwait.res index 765e6597..efabc856 100644 --- a/tests/printer/expr/asyncAwait.res +++ b/tests/printer/expr/asyncAwait.res @@ -98,4 +98,7 @@ let f12 = @a (@b x) => 3 let f13 = @a @b (~x) => 3 let aw = (await (server->start))->foo -let aw = (@foo (server->start))->foo \ No newline at end of file +let aw = (@foo (server->start))->foo + +let foo = async(~a=34) +let bar = async(~a)=>a+1 \ No newline at end of file diff --git a/tests/printer/expr/expected/asyncAwait.res.txt b/tests/printer/expr/expected/asyncAwait.res.txt index bfd223bc..1082a3d8 100644 --- a/tests/printer/expr/expected/asyncAwait.res.txt +++ b/tests/printer/expr/expected/asyncAwait.res.txt @@ -121,3 +121,6 @@ let f13 = (@a @b ~x) => 3 let aw = await (server->start)->foo let aw = @foo (server->start)->foo + +let foo = async(~a=34) +let bar = async (~a) => a + 1 From dd421339658da20c68074254492e514086984513 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 28 Oct 2022 08:31:30 +0200 Subject: [PATCH 2/2] Add parsing test. --- tests/parsing/grammar/expressions/async.res | 5 ++++- tests/parsing/grammar/expressions/expected/async.res.txt | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/parsing/grammar/expressions/async.res b/tests/parsing/grammar/expressions/async.res index b104866d..9f33ef2d 100644 --- a/tests/parsing/grammar/expressions/async.res +++ b/tests/parsing/grammar/expressions/async.res @@ -26,4 +26,7 @@ let async = { result->async->mapAsync(a => doStuff(a)) } -let f = isPositive ? (async (a, b) : int => a + b) : async (c, d) : int => c - d \ No newline at end of file +let f = isPositive ? (async (a, b) : int => a + b) : async (c, d) : int => c - d + +let foo = async(~a=34) +let bar = async(~a)=>a+1 \ No newline at end of file diff --git a/tests/parsing/grammar/expressions/expected/async.res.txt b/tests/parsing/grammar/expressions/expected/async.res.txt index 7aef8ffd..eb4424d9 100644 --- a/tests/parsing/grammar/expressions/expected/async.res.txt +++ b/tests/parsing/grammar/expressions/expected/async.res.txt @@ -25,4 +25,6 @@ let f = ((if isPositive then ((fun a -> fun b -> (a + b : int))[@res.async ]) else (((fun c -> fun d -> (c - d : int)))[@res.async ])) - [@ns.ternary ]) \ No newline at end of file + [@ns.ternary ]) +let foo = async ~a:((34)[@ns.namedArgLoc ]) +let bar = ((fun ~a:((a)[@ns.namedArgLoc ]) -> a + 1)[@res.async ]) \ No newline at end of file