From b47df8bfa810e74b599f4d57af1332fa56df0e9a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 6 Feb 2023 10:37:40 +0100 Subject: [PATCH] Fix issue with async context and locally abstract types This is a port of the compiler part of https://github.com/rescript-lang/rescript-compiler/pull/5982 to 10.1. --- CHANGELOG.md | 2 ++ jscomp/frontend/bs_builtin_ppx.ml | 5 +++++ jscomp/napkin/CHANGELOG.md | 1 + lib/4.06.1/unstable/js_compiler.ml | 11 +++++++---- lib/4.06.1/unstable/js_playground_compiler.ml | 11 +++++++---- lib/4.06.1/whole_compiler.ml | 11 +++++++---- syntax | 2 +- 7 files changed, 30 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7135a174a7..4829236fa9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ - 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 +- Fix issue with printing async functions with locally abstract types https://github.com/rescript-lang/syntax/pull/732 +- Fix issue with async context and locally abstract types https://github.com/rescript-lang/rescript-compiler/pull/5985 # 10.1.2 diff --git a/jscomp/frontend/bs_builtin_ppx.ml b/jscomp/frontend/bs_builtin_ppx.ml index d1499b0410..89bb650ec4 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -115,6 +115,11 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) | true, pexp_attributes -> Ast_bs_open.convertBsErrorFunction e.pexp_loc self pexp_attributes cases) + | 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 diff --git a/jscomp/napkin/CHANGELOG.md b/jscomp/napkin/CHANGELOG.md index e92c49b5ee..91c51a7e5c 100644 --- a/jscomp/napkin/CHANGELOG.md +++ b/jscomp/napkin/CHANGELOG.md @@ -58,6 +58,7 @@ - Fix an issue where error messages related to duplicate props were displayed without a loc and were unclear https://github.com/rescript-lang/syntax/pull/728 - 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 printing async functions with locally abstract types https://github.com/rescript-lang/syntax/pull/732 #### :eyeglasses: Spec Compliance diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 39ab3adc77..65d2165297 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -49739,10 +49739,8 @@ let funExpr expr = | expr -> (attrsBefore, List.rev acc, expr) in match expr with - | { - pexp_desc = Pexp_fun (_, _defaultExpr, _pattern, _returnExpr); - pexp_attributes = attrs; - } as expr -> + | {pexp_desc = Pexp_fun _ | Pexp_newtype _; pexp_attributes = attrs} as expr + -> collect attrs [] {expr with pexp_attributes = []} | expr -> collect [] [] expr @@ -272986,6 +272984,11 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) | true, pexp_attributes -> Ast_bs_open.convertBsErrorFunction e.pexp_loc self pexp_attributes cases) + | 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 diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 1867dfaee2..65b4d9ce74 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -49739,10 +49739,8 @@ let funExpr expr = | expr -> (attrsBefore, List.rev acc, expr) in match expr with - | { - pexp_desc = Pexp_fun (_, _defaultExpr, _pattern, _returnExpr); - pexp_attributes = attrs; - } as expr -> + | {pexp_desc = Pexp_fun _ | Pexp_newtype _; pexp_attributes = attrs} as expr + -> collect attrs [] {expr with pexp_attributes = []} | expr -> collect [] [] expr @@ -272986,6 +272984,11 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) | true, pexp_attributes -> Ast_bs_open.convertBsErrorFunction e.pexp_loc self pexp_attributes cases) + | 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 diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 656aee9d6c..33b611753f 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -225711,10 +225711,8 @@ let funExpr expr = | expr -> (attrsBefore, List.rev acc, expr) in match expr with - | { - pexp_desc = Pexp_fun (_, _defaultExpr, _pattern, _returnExpr); - pexp_attributes = attrs; - } as expr -> + | {pexp_desc = Pexp_fun _ | Pexp_newtype _; pexp_attributes = attrs} as expr + -> collect attrs [] {expr with pexp_attributes = []} | expr -> collect [] [] expr @@ -283370,6 +283368,11 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) | true, pexp_attributes -> Ast_bs_open.convertBsErrorFunction e.pexp_loc self pexp_attributes cases) + | 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 diff --git a/syntax b/syntax index 392c10018b..2ed49eadcf 160000 --- a/syntax +++ b/syntax @@ -1 +1 @@ -Subproject commit 392c10018be5a17bef652752098daa96e8fce3f8 +Subproject commit 2ed49eadcfa1b112b7dc6681bb269c72e6e06fa9