Skip to content

Fix issue with async and locally abstract types #5982

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 @@ -56,6 +56,7 @@ These are only breaking changes for unformatted code.
- 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
- Fix issue with async context check, and printer, for async functions with locally abstract type https://github.com/rescript-lang/rescript-compiler/pull/5982

#### :nail_care: Polish

Expand Down
5 changes: 5 additions & 0 deletions jscomp/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
(* Treat @this (. x, y, z) => ... just like @this (x, y, z) => ... *)
let fun_expr = Ast_uncurried.exprExtractUncurriedFun e in
self.expr self fun_expr
| Pexp_newtype (s, body) ->
let async = Ast_attributes.has_async_payload e.pexp_attributes <> None in
let body = Ast_async.add_async_attribute ~async body in
let res = self.expr self body in
{e with pexp_desc = Pexp_newtype(s, res)}
| Pexp_fun (label, _, pat, body) -> (
let async = Ast_attributes.has_async_payload e.pexp_attributes <> None in
match Ast_attributes.process_attributes_rev e.pexp_attributes with
Expand Down
2 changes: 1 addition & 1 deletion res_syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ let funExpr expr =
| expr -> (uncurried, attrsBefore, List.rev acc, expr)
in
match expr with
| {pexp_desc = Pexp_fun _} ->
| {pexp_desc = Pexp_fun _ | Pexp_newtype _} ->
collect ~uncurried:false ~nFun:0 expr.pexp_attributes []
{expr with pexp_attributes = []}
| _ when Ast_uncurried.exprIsUncurriedFun expr ->
Expand Down
4 changes: 4 additions & 0 deletions res_syntax/tests/printer/expr/asyncAwait.res
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ let c3 = (. x) => @foo y => x+y

type t1 = (. int) => string => bool
type t2 = (. int, string) => bool

let f = async (type a, ()) => {
await Js.Promise.resolve(())
}
4 changes: 4 additions & 0 deletions res_syntax/tests/printer/expr/expected/asyncAwait.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,7 @@ let c3 = (. x) => {@foo y => x + y}

type t1 = (. int) => string => bool
type t2 = (. int, string) => bool

let f = async (type a, ()) => {
await Js.Promise.resolve()
}
18 changes: 6 additions & 12 deletions res_syntax/tests/printer/expr/expected/newtype.res.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
let f = (type t, xs: list<t>) => ()
let f = (@attr type t, xs: list<t>) => ()
let f = @attr (type t, xs: list<t>) => ()
let f = (type t, xs: list<t>, type s, ys: list<s>) => ()
let f = (@attr type t, xs: list<t>, @attr2 type s, ys: list<s>) => ()
let f = @attr (type t, xs: list<t>, @attr2 type s, ys: list<s>) => ()
let f = (type t u v, xs: list<(t, u, v)>) => ()
let f = (@attr type t u v, xs: list<(t, u, v)>) => ()
let f = @attr (type t u v, xs: list<(t, u, v)>) => ()
let f = (type t u v, xs: list<(t, u, v)>, type s w z, ys: list<(s, w, z)>) => ()
let f = (@attr type t u v, xs: list<(t, u, v)>, @attr2 type s w z, ys: list<(s, w, z)>) => ()
let f = (
@attr type t,
@attr type s,
xs: list<(t, s)>,
@attr type u,
@attr type v w,
ys: list<(u, v, w)>,
) => ()
let f = @attr (type t u v, xs: list<(t, u, v)>, @attr2 type s w z, ys: list<(s, w, z)>) => ()
let f = @attr
(type t, @attr type s, xs: list<(t, s)>, @attr type u, @attr type v w, ys: list<(u, v, w)>) => ()

let mk_formatting_gen:
type a b c d e f. formatting_gen<a, b, c, d, e, f> => Parsetree.expression =
Expand Down