diff --git a/CHANGELOG.md b/CHANGELOG.md index fda24ed8bd..7135a174a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/ml/translcore.ml b/jscomp/ml/translcore.ml index c138c0c137..d8e4568088 100644 --- a/jscomp/ml/translcore.ml +++ b/jscomp/ml/translcore.ml @@ -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 @@ -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 @@ -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 diff --git a/jscomp/test/async_inline.js b/jscomp/test/async_inline.js index 917e89991e..be36ca2a3a 100644 --- a/jscomp/test/async_inline.js +++ b/jscomp/test/async_inline.js @@ -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 */ diff --git a/jscomp/test/async_inline.res b/jscomp/test/async_inline.res index fa7da47385..ede76f1821 100644 --- a/jscomp/test/async_inline.res +++ b/jscomp/test/async_inline.res @@ -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 \ No newline at end of file diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 482ef0ecc9..39ab3adc77 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -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 @@ -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 @@ -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 diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 3d8ea533a7..1867dfaee2 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -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 @@ -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 @@ -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 diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index dc2f017a2a..656aee9d6c 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -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 @@ -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 @@ -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