Skip to content

Fix printing of nested types in uncurried mode #5826

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 1 commit into from
Nov 18, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ These are only breaking changes for unformatted code.
#### :bug: Bug Fix

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

#### :nail_care: Polish

Expand Down
7 changes: 6 additions & 1 deletion lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54648,6 +54648,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =

and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
let printArrow ~uncurried ?(arity = max_int) typExpr =
(* XXX *)
let attrsBefore, args, returnType =
ParsetreeViewer.arrowType ~arity typExpr
in
Expand Down Expand Up @@ -54680,7 +54681,11 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
let typDoc =
let doc = printTypExpr ~state n cmtTbl in
match n.ptyp_desc with
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
| Ptyp_constr
( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
[{ptyp_desc = Ptyp_arrow _}] )
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
addParens doc
| _ -> doc
in
Doc.group
Expand Down
7 changes: 6 additions & 1 deletion lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54648,6 +54648,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =

and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
let printArrow ~uncurried ?(arity = max_int) typExpr =
(* XXX *)
let attrsBefore, args, returnType =
ParsetreeViewer.arrowType ~arity typExpr
in
Expand Down Expand Up @@ -54680,7 +54681,11 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
let typDoc =
let doc = printTypExpr ~state n cmtTbl in
match n.ptyp_desc with
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
| Ptyp_constr
( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
[{ptyp_desc = Ptyp_arrow _}] )
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
addParens doc
| _ -> doc
in
Doc.group
Expand Down
7 changes: 6 additions & 1 deletion lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109646,6 +109646,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =

and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
let printArrow ~uncurried ?(arity = max_int) typExpr =
(* XXX *)
let attrsBefore, args, returnType =
ParsetreeViewer.arrowType ~arity typExpr
in
Expand Down Expand Up @@ -109678,7 +109679,11 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
let typDoc =
let doc = printTypExpr ~state n cmtTbl in
match n.ptyp_desc with
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
| Ptyp_constr
( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
[{ptyp_desc = Ptyp_arrow _}] )
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
addParens doc
| _ -> doc
in
Doc.group
Expand Down
7 changes: 6 additions & 1 deletion res_syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,7 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =

and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
let printArrow ~uncurried ?(arity = max_int) typExpr =
(* XXX *)
let attrsBefore, args, returnType =
ParsetreeViewer.arrowType ~arity typExpr
in
Expand Down Expand Up @@ -1581,7 +1582,11 @@ and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
let typDoc =
let doc = printTypExpr ~state n cmtTbl in
match n.ptyp_desc with
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
| Ptyp_constr
( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
[{ptyp_desc = Ptyp_arrow _}] )
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
addParens doc
| _ -> doc
in
Doc.group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type upp = (. ()) => (. ()) => int
type uu2 = (. unit, unit) => unit
type up2 = (. (), ()) => unit

type cnested = (string => unit) => unit
type unested = (. (. string) => unit) => unit

let uannpoly: (. 'a) => string = xx
let uannint: (. int) => string = xx

Expand Down Expand Up @@ -70,6 +73,9 @@ type upp = () => () => int
type uu2 = (unit, unit) => unit
type up2 = ((), ()) => unit

type cnested = (. (. string) => unit) => unit
type unested = (string => unit) => unit

let pipe1 = 3->f

let uannpoly: 'a => string = xx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type nonrec uup = (unit -> int Js.Fn.arity0) Js.Fn.arity1
type nonrec upp = int Js.Fn.arity0 Js.Fn.arity0
type nonrec uu2 = (unit -> unit -> unit) Js.Fn.arity2
type nonrec up2 = (unit -> unit -> unit) Js.Fn.arity2
type nonrec cnested = (string -> unit) -> unit
type nonrec unested = ((string -> unit) Js.Fn.arity1 -> unit) Js.Fn.arity1
let (uannpoly : ('a -> string) Js.Fn.arity1) = xx
let (uannint : (int -> string) Js.Fn.arity1) = xx
[@@@uncurried ]
Expand Down Expand Up @@ -86,6 +88,8 @@ type nonrec uup = (unit -> int Js.Fn.arity0) Js.Fn.arity1
type nonrec upp = int Js.Fn.arity0 Js.Fn.arity0
type nonrec uu2 = (unit -> unit -> unit) Js.Fn.arity2
type nonrec up2 = (unit -> unit -> unit) Js.Fn.arity2
type nonrec cnested = (string -> unit) -> unit
type nonrec unested = ((string -> unit) Js.Fn.arity1 -> unit) Js.Fn.arity1
let pipe1 = 3 |.u f
let (uannpoly : ('a -> string) Js.Fn.arity1) = xx
let (uannint : (int -> string) Js.Fn.arity1) = xx
6 changes: 6 additions & 0 deletions res_syntax/tests/printer/expr/UncurriedByDefault.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type upp = (. ()) => (. ()) => int
type uu2 = (. unit, unit) => unit
type up2 = (. (), ()) => unit

type cnested = (string => unit) => unit
type unested = (. (. string) => unit) => unit

let pipe = a->foo(. b, c)

@@uncurried
Expand Down Expand Up @@ -69,4 +72,7 @@ type upp = () => () => int
type uu2 = (unit, unit) => unit
type up2 = ((), ()) => unit

type cnested = (. (. string) => unit) => unit
type unested = (string => unit) => unit

let pipe = a->foo(b, c)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type upp = (. ()) => (. ()) => int
type uu2 = (. unit, unit) => unit
type up2 = (. unit, unit) => unit

type cnested = (string => unit) => unit
type unested = (. (. string) => unit) => unit

let pipe = a->foo(. b, c)

@@uncurried
Expand Down Expand Up @@ -69,4 +72,7 @@ type upp = () => () => int
type uu2 = (unit, unit) => unit
type up2 = (unit, unit) => unit

type cnested = (. (. string) => unit) => unit
type unested = (string => unit) => unit

let pipe = a->foo(b, c)