Skip to content

Commit d747dc1

Browse files
committed
Fix issue with nested async functions, where the inner function would be emitted without async
1 parent c61fb25 commit d747dc1

7 files changed

+37
-8
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
#### :nail_care: Polish
1616

1717
- Add the gap property to jsxDOMStyle https://github.com/rescript-lang/rescript-compiler/pull/5956
18+
19+
#### :bug: Bug Fix
1820
- Fix issue where error messages related to non-existent props were displayed without location information https://github.com/rescript-lang/syntax/pull/730
1921
- 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
22+
- Fix issue with nested async functions, where the inner function would be emitted without `async`
2023

2124
# 10.1.2
2225

jscomp/ml/translcore.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ let rec cut n l =
681681

682682
let try_ids = Hashtbl.create 8
683683

684+
let has_async_attribute exp = exp.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async")
685+
684686
let rec transl_exp e =
685687
List.iter (Translattribute.check_attribute e) e.exp_attributes;
686688
transl_exp0 e
@@ -695,7 +697,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
695697
| Texp_let (rec_flag, pat_expr_list, body) ->
696698
transl_let rec_flag pat_expr_list (transl_exp body)
697699
| Texp_function { arg_label = _; param; cases; partial } ->
698-
let async = e.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async") in
700+
let async = has_async_attribute e in
699701
let params, body, return_unit =
700702
let pl = push_defaults e.exp_loc [] cases partial in
701703
transl_function e.exp_loc partial param pl
@@ -1021,7 +1023,7 @@ and transl_function loc partial param cases =
10211023
} as exp;
10221024
};
10231025
]
1024-
when Parmatch.inactive ~partial pat ->
1026+
when Parmatch.inactive ~partial pat && not (exp |> has_async_attribute) ->
10251027
let params, body, return_unit =
10261028
transl_function exp.exp_loc partial' param' cases
10271029
in

jscomp/test/async_inline.js

+14
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,24 @@ async function broken$1(someAsyncFunction) {
3838

3939
var broken$2 = broken$1;
4040

41+
function nested1(param) {
42+
return async function (y) {
43+
return await y;
44+
};
45+
}
46+
47+
async function nested2(param) {
48+
return async function (y) {
49+
return await y;
50+
};
51+
}
52+
4153
exports.willBeInlined = willBeInlined;
4254
exports.inlined = inlined;
4355
exports.wrapSomethingAsync = wrapSomethingAsync;
4456
exports.wrapSomethingAsync2 = wrapSomethingAsync2;
4557
exports.M = M;
4658
exports.broken = broken$2;
59+
exports.nested1 = nested1;
60+
exports.nested2 = nested2;
4761
/* inlined Not a pure module */

jscomp/test/async_inline.res

+4
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ let broken = async (someAsyncFunction) => {
3636
}
3737

3838
let broken = someAsyncFunction => broken(someAsyncFunction)
39+
40+
let nested1 = () => async (y) => await y
41+
42+
let nested2 = async () => async (y) => await y

lib/4.06.1/unstable/js_compiler.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -283499,6 +283499,8 @@ let rec cut n l =
283499283499

283500283500
let try_ids = Hashtbl.create 8
283501283501

283502+
let has_async_attribute exp = exp.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async")
283503+
283502283504
let rec transl_exp e =
283503283505
List.iter (Translattribute.check_attribute e) e.exp_attributes;
283504283506
transl_exp0 e
@@ -283513,7 +283515,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
283513283515
| Texp_let (rec_flag, pat_expr_list, body) ->
283514283516
transl_let rec_flag pat_expr_list (transl_exp body)
283515283517
| Texp_function { arg_label = _; param; cases; partial } ->
283516-
let async = e.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async") in
283518+
let async = has_async_attribute e in
283517283519
let params, body, return_unit =
283518283520
let pl = push_defaults e.exp_loc [] cases partial in
283519283521
transl_function e.exp_loc partial param pl
@@ -283839,7 +283841,7 @@ and transl_function loc partial param cases =
283839283841
} as exp;
283840283842
};
283841283843
]
283842-
when Parmatch.inactive ~partial pat ->
283844+
when Parmatch.inactive ~partial pat && not (exp |> has_async_attribute) ->
283843283845
let params, body, return_unit =
283844283846
transl_function exp.exp_loc partial' param' cases
283845283847
in

lib/4.06.1/unstable/js_playground_compiler.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -293507,6 +293507,8 @@ let rec cut n l =
293507293507

293508293508
let try_ids = Hashtbl.create 8
293509293509

293510+
let has_async_attribute exp = exp.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async")
293511+
293510293512
let rec transl_exp e =
293511293513
List.iter (Translattribute.check_attribute e) e.exp_attributes;
293512293514
transl_exp0 e
@@ -293521,7 +293523,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
293521293523
| Texp_let (rec_flag, pat_expr_list, body) ->
293522293524
transl_let rec_flag pat_expr_list (transl_exp body)
293523293525
| Texp_function { arg_label = _; param; cases; partial } ->
293524-
let async = e.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async") in
293526+
let async = has_async_attribute e in
293525293527
let params, body, return_unit =
293526293528
let pl = push_defaults e.exp_loc [] cases partial in
293527293529
transl_function e.exp_loc partial param pl
@@ -293847,7 +293849,7 @@ and transl_function loc partial param cases =
293847293849
} as exp;
293848293850
};
293849293851
]
293850-
when Parmatch.inactive ~partial pat ->
293852+
when Parmatch.inactive ~partial pat && not (exp |> has_async_attribute) ->
293851293853
let params, body, return_unit =
293852293854
transl_function exp.exp_loc partial' param' cases
293853293855
in

lib/4.06.1/whole_compiler.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -292966,6 +292966,8 @@ let rec cut n l =
292966292966

292967292967
let try_ids = Hashtbl.create 8
292968292968

292969+
let has_async_attribute exp = exp.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async")
292970+
292969292971
let rec transl_exp e =
292970292972
List.iter (Translattribute.check_attribute e) e.exp_attributes;
292971292973
transl_exp0 e
@@ -292980,7 +292982,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
292980292982
| Texp_let (rec_flag, pat_expr_list, body) ->
292981292983
transl_let rec_flag pat_expr_list (transl_exp body)
292982292984
| Texp_function { arg_label = _; param; cases; partial } ->
292983-
let async = e.exp_attributes |> List.exists (fun ({txt}, _payload) -> txt = "res.async") in
292985+
let async = has_async_attribute e in
292984292986
let params, body, return_unit =
292985292987
let pl = push_defaults e.exp_loc [] cases partial in
292986292988
transl_function e.exp_loc partial param pl
@@ -293306,7 +293308,7 @@ and transl_function loc partial param cases =
293306293308
} as exp;
293307293309
};
293308293310
]
293309-
when Parmatch.inactive ~partial pat ->
293311+
when Parmatch.inactive ~partial pat && not (exp |> has_async_attribute) ->
293310293312
let params, body, return_unit =
293311293313
transl_function exp.exp_loc partial' param' cases
293312293314
in

0 commit comments

Comments
 (0)