Skip to content

Commit cde772a

Browse files
authored
Example of broken formatting for foo(a,_) in uncurried mode. (#6148)
* Example of broken formatting for foo(a,_) in uncurried mode. See #6146 * Fix pretty printing. Fixes #6148 * Fix second case. * Update CHANGELOG.md * Somehow roundtrip tests are not happy.
1 parent 9571bdc commit cde772a

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 11.0.0-alpha.4 (Unreleased)
1414

15+
#### :bug: Bug Fix
16+
17+
- Fix broken formatting in uncurried mode for functions with _ placeholder args. https://github.com/rescript-lang/rescript-compiler/pull/6148
18+
1519
# 11.0.0-alpha.3
1620

1721
#### :rocket: Main New Feature

res_syntax/src/res_parsetree_viewer.ml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,27 @@ let funExpr expr =
154154
let rec collect ~uncurried ~nFun attrsBefore acc expr =
155155
match expr with
156156
| {
157-
pexp_desc =
158-
Pexp_fun
159-
( Nolabel,
160-
None,
161-
{ppat_desc = Ppat_var {txt = "__x"}},
162-
{pexp_desc = Pexp_apply _} );
163-
} ->
157+
pexp_desc =
158+
Pexp_fun
159+
( Nolabel,
160+
None,
161+
{ppat_desc = Ppat_var {txt = "__x"}},
162+
{pexp_desc = Pexp_apply _} );
163+
}
164+
| {
165+
pexp_desc =
166+
Pexp_construct
167+
( {txt = Lident "Function$"},
168+
Some
169+
{
170+
pexp_desc =
171+
Pexp_fun
172+
( Nolabel,
173+
None,
174+
{ppat_desc = Ppat_var {txt = "__x"}},
175+
{pexp_desc = Pexp_apply _} );
176+
} );
177+
} ->
164178
(uncurried, attrsBefore, List.rev acc, rewriteUnderscoreApply expr)
165179
| {pexp_desc = Pexp_newtype (stringLoc, rest); pexp_attributes = attrs} ->
166180
let stringLocs, returnExpr = collectNewTypes [stringLoc] rest in

res_syntax/src/res_printer.ml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,18 +2671,32 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
26712671
(Doc.concat
26722672
[attrs; parametersDoc; typConstraintDoc; Doc.text " =>"; returnExprDoc])
26732673
in
2674+
let uncurried = Ast_uncurried.exprIsUncurriedFun e in
2675+
let e_fun =
2676+
if uncurried then Ast_uncurried.exprExtractUncurriedFun e else e
2677+
in
26742678
let printedExpression =
2675-
match e.pexp_desc with
2679+
match e_fun.pexp_desc with
26762680
| Pexp_fun
26772681
( Nolabel,
26782682
None,
26792683
{ppat_desc = Ppat_var {txt = "__x"}},
2680-
{pexp_desc = Pexp_apply _} ) ->
2684+
{pexp_desc = Pexp_apply _} )
2685+
| Pexp_construct
2686+
( {txt = Lident "Function$"},
2687+
Some
2688+
{
2689+
pexp_desc =
2690+
Pexp_fun
2691+
( Nolabel,
2692+
None,
2693+
{ppat_desc = Ppat_var {txt = "__x"}},
2694+
{pexp_desc = Pexp_apply _} );
2695+
} ) ->
26812696
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
26822697
printExpressionWithComments ~state
2683-
(ParsetreeViewer.rewriteUnderscoreApply e)
2698+
(ParsetreeViewer.rewriteUnderscoreApply e_fun)
26842699
cmtTbl
2685-
| _ when Ast_uncurried.exprIsUncurriedFun e -> printArrow e
26862700
| Pexp_fun _ | Pexp_newtype _ -> printArrow e
26872701
| Parsetree.Pexp_constant c ->
26882702
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c

0 commit comments

Comments
 (0)