Skip to content

Fix formatting of uncurried function with constraint on return type. #6143

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 4 commits into from
Apr 13, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions res_syntax/src/res_parens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) =
Expand Down
12 changes: 12 additions & 0 deletions res_syntax/tests/printer/expr/UncurriedByDefault.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
12 changes: 12 additions & 0 deletions res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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