Skip to content

Commit f26fb4b

Browse files
committed
Fix issue with async and newtype in uncurried mode.
Fixes #6587
1 parent c9f775c commit f26fb4b

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

jscomp/ml/ast_async.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ let add_promise_type ?(loc = Location.none) ~async
1313

1414
let add_async_attribute ~async (body : Parsetree.expression) =
1515
if async then
16-
{
17-
body with
18-
pexp_attributes =
19-
({txt = "res.async"; loc = Location.none}, PStr [])
20-
:: body.pexp_attributes;
21-
}
16+
(
17+
match body.pexp_desc with
18+
| Pexp_construct (x, Some e) when Ast_uncurried.exprIsUncurriedFun body ->
19+
{body with pexp_desc = Pexp_construct (x, Some {e with pexp_attributes =
20+
({txt = "res.async"; loc = Location.none}, PStr []) :: e.pexp_attributes} )}
21+
| _ ->
22+
{
23+
body with
24+
pexp_attributes =
25+
({txt = "res.async"; loc = Location.none}, PStr [])
26+
:: body.pexp_attributes;
27+
})
2228
else body
2329

2430
let rec add_promise_to_result ~loc (e : Parsetree.expression) =

jscomp/test/async_await.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/async_await.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ let arr = [1, 2, 3]
1616

1717
let toplevelAwait = await topFoo()
1818
let toplevelAwait2 = arr[await topFoo()]
19+
20+
let f = async (type input, value: input) => {
21+
await Js.Promise.resolve(. 1)
22+
}

0 commit comments

Comments
 (0)