diff --git a/CHANGES.md b/CHANGES.md
index cb790c597..d9600e030 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,6 +6,7 @@
[#2773](https://github.com/reasonml/reason/pull/2773))
- Wrap `let lazy patterns = ..` in parentheses (`let lazy(patterns) = ..`)
(@anmonteiro, [#2774](https://github.com/reasonml/reason/pull/2774))
+- Print poly variants as normal variansts (@Sander Spies) [#2708](https://github.com/reasonml/reason/pull/2708)
## 3.12.0
diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml
index dfd4ace1b..46bb3e09d 100644
--- a/src/reason-parser/reason_pprint_ast.ml
+++ b/src/reason-parser/reason_pprint_ast.ml
@@ -3118,7 +3118,11 @@ let printer = object(self:'self)
let ll = (List.map (fun t -> atom ("`" ^ t)) tl) in
let tag_list = makeList ~postSpace:true ~break:IfNeed ((atom ">")::ll) in
let type_list = if tl != [] then node_list@[tag_list] else node_list in
- makeList ~wrap:("[" ^ designator,"]") ~pad:(true, false) ~postSpace:true ~break:IfNeed type_list
+ let break = match type_list with
+ | _ :: _ :: _ -> Layout.Always_rec
+ | [] | _ :: [] -> IfNeed
+ in
+ makeList ~wrap:("[" ^ designator,"]") ~pad:(true, false) ~postSpace:true ~break type_list
| Ptyp_class (li, []) -> makeList [atom "#"; self#longident_loc li]
| Ptyp_class (li, l) ->
label
diff --git a/test/4.10/type-jsx.t/run.t b/test/4.10/type-jsx.t/run.t
index 51295c781..83612eaab 100644
--- a/test/4.10/type-jsx.t/run.t
+++ b/test/4.10/type-jsx.t/run.t
@@ -368,7 +368,10 @@ Print the formatted file
/**
* Test no conflict with polymorphic variant types.
*/
- type thisType = [ | `Foo | `Bar];
+ type thisType = [
+ | `Foo
+ | `Bar
+ ];
type t('a) = [< thisType] as 'a;
let asd =
@@ -590,8 +593,8 @@ Print the formatted file
Type-check basics
$ ocamlc -c -pp 'refmt --print binary' -intf-suffix .rei -impl formatted.re
- File "formatted.re", line 460, characters 23-26:
- 460 | ;
+ File "formatted.re", line 463, characters 23-26:
+ 463 | ;
^^^
Warning 43: the label required is not optional.
diff --git a/test/4.12/type-jsx.t/run.t b/test/4.12/type-jsx.t/run.t
index 1b9fe642a..56ae73af7 100644
--- a/test/4.12/type-jsx.t/run.t
+++ b/test/4.12/type-jsx.t/run.t
@@ -368,7 +368,10 @@ Print the formatted file
/**
* Test no conflict with polymorphic variant types.
*/
- type thisType = [ | `Foo | `Bar];
+ type thisType = [
+ | `Foo
+ | `Bar
+ ];
type t('a) = [< thisType] as 'a;
let asd =
@@ -590,8 +593,8 @@ Print the formatted file
Type-check basics
$ ocamlc -c -pp 'refmt --print binary' -intf-suffix .rei -impl formatted.re
- File "formatted.re", line 460, characters 23-26:
- 460 | ;
+ File "formatted.re", line 463, characters 23-26:
+ 463 | ;
^^^
Warning 43 [nonoptional-label]: the label required is not optional.
diff --git a/test/ocaml_identifiers.t/run.t b/test/ocaml_identifiers.t/run.t
index 1f52cfca3..069cae894 100644
--- a/test/ocaml_identifiers.t/run.t
+++ b/test/ocaml_identifiers.t/run.t
@@ -80,7 +80,10 @@ Format OCaml identifiers file
/* Polymorphic variants (probably ok as-is?) */
module P = {
- type t = [ | `pub_ | `method];
+ type t = [
+ | `pub_
+ | `method
+ ];
let x = `method;