Skip to content

Fix issue with nested async functions #5983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ These are only breaking changes for unformatted code.
- Fix type inference issue with uncurried functions applied to a single unit argument. The issue was introduced in https://github.com/rescript-lang/rescript-compiler/pull/5907 when adding support to `foo()` when `foo` has only optional arguments. https://github.com/rescript-lang/rescript-compiler/pull/5970
- Fix issue where uncurried functions were incorrectly converting the type of a prop given as a default value to curried https://github.com/rescript-lang/rescript-compiler/pull/5971
- Fix issue with error messages for uncurried functions where expected and given type were swapped https://github.com/rescript-lang/rescript-compiler/pull/5973
- Fix issue with nested async functions, where the inner function would be emitted without `async` https://github.com/rescript-lang/rescript-compiler/pull/5983

#### :nail_care: Polish

Expand Down
6 changes: 4 additions & 2 deletions jscomp/ml/translcore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ let rec cut n l =

let try_ids = Hashtbl.create 8

let has_async_attribute exp = exp.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async")

let rec transl_exp e =
List.iter (Translattribute.check_attribute e) e.exp_attributes;
transl_exp0 e
Expand All @@ -695,7 +697,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
| Texp_let (rec_flag, pat_expr_list, body) ->
transl_let rec_flag pat_expr_list (transl_exp body)
| Texp_function { arg_label = _; param; cases; partial } ->
let async = e.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async") in
let async = has_async_attribute e in
let params, body, return_unit =
let pl = push_defaults e.exp_loc [] cases partial in
transl_function e.exp_loc partial param pl
Expand Down Expand Up @@ -1036,7 +1038,7 @@ and transl_function loc partial param cases =
} as exp;
};
]
when Parmatch.inactive ~partial pat ->
when Parmatch.inactive ~partial pat && not (exp |> has_async_attribute) ->
let params, body, return_unit =
transl_function exp.exp_loc partial' param' cases
in
Expand Down
14 changes: 14 additions & 0 deletions jscomp/test/async_inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ var tui = 3;

var tuia = uncurriedIdAsync(3);

function nested1(param) {
return async function (y) {
return await y;
};
}

async function nested2(param) {
return async function (y) {
return await y;
};
}

var tci = 3;

exports.willBeInlined = willBeInlined;
Expand All @@ -76,4 +88,6 @@ exports.tci = tci;
exports.tcia = tcia;
exports.tui = tui;
exports.tuia = tuia;
exports.nested1 = nested1;
exports.nested2 = nested2;
/* inlined Not a pure module */
6 changes: 5 additions & 1 deletion jscomp/test/async_inline.res
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ let uncurriedIdAsync = async (.x ) => x
let tci = curriedId(3)
let tcia = curriedIdAsync(3)
let tui = uncurriedId(. 3)
let tuia = uncurriedIdAsync(. 3)
let tuia = uncurriedIdAsync(. 3)

let nested1 = () => async (y) => await y

let nested2 = async () => async (y) => await y