Skip to content

Commit

Permalink
Preserve necessary braces for final function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen committed Aug 1, 2023
1 parent e90a78b commit 28a9ba1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

* Preserve necessary braces for final function arguments. [Issue
1044](https://github.com/tweag/ormolu/issues/1044).

## Ormolu 0.7.1.0

* Include `base` fixity information when formatting a Haskell file that's
Expand Down
3 changes: 3 additions & 0 deletions data/examples/other/necessary-brackets-out.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
insertEmDash = Text.concat . map \case { x | x == "--" -> ""; x -> x } . Text.groupBy ((==) `on` Char.isSpace)

foo f a b c = f do { a } + f do { b } + f do c
3 changes: 3 additions & 0 deletions data/examples/other/necessary-brackets.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
insertEmDash = Text.concat . map \case{ x | x == "--" -> ""; x -> x } . Text.groupBy ((==) `on` Char.isSpace)

foo f a b c = f do {a} + f do {b} + f do {c}
15 changes: 12 additions & 3 deletions src/Ormolu/Printer/Meat/Declaration/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,18 @@ p_stmts ::
p_stmts isApp placer render es = do
breakpoint
ub <- layoutToBraces <$> getLayout
let p_stmtExt (relPos, stmt) =
ub' $ withSpacing (p_stmt' placer render) stmt
where
-- We need to set brace usage information for all but the last
-- statement (e.g.in the case of nested do blocks).
ub' = case relPos of
FirstPos -> ub
MiddlePos -> ub
LastPos -> id
SinglePos -> id
inciApplicand isApp . located es $
sepSemi
(ub . withSpacing (p_stmt' placer render))
sepSemi p_stmtExt . attachRelativePos

gatherStmt :: ExprLStmt GhcPs -> [[ExprLStmt GhcPs]]
gatherStmt (L _ (ParStmt _ block _ _)) =
Expand Down Expand Up @@ -654,7 +663,7 @@ p_hsExpr' isApp s = \case
located func (p_hsExpr' Applicand s)
breakpoint
sep breakpoint (located' p_hsExpr) initp
placeHanging placement . dontUseBraces $
placeHanging placement $
located lastp p_hsExpr
HsAppType _ e _ a -> do
located e p_hsExpr
Expand Down

0 comments on commit 28a9ba1

Please sign in to comment.