Skip to content

Example of broken formatting for foo(a,_) in uncurried mode. #6148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 14, 2023
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