Skip to content

Fix issue with nested async functions, where the inner function would… #5984

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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
#### :nail_care: Polish

- Add the gap property to jsxDOMStyle https://github.com/rescript-lang/rescript-compiler/pull/5956

#### :bug: Bug Fix
- Fix issue where error messages related to non-existent props were displayed without location information https://github.com/rescript-lang/syntax/pull/730
- 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/syntax/pull/731
- Fix issue with nested async functions, where the inner function would be emitted without `async` https://github.com/rescript-lang/rescript-compiler/pull/5984

# 10.1.2

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 @@ -1021,7 +1023,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 @@ -38,10 +38,24 @@ async function broken$1(someAsyncFunction) {

var broken$2 = broken$1;

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

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

exports.willBeInlined = willBeInlined;
exports.inlined = inlined;
exports.wrapSomethingAsync = wrapSomethingAsync;
exports.wrapSomethingAsync2 = wrapSomethingAsync2;
exports.M = M;
exports.broken = broken$2;
exports.nested1 = nested1;
exports.nested2 = nested2;
/* inlined Not a pure module */
4 changes: 4 additions & 0 deletions jscomp/test/async_inline.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ let broken = async (someAsyncFunction) => {
}

let broken = someAsyncFunction => broken(someAsyncFunction)

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

let nested2 = async () => async (y) => await y
6 changes: 4 additions & 2 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -283499,6 +283499,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 @@ -283513,7 +283515,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 @@ -283839,7 +283841,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
6 changes: 4 additions & 2 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -293507,6 +293507,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 @@ -293521,7 +293523,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 @@ -293847,7 +293849,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
6 changes: 4 additions & 2 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -292966,6 +292966,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 @@ -292980,7 +292982,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 @@ -293306,7 +293308,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