diff --git a/CHANGELOG.md b/CHANGELOG.md index 7468b33748..d7327ab5b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ # 11.1.0-rc.2 (Unreleased) +#### :bug: Bug Fix + +- Fix issue with async and newtype in uncurried mode. https://github.com/rescript-lang/rescript-compiler/pull/6601 + # 11.1.0-rc.1 #### :rocket: New Feature diff --git a/jscomp/ml/ast_async.ml b/jscomp/ml/ast_async.ml index d16b193a4c..b1552cd9a2 100644 --- a/jscomp/ml/ast_async.ml +++ b/jscomp/ml/ast_async.ml @@ -13,12 +13,18 @@ let add_promise_type ?(loc = Location.none) ~async let add_async_attribute ~async (body : Parsetree.expression) = if async then - { - body with - pexp_attributes = - ({txt = "res.async"; loc = Location.none}, PStr []) - :: body.pexp_attributes; - } + ( + match body.pexp_desc with + | Pexp_construct (x, Some e) when Ast_uncurried.exprIsUncurriedFun body -> + {body with pexp_desc = Pexp_construct (x, Some {e with pexp_attributes = + ({txt = "res.async"; loc = Location.none}, PStr []) :: e.pexp_attributes} )} + | _ -> + { + body with + pexp_attributes = + ({txt = "res.async"; loc = Location.none}, PStr []) + :: body.pexp_attributes; + }) else body let rec add_promise_to_result ~loc (e : Parsetree.expression) = diff --git a/jscomp/test/async_await.js b/jscomp/test/async_await.js index 0c674d3b90..d376f50acf 100644 --- a/jscomp/test/async_await.js +++ b/jscomp/test/async_await.js @@ -34,6 +34,10 @@ var toplevelAwait = await topFoo(); var toplevelAwait2 = Caml_array.get(arr, await topFoo()); +async function f(value) { + return await Promise.resolve(1); +} + exports.next = next; exports.useNext = useNext; exports.Make = Make; @@ -41,4 +45,5 @@ exports.topFoo = topFoo; exports.arr = arr; exports.toplevelAwait = toplevelAwait; exports.toplevelAwait2 = toplevelAwait2; +exports.f = f; /* toplevelAwait Not a pure module */ diff --git a/jscomp/test/async_await.res b/jscomp/test/async_await.res index fd7bf92f34..85aafb08bd 100644 --- a/jscomp/test/async_await.res +++ b/jscomp/test/async_await.res @@ -16,3 +16,7 @@ let arr = [1, 2, 3] let toplevelAwait = await topFoo() let toplevelAwait2 = arr[await topFoo()] + +let f = async (type input, value: input) => { + await Js.Promise.resolve(. 1) +} \ No newline at end of file