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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

# 11.0.0-alpha.4 (Unreleased)

#### :bug: Bug Fix

- Fix broken formatting in uncurried mode for functions with _ placeholder args. https://github.com/rescript-lang/rescript-compiler/pull/6148

# 11.0.0-alpha.3

#### :rocket: Main New Feature
Expand Down
28 changes: 21 additions & 7 deletions res_syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,27 @@ let funExpr expr =
let rec collect ~uncurried ~nFun attrsBefore acc expr =
match expr with
| {
pexp_desc =
Pexp_fun
( Nolabel,
None,
{ppat_desc = Ppat_var {txt = "__x"}},
{pexp_desc = Pexp_apply _} );
} ->
pexp_desc =
Pexp_fun
( Nolabel,
None,
{ppat_desc = Ppat_var {txt = "__x"}},
{pexp_desc = Pexp_apply _} );
}
| {
pexp_desc =
Pexp_construct
( {txt = Lident "Function$"},
Some
{
pexp_desc =
Pexp_fun
( Nolabel,
None,
{ppat_desc = Ppat_var {txt = "__x"}},
{pexp_desc = Pexp_apply _} );
} );
} ->
(uncurried, attrsBefore, List.rev acc, rewriteUnderscoreApply expr)
| {pexp_desc = Pexp_newtype (stringLoc, rest); pexp_attributes = attrs} ->
let stringLocs, returnExpr = collectNewTypes [stringLoc] rest in
Expand Down
22 changes: 18 additions & 4 deletions res_syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2671,18 +2671,32 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
(Doc.concat
[attrs; parametersDoc; typConstraintDoc; Doc.text " =>"; returnExprDoc])
in
let uncurried = Ast_uncurried.exprIsUncurriedFun e in
let e_fun =
if uncurried then Ast_uncurried.exprExtractUncurriedFun e else e
in
let printedExpression =
match e.pexp_desc with
match e_fun.pexp_desc with
| Pexp_fun
( Nolabel,
None,
{ppat_desc = Ppat_var {txt = "__x"}},
{pexp_desc = Pexp_apply _} ) ->
{pexp_desc = Pexp_apply _} )
| Pexp_construct
( {txt = Lident "Function$"},
Some
{
pexp_desc =
Pexp_fun
( Nolabel,
None,
{ppat_desc = Ppat_var {txt = "__x"}},
{pexp_desc = Pexp_apply _} );
} ) ->
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
printExpressionWithComments ~state
(ParsetreeViewer.rewriteUnderscoreApply e)
(ParsetreeViewer.rewriteUnderscoreApply e_fun)
cmtTbl
| _ when Ast_uncurried.exprIsUncurriedFun e -> printArrow e
| Pexp_fun _ | Pexp_newtype _ -> printArrow e
| Parsetree.Pexp_constant c ->
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c
Expand Down