diff --git a/CHANGELOG.md b/CHANGELOG.md index 9396e40285..79d5a004df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ - Add support for extensible records (e.g. `type t = {...t1, x:int, ...t2}`) https://github.com/rescript-lang/rescript-compiler/pull/5715 +#### :bug: Bug Fix + +- Fix formatting and parentheses placement in uncurried functions with constraints. https://github.com/rescript-lang/rescript-compiler/pull/6143 + # 11.0.0-alpha.2 #### :rocket: Main New Feature diff --git a/res_syntax/src/res_parens.ml b/res_syntax/src/res_parens.ml index 93cf6e4213..13e801b5c0 100644 --- a/res_syntax/src/res_parens.ml +++ b/res_syntax/src/res_parens.ml @@ -132,6 +132,7 @@ let binaryExprOperand ~isLhs expr = Pexp_constraint _ | Pexp_fun _ | Pexp_function _ | Pexp_newtype _; } -> Parenthesized + | _ when Ast_uncurried.exprIsUncurriedFun expr -> Parenthesized | expr when ParsetreeViewer.isBinaryExpression expr -> Parenthesized | expr when ParsetreeViewer.isTernaryExpr expr -> Parenthesized | {pexp_desc = Pexp_lazy _ | Pexp_assert _} when isLhs -> Parenthesized @@ -441,6 +442,7 @@ let includeModExpr modExpr = let arrowReturnTypExpr typExpr = match typExpr.Parsetree.ptyp_desc with | Parsetree.Ptyp_arrow _ -> true + | _ when Ast_uncurried.typeIsUncurriedFun typExpr -> true | _ -> false let patternRecordRowRhs (pattern : Parsetree.pattern) = diff --git a/res_syntax/tests/printer/expr/UncurriedByDefault.res b/res_syntax/tests/printer/expr/UncurriedByDefault.res index 7c79cbabc5..758c6155de 100644 --- a/res_syntax/tests/printer/expr/UncurriedByDefault.res +++ b/res_syntax/tests/printer/expr/UncurriedByDefault.res @@ -71,6 +71,14 @@ type callback4 = (. ReactEvent.Mouse.t) => unit as 'callback type callback5 = (. ReactEvent.Mouse.t) => (unit as 'u) type callback6 = ((. ReactEvent.Mouse.t) => unit) as 'callback +let foo = (. ()) => () +let fn = (_x): ((. unit) => unit) => foo +let fooC = () => () +let fnC = (_x): ((unit) => unit) => fooC + +let a = ((. ()) => "foo")->Ok +let aC = (() => "foo")->Ok + @@uncurried.swap let cApp = foo(. 3) @@ -143,3 +151,7 @@ type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback type callback4 = ReactEvent.Mouse.t => unit as 'callback type callback5 = ReactEvent.Mouse.t => (unit as 'u) type callback6 = (ReactEvent.Mouse.t => unit) as 'callback + +let fooU = () => () +let fnU = (_x): ((unit) => unit) => fooC +let aU = (() => "foo")->Ok diff --git a/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt b/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt index 3c3a9c3a77..157a4437d5 100644 --- a/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt +++ b/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt @@ -71,6 +71,14 @@ type callback4 = ((. ReactEvent.Mouse.t) => unit) as 'callback type callback5 = (. ReactEvent.Mouse.t) => (unit as 'u) type callback6 = ((. ReactEvent.Mouse.t) => unit) as 'callback +let foo = (. ()) => () +let fn = (_x): ((. unit) => unit) => foo +let fooC = () => () +let fnC = (_x): (unit => unit) => fooC + +let a = ((. ()) => "foo")->Ok +let aC = (() => "foo")->Ok + @@uncurried.swap let cApp = foo(. 3) @@ -143,3 +151,7 @@ type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback type callback4 = (ReactEvent.Mouse.t => unit) as 'callback type callback5 = ReactEvent.Mouse.t => (unit as 'u) type callback6 = (ReactEvent.Mouse.t => unit) as 'callback + +let fooU = () => () +let fnU = (_x): (unit => unit) => fooC +let aU = (() => "foo")->Ok