Skip to content

Commit f98d8c2

Browse files
authored
Fix formatting of uncurried function with constraint on return type. (#6143)
* Fix formatting of uncurried function with constraint on return type. See #6141 * Fix parens on uncurried func on lhs of `->`. Fixes #6141 * Update CHANGELOG.md * more test
1 parent a991c05 commit f98d8c2

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
- Add support for extensible records (e.g. `type t = {...t1, x:int, ...t2}`) https://github.com/rescript-lang/rescript-compiler/pull/5715
1818

19+
#### :bug: Bug Fix
20+
21+
- Fix formatting and parentheses placement in uncurried functions with constraints. https://github.com/rescript-lang/rescript-compiler/pull/6143
22+
1923
# 11.0.0-alpha.2
2024

2125
#### :rocket: Main New Feature

res_syntax/src/res_parens.ml

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ let binaryExprOperand ~isLhs expr =
132132
Pexp_constraint _ | Pexp_fun _ | Pexp_function _ | Pexp_newtype _;
133133
} ->
134134
Parenthesized
135+
| _ when Ast_uncurried.exprIsUncurriedFun expr -> Parenthesized
135136
| expr when ParsetreeViewer.isBinaryExpression expr -> Parenthesized
136137
| expr when ParsetreeViewer.isTernaryExpr expr -> Parenthesized
137138
| {pexp_desc = Pexp_lazy _ | Pexp_assert _} when isLhs -> Parenthesized
@@ -441,6 +442,7 @@ let includeModExpr modExpr =
441442
let arrowReturnTypExpr typExpr =
442443
match typExpr.Parsetree.ptyp_desc with
443444
| Parsetree.Ptyp_arrow _ -> true
445+
| _ when Ast_uncurried.typeIsUncurriedFun typExpr -> true
444446
| _ -> false
445447

446448
let patternRecordRowRhs (pattern : Parsetree.pattern) =

res_syntax/tests/printer/expr/UncurriedByDefault.res

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ type callback4 = (. ReactEvent.Mouse.t) => unit as 'callback
7171
type callback5 = (. ReactEvent.Mouse.t) => (unit as 'u)
7272
type callback6 = ((. ReactEvent.Mouse.t) => unit) as 'callback
7373

74+
let foo = (. ()) => ()
75+
let fn = (_x): ((. unit) => unit) => foo
76+
let fooC = () => ()
77+
let fnC = (_x): ((unit) => unit) => fooC
78+
79+
let a = ((. ()) => "foo")->Ok
80+
let aC = (() => "foo")->Ok
81+
7482
@@uncurried.swap
7583

7684
let cApp = foo(. 3)
@@ -143,3 +151,7 @@ type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback
143151
type callback4 = ReactEvent.Mouse.t => unit as 'callback
144152
type callback5 = ReactEvent.Mouse.t => (unit as 'u)
145153
type callback6 = (ReactEvent.Mouse.t => unit) as 'callback
154+
155+
let fooU = () => ()
156+
let fnU = (_x): ((unit) => unit) => fooC
157+
let aU = (() => "foo")->Ok

res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ type callback4 = ((. ReactEvent.Mouse.t) => unit) as 'callback
7171
type callback5 = (. ReactEvent.Mouse.t) => (unit as 'u)
7272
type callback6 = ((. ReactEvent.Mouse.t) => unit) as 'callback
7373

74+
let foo = (. ()) => ()
75+
let fn = (_x): ((. unit) => unit) => foo
76+
let fooC = () => ()
77+
let fnC = (_x): (unit => unit) => fooC
78+
79+
let a = ((. ()) => "foo")->Ok
80+
let aC = (() => "foo")->Ok
81+
7482
@@uncurried.swap
7583

7684
let cApp = foo(. 3)
@@ -143,3 +151,7 @@ type callback3 = ((. ReactEvent.Mouse.t) => unit) as 'callback
143151
type callback4 = (ReactEvent.Mouse.t => unit) as 'callback
144152
type callback5 = ReactEvent.Mouse.t => (unit as 'u)
145153
type callback6 = (ReactEvent.Mouse.t => unit) as 'callback
154+
155+
let fooU = () => ()
156+
let fnU = (_x): (unit => unit) => fooC
157+
let aU = (() => "foo")->Ok

0 commit comments

Comments
 (0)