Skip to content

Commit

Permalink
Fix issue with generating async functions inside loops.
Browse files Browse the repository at this point in the history
Fixes #6444
  • Loading branch information
cristianoc committed Nov 9, 2023
1 parent 4755d4a commit 182c6e8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

- Fix issue with GenType and `result` introduced in rc.5. https://github.com/rescript-lang/rescript-compiler/pull/6464
- Fix compiler crash when inlining complex constants in pattern matching. https://github.com/rescript-lang/rescript-compiler/pull/6471
- Fix issue with generating async functions inside loops. https://github.com/rescript-lang/rescript-compiler/pull/6479


# 11.0.0-rc.5

Expand Down
3 changes: 2 additions & 1 deletion jscomp/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,13 @@ and pp_function ~return_unit ~async ~is_method cxt (f : P.t) ~fn_state
| No_name _ -> ()
| Name_non_top name | Name_top name ->
ignore (pp_var_assign inner_cxt f name : cxt));
if async then P.string f L.await;
P.string f L.lparen;
P.string f (L.function_async ~async);
pp_paren_params inner_cxt f lexical;
P.brace_vgroup f 0 (fun _ ->
return_sp f;
P.string f L.function_;
P.string f (L.function_async ~async);
P.space f;
(match fn_state with
| Is_return | No_name _ -> ()
Expand Down
3 changes: 3 additions & 0 deletions jscomp/core/js_dump_lit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)


let await = "await"

let function_ = "function"

let function_async ~async = if async then "async function" else "function"
Expand Down
20 changes: 20 additions & 0 deletions jscomp/test/async_inside_loop.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions jscomp/test/async_inside_loop.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let topLevelAsyncFunction = async () => {
for innerScopeVal in 0 to 3 {
let asyncClosureAccessingScopedVal = async () => {
Js.log2("Accessing scoped var inside loop", innerScopeVal)
await Js.Promise.resolve()
}

await asyncClosureAccessingScopedVal()
}
}

let _ = topLevelAsyncFunction()
3 changes: 2 additions & 1 deletion jscomp/test/build.ninja

Large diffs are not rendered by default.

0 comments on commit 182c6e8

Please sign in to comment.