From 7528ef6776195ad44dfc591334e746c31a37c0d2 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 6 Feb 2023 10:05:48 +0100 Subject: [PATCH] Fix issue with printing async functions with locally abstract types --- CHANGELOG.md | 1 + src/res_parsetree_viewer.ml | 6 ++---- tests/printer/expr/asyncAwait.res | 7 ++++++- tests/printer/expr/expected/asyncAwait.res.txt | 4 ++++ tests/printer/expr/expected/newtype.res.txt | 18 ++++++------------ 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e92c49b5..91c51a7e 100644 --- a/CHANGELOG.md +++ b/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/src/res_parsetree_viewer.ml b/src/res_parsetree_viewer.ml index 374ec7b2..f8e0a0ed 100644 --- a/src/res_parsetree_viewer.ml +++ b/src/res_parsetree_viewer.ml @@ -163,10 +163,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 diff --git a/tests/printer/expr/asyncAwait.res b/tests/printer/expr/asyncAwait.res index c80d6f1f..8642df7e 100644 --- a/tests/printer/expr/asyncAwait.res +++ b/tests/printer/expr/asyncAwait.res @@ -116,4 +116,9 @@ let b4 = await (foo.bar.baz) let c1 = @foo x => @bar y => x + y let c2 = (. x) => y => x+y -let c3 = (. x) => @foo y => x+y \ No newline at end of file +let c3 = (. x) => @foo y => x+y + +let f = async (type a, ()) => { + await Js.Promise.resolve(()) + } + \ No newline at end of file diff --git a/tests/printer/expr/expected/asyncAwait.res.txt b/tests/printer/expr/expected/asyncAwait.res.txt index 4a51a963..34c54e7c 100644 --- a/tests/printer/expr/expected/asyncAwait.res.txt +++ b/tests/printer/expr/expected/asyncAwait.res.txt @@ -139,3 +139,7 @@ let b4 = await foo.bar.baz let c1 = @foo x => @bar y => x + y let c2 = (. x, y) => x + y let c3 = (. x) => @foo y => x + y + +let f = async (type a, ()) => { + await Js.Promise.resolve() +} diff --git a/tests/printer/expr/expected/newtype.res.txt b/tests/printer/expr/expected/newtype.res.txt index 78a7a554..39dc430d 100644 --- a/tests/printer/expr/expected/newtype.res.txt +++ b/tests/printer/expr/expected/newtype.res.txt @@ -1,19 +1,13 @@ let f = (type t, xs: list) => () -let f = (@attr type t, xs: list) => () +let f = @attr (type t, xs: list) => () let f = (type t, xs: list, type s, ys: list) => () -let f = (@attr type t, xs: list, @attr2 type s, ys: list) => () +let f = @attr (type t, xs: list, @attr2 type s, ys: list) => () 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 => Parsetree.expression =