on master help sign in
Fix application of multi-way if to arguments
commit4e253c9eb2d21ce154230cb3b79e61a47650c3e2 authorMark Karpov <mark.karpov@tweag.io> dateMon 6 Jan 2020, 15:54 (7 years ago) parent9dbba53
4 files changed+22−8
CHANGELOG.md+5 data/examples/declaration/value/function/multi-way-if-out.hs+9−5 data/examples/declaration/value/function/multi-way-if.hs+5 src/Ormolu/Printer/Meat/Declaration/Value.hs+3−3
CHANGELOG.md+5
@@ -3,6 +3,11 @@
33* Fixed an issue related to unnecessary use of curly braces. [Issue
44 473](https://github.com/tweag/ormolu/issues/473).
55
6+* Fixed the issue with formatting multi-way if when it happens to be a
7+ function applied to arguments [Issue
8+ 488](https://github.com/tweag/ormolu/issues/488). This changed the way
9+ multi-line if is formatted in general.
10+
611## Ormolu 0.0.2.0
712
813* Switched to `ghc-lib-parser` instead of depending on the `ghc` package
data/examples/declaration/value/function/multi-way-if-out.hs+9−5
@@ -3,8 +3,12 @@
33foo x = if | x == 5 -> 5
44
55bar x y =
6− if
7− | x > y -> x
8− | x < y ->
9− y
10− | otherwise -> x
6+ if | x > y -> x
7+ | x < y ->
8+ y
9+ | otherwise -> x
10+
11+baz =
12+ if | p -> f
13+ | otherwise -> g
14+ x
data/examples/declaration/value/function/multi-way-if.hs+5
@@ -7,3 +7,8 @@ bar x y = if
77 | x < y
88 -> y
99 | otherwise -> x
10+
11+baz =
12+ if | p -> f
13+ | otherwise -> g
14+ x
src/Ormolu/Printer/Meat/Declaration/Value.hs+3−3
@@ -562,6 +562,7 @@ p_hsExpr' s = \case
562562 indent =
563563 case func of
564564 L _ (HsPar NoExt _) -> inci
565+ L _ (HsMultiIf NoExt _) -> inci
565566 L spn _ ->
566567 if isOneLineSpan spn
567568 then inci
@@ -629,9 +630,8 @@ p_hsExpr' s = \case
629630 HsIf NoExt _ if' then' else' ->
630631 p_if exprPlacement p_hsExpr if' then' else'
631632 HsMultiIf NoExt guards -> do
632− txt "if"
633− breakpoint
634− inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
633+ txt "if "
634+ inci . inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
635635 HsLet NoExt localBinds e ->
636636 p_let p_hsExpr localBinds e
637637 HsDo NoExt ctx es -> do