Skip to content
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: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
- printer: pad record braces with spaces (@anmonteiro,
[#2859](https://github.com/reasonml/reason/pull/2859))
- printer: don't escape infix keywords (@syaiful6,
[#2872](https://github.com/reasonml/reason/pull/2859))
[#2872](https://github.com/reasonml/reason/pull/2874))
- fix(printer): wrap `Ppat_constraint` in parentheses (@anmonteiro,
[#2874](https://github.com/reasonml/reason/pull/2874))

## 3.16.0

Expand Down
10 changes: 9 additions & 1 deletion src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5571,17 +5571,24 @@ let createFormatter () =
sixteenTuple = echoTuple ( * 0, * 0, * 0 * ); *)

method formatSimplePatternBinding
?(wrap=false)
labelOpener
layoutPattern
typeConstraint
appTerms =
let letPattern =
let layoutPattern =
match typeConstraint, wrap with
| (Some (_, `Constraint), true) -> makeList ~wrap:("(","") [layoutPattern]
| (Some _ | None), _ -> layoutPattern
in
label ~break:`Never ~space:true (atom labelOpener) layoutPattern
in
let upUntilEqual =
match typeConstraint with
| None -> letPattern
| Some (tc, `Constraint) -> formatTypeConstraint letPattern tc
| Some (tc, `Constraint) ->
makeList ~wrap:(("", if wrap then ")" else "")) [ formatTypeConstraint letPattern tc ]
| Some (tc, `Coercion ground) -> formatCoerce letPattern ground tc
in
let includingEqual =
Expand Down Expand Up @@ -6223,6 +6230,7 @@ let createFormatter () =
in
let appTerms = self#unparseExprApplicationItems expr in
self#formatSimplePatternBinding
~wrap:true
prefixText
layoutPattern
typeLayout
Expand Down
2 changes: 1 addition & 1 deletion test/4.10/attributes-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ Print the formatted file
)
This will get sugared to `let ([@attr] x2) : int = xInt`
*/
let ([@attr] x2): int = xInt;
let (([@attr] x2): int) = xInt;
/**
Attribute on the pattern holding the constraint:
pattern(
Expand Down
2 changes: 1 addition & 1 deletion test/4.12/attributes-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ Print the formatted file
)
This will get sugared to `let ([@attr] x2) : int = xInt`
*/
let ([@attr] x2): int = xInt;
let (([@attr] x2): int) = xInt;
/**
Attribute on the pattern holding the constraint:
pattern(
Expand Down
6 changes: 3 additions & 3 deletions test/basicStructures.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ Format basicStructures
*/;
let x: int = 10;
let x: int = 10;
let x: int = 10;
let x: int = (10: int);
let (x: int) = 10;
let (x: int) = (10: int);
/* let (x:int) = (10:string); */
/* let (x:string) = ("hello":int); */

Expand All @@ -341,7 +341,7 @@ Format basicStructures

/* In Reason, types look like the data they model! Tuples are no exception. */
type pairOfInts = (int, int);
let letBindingWithTypeConstraint: int = 10;
let (letBindingWithTypeConstraint: int) = 10;
let (tupleItem: int, withTypeConstraint: int) = (
10,
20,
Expand Down
2 changes: 1 addition & 1 deletion test/general-syntax-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ Format general implementation syntax
/* We could even force that consistency with let bindings - it's allowed
currently but not forced.
*/
let myAnnotatedValBinding: int = 10;
let (myAnnotatedValBinding: int) = 10;

/* Class functions (constructors) and methods are unified in the same way */

Expand Down
4 changes: 2 additions & 2 deletions test/patternMatching.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ Print the formatted file
type aOrB =
| A(int)
| B(int);
let (nestedAnnotation: int): int = 0;
let (A(i) | B(i)): aOrB = A(0);
let ((nestedAnnotation: int): int) = 0;
let ((A(i) | B(i)): aOrB) = A(0);

type test_foo =
| VariantType1
Expand Down
4 changes: 2 additions & 2 deletions test/wrapping-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2217,12 +2217,12 @@ Format wrapping in .re files
someVar3,
);

let theTupleTypeAnnotationShouldWrap: (
let (theTupleTypeAnnotationShouldWrap: (
string,
string,
string,
string,
) = (
)) = (
"now these tuple values should wrap",
"now these tuple values should wrap",
"now these tuple values should wrap",
Expand Down
Loading