Skip to content

Commit b55d5e7

Browse files
committed
Fix printing of nested types in uncurried mode.
1 parent edbe4ef commit b55d5e7

File tree

9 files changed

+47
-4
lines changed

9 files changed

+47
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ These are only breaking changes for unformatted code.
3737
#### :bug: Bug Fix
3838

3939
- Fix issue where uncurried was not supported with pipe https://github.com/rescript-lang/rescript-compiler/pull/5803
40+
- Fix printing of nested types in uncurried mode https://github.com/rescript-lang/rescript-compiler/pull/5826
4041

4142
#### :nail_care: Polish
4243

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54648,6 +54648,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
5464854648

5464954649
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5465054650
let printArrow ~uncurried ?(arity = max_int) typExpr =
54651+
(* XXX *)
5465154652
let attrsBefore, args, returnType =
5465254653
ParsetreeViewer.arrowType ~arity typExpr
5465354654
in
@@ -54680,7 +54681,11 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5468054681
let typDoc =
5468154682
let doc = printTypExpr ~state n cmtTbl in
5468254683
match n.ptyp_desc with
54683-
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
54684+
| Ptyp_constr
54685+
( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
54686+
[{ptyp_desc = Ptyp_arrow _}] )
54687+
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
54688+
addParens doc
5468454689
| _ -> doc
5468554690
in
5468654691
Doc.group

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54648,6 +54648,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
5464854648

5464954649
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5465054650
let printArrow ~uncurried ?(arity = max_int) typExpr =
54651+
(* XXX *)
5465154652
let attrsBefore, args, returnType =
5465254653
ParsetreeViewer.arrowType ~arity typExpr
5465354654
in
@@ -54680,7 +54681,11 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
5468054681
let typDoc =
5468154682
let doc = printTypExpr ~state n cmtTbl in
5468254683
match n.ptyp_desc with
54683-
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
54684+
| Ptyp_constr
54685+
( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
54686+
[{ptyp_desc = Ptyp_arrow _}] )
54687+
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
54688+
addParens doc
5468454689
| _ -> doc
5468554690
in
5468654691
Doc.group

lib/4.06.1/whole_compiler.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109646,6 +109646,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
109646109646

109647109647
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
109648109648
let printArrow ~uncurried ?(arity = max_int) typExpr =
109649+
(* XXX *)
109649109650
let attrsBefore, args, returnType =
109650109651
ParsetreeViewer.arrowType ~arity typExpr
109651109652
in
@@ -109678,7 +109679,11 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
109678109679
let typDoc =
109679109680
let doc = printTypExpr ~state n cmtTbl in
109680109681
match n.ptyp_desc with
109681-
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
109682+
| Ptyp_constr
109683+
( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
109684+
[{ptyp_desc = Ptyp_arrow _}] )
109685+
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
109686+
addParens doc
109682109687
| _ -> doc
109683109688
in
109684109689
Doc.group

res_syntax/src/res_printer.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
15491549

15501550
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
15511551
let printArrow ~uncurried ?(arity = max_int) typExpr =
1552+
(* XXX *)
15521553
let attrsBefore, args, returnType =
15531554
ParsetreeViewer.arrowType ~arity typExpr
15541555
in
@@ -1581,7 +1582,11 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
15811582
let typDoc =
15821583
let doc = printTypExpr ~state n cmtTbl in
15831584
match n.ptyp_desc with
1584-
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
1585+
| Ptyp_constr
1586+
( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
1587+
[{ptyp_desc = Ptyp_arrow _}] )
1588+
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
1589+
addParens doc
15851590
| _ -> doc
15861591
in
15871592
Doc.group

res_syntax/tests/parsing/grammar/expressions/UncurriedByDefault.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type upp = (. ()) => (. ()) => int
3131
type uu2 = (. unit, unit) => unit
3232
type up2 = (. (), ()) => unit
3333

34+
type cnested = (string => unit) => unit
35+
type unested = (. (. string) => unit) => unit
36+
3437
let uannpoly: (. 'a) => string = xx
3538
let uannint: (. int) => string = xx
3639

@@ -70,6 +73,9 @@ type upp = () => () => int
7073
type uu2 = (unit, unit) => unit
7174
type up2 = ((), ()) => unit
7275

76+
type cnested = (. (. string) => unit) => unit
77+
type unested = (string => unit) => unit
78+
7379
let pipe1 = 3->f
7480

7581
let uannpoly: 'a => string = xx

res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type nonrec uup = (unit -> int Js.Fn.arity0) Js.Fn.arity1
4040
type nonrec upp = int Js.Fn.arity0 Js.Fn.arity0
4141
type nonrec uu2 = (unit -> unit -> unit) Js.Fn.arity2
4242
type nonrec up2 = (unit -> unit -> unit) Js.Fn.arity2
43+
type nonrec cnested = (string -> unit) -> unit
44+
type nonrec unested = ((string -> unit) Js.Fn.arity1 -> unit) Js.Fn.arity1
4345
let (uannpoly : ('a -> string) Js.Fn.arity1) = xx
4446
let (uannint : (int -> string) Js.Fn.arity1) = xx
4547
[@@@uncurried ]
@@ -86,6 +88,8 @@ type nonrec uup = (unit -> int Js.Fn.arity0) Js.Fn.arity1
8688
type nonrec upp = int Js.Fn.arity0 Js.Fn.arity0
8789
type nonrec uu2 = (unit -> unit -> unit) Js.Fn.arity2
8890
type nonrec up2 = (unit -> unit -> unit) Js.Fn.arity2
91+
type nonrec cnested = (string -> unit) -> unit
92+
type nonrec unested = ((string -> unit) Js.Fn.arity1 -> unit) Js.Fn.arity1
8993
let pipe1 = 3 |.u f
9094
let (uannpoly : ('a -> string) Js.Fn.arity1) = xx
9195
let (uannint : (int -> string) Js.Fn.arity1) = xx

res_syntax/tests/printer/expr/UncurriedByDefault.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type upp = (. ()) => (. ()) => int
3131
type uu2 = (. unit, unit) => unit
3232
type up2 = (. (), ()) => unit
3333

34+
type cnested = (string => unit) => unit
35+
type unested = (. (. string) => unit) => unit
36+
3437
let pipe = a->foo(. b, c)
3538

3639
@@uncurried
@@ -69,4 +72,7 @@ type upp = () => () => int
6972
type uu2 = (unit, unit) => unit
7073
type up2 = ((), ()) => unit
7174

75+
type cnested = (. (. string) => unit) => unit
76+
type unested = (string => unit) => unit
77+
7278
let pipe = a->foo(b, c)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type upp = (. ()) => (. ()) => int
3131
type uu2 = (. unit, unit) => unit
3232
type up2 = (. unit, unit) => unit
3333

34+
type cnested = (string => unit) => unit
35+
type unested = (. (. string) => unit) => unit
36+
3437
let pipe = a->foo(. b, c)
3538

3639
@@uncurried
@@ -69,4 +72,7 @@ type upp = () => () => int
6972
type uu2 = (unit, unit) => unit
7073
type up2 = (unit, unit) => unit
7174

75+
type cnested = (. (. string) => unit) => unit
76+
type unested = (string => unit) => unit
77+
7278
let pipe = a->foo(b, c)

0 commit comments

Comments
 (0)