Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit cd0a368

Browse files
committed
Fix issue where nested pipe discards await
Fixes #687 Certain nested patterns for binary operators are printed "manually" so the special printing for await is not used.
1 parent 202b8a9 commit cd0a368

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/res_printer.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,17 +3604,23 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
36043604
| [] -> doc
36053605
| _ -> addParens doc
36063606
in
3607+
let isAwait =
3608+
ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes
3609+
in
36073610
let doc =
36083611
Doc.concat
36093612
[
3613+
(if isAwait then Doc.text "await " else Doc.nil);
36103614
leftPrinted;
36113615
printBinaryOperator ~inlineRhs:false operator;
36123616
rightPrinted;
36133617
]
36143618
in
36153619
let doc =
3616-
if (not isLhs) && Parens.rhsBinaryExprOperand operator expr then
3617-
Doc.concat [Doc.lparen; doc; Doc.rparen]
3620+
if
3621+
isAwait
3622+
|| ((not isLhs) && Parens.rhsBinaryExprOperand operator expr)
3623+
then Doc.concat [Doc.lparen; doc; Doc.rparen]
36183624
else doc
36193625
in
36203626
printComments doc cmtTbl expr.pexp_loc

tests/printer/expr/asyncAwait.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ let f11 = (. ~x) => (. ~y) => 3
9696

9797
let f12 = @a (@b x) => 3
9898
let f13 = @a @b (~x) => 3
99+
100+
let aw = (await (server->start))->foo
101+
let aw = (@foo (server->start))->foo

tests/printer/expr/expected/asyncAwait.res.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ let f11 = (. ~x) => (. ~y) => 3
118118

119119
let f12 = @a x => 3
120120
let f13 = (@a @b ~x) => 3
121+
122+
let aw = (await server->start)->foo
123+
let aw = @foo (server->start)->foo

0 commit comments

Comments
 (0)