From 0b7d3f341918e39f0aadd6b835d834eda2c43b4b Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Mar 2023 14:11:36 +0100 Subject: [PATCH] Fix printing of uncurried application when the lhs is a function definition. --- CHANGELOG.md | 1 + res_syntax/src/res_parens.ml | 1 + res_syntax/tests/printer/expr/UncurriedByDefault.res | 6 ++++++ .../tests/printer/expr/expected/UncurriedByDefault.res.txt | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 079fc2d513..25e3f669b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ These are only breaking changes for unformatted code. - Fix issue with integer overflow check https://github.com/rescript-lang/rescript-compiler/pull/6028 - Make internal encoding of locations aware of unicode https://github.com/rescript-lang/rescript-compiler/pull/6073 - Fix issue where `foo(x,_)` in uncurried mode would generate a curried function https://github.com/rescript-lang/rescript-compiler/pull/6082 +- Fix printing of uncurried application when the lhs is a function definition https://github.com/rescript-lang/rescript-compiler/pull/6084 #### :nail_care: Polish diff --git a/res_syntax/src/res_parens.ml b/res_syntax/src/res_parens.ml index d6628c8728..93cf6e4213 100644 --- a/res_syntax/src/res_parens.ml +++ b/res_syntax/src/res_parens.ml @@ -55,6 +55,7 @@ let callExpr expr = | Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ ); } -> Parenthesized + | _ when Ast_uncurried.exprIsUncurriedFun expr -> Parenthesized | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes -> Parenthesized | _ -> Nothing) diff --git a/res_syntax/tests/printer/expr/UncurriedByDefault.res b/res_syntax/tests/printer/expr/UncurriedByDefault.res index 9b7e7b1e4f..117687ecad 100644 --- a/res_syntax/tests/printer/expr/UncurriedByDefault.res +++ b/res_syntax/tests/printer/expr/UncurriedByDefault.res @@ -57,6 +57,9 @@ let t4 = (. type a b) => (l: list, x: a) => list{x, ...l} let t5 = (type a b) => (. l: list, x: a) => list{x, ...l} let t6 = (. type a b) => (. l: list, x: a) => list{x, ...l} +let () = (x => ignore(x))(3) +let () = ((. x) => ignore(x))(. 3) + @@uncurried.swap let cApp = foo(. 3) @@ -115,3 +118,6 @@ let t0 = (type a b, l: list, x: a) => list{x, ...l} let t1 = (. type a b, l: list, x: a) => list{x, ...l} let t2 = (type a b, . l: list, x: a) => list{x, ...l} let t3 = (. type a b, . l: list, x: a) => list{x, ...l} + +let () = (x => ignore(x))(3) +let () = ((. x) => ignore(x))(. 3) diff --git a/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt b/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt index 15c4e15836..5ad44bea36 100644 --- a/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt +++ b/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt @@ -57,6 +57,9 @@ let t4 = (type a b, l: list, x: a) => list{x, ...l} let t5 = (. type a b, l: list, x: a) => list{x, ...l} let t6 = (. type a b, l: list, x: a) => list{x, ...l} +let () = (x => ignore(x))(3) +let () = ((. x) => ignore(x))(. 3) + @@uncurried.swap let cApp = foo(. 3) @@ -115,3 +118,6 @@ let t0 = (type a b, l: list, x: a) => list{x, ...l} let t1 = (. type a b, l: list, x: a) => list{x, ...l} let t2 = (. type a b, l: list, x: a) => list{x, ...l} let t3 = (. type a b, l: list, x: a) => list{x, ...l} + +let () = (x => ignore(x))(3) +let () = ((. x) => ignore(x))(. 3)