on master help sign in
Fix application of multi-way if to arguments
4e253c9Mark Karpov
CHANGELOG.md+5
@@ -3,6 +3,11 @@
3* Fixed an issue related to unnecessary use of curly braces. [Issue
3* Fixed an issue related to unnecessary use of curly braces. [Issue
4 473](https://github.com/tweag/ormolu/issues/473).
4 473](https://github.com/tweag/ormolu/issues/473).
5
5
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+
6## Ormolu 0.0.2.0
11## Ormolu 0.0.2.0
7
12
8* Switched to `ghc-lib-parser` instead of depending on the `ghc` package
13* 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 @@
3foo x = if | x == 5 -> 5
3foo x = if | x == 5 -> 5
4
4
5bar x y =
5bar x y =
6− if
7− | x > y -> x
6+ if | x > y -> x
8− | x < y ->
7+ | x < y ->
9− y
8+ y
9+ | otherwise -> x
10+
11+baz =
12+ if | p -> f
10− | otherwise -> x
13+ | otherwise -> g
14+ x
data/examples/declaration/value/function/multi-way-if.hs+5
@@ -7,3 +7,8 @@ bar x y = if
7 | x < y
7 | x < y
8 -> y
8 -> y
9 | otherwise -> x
9 | 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
562 indent =
562 indent =
563 case func of
563 case func of
564 L _ (HsPar NoExt _) -> inci
564 L _ (HsPar NoExt _) -> inci
565+ L _ (HsMultiIf NoExt _) -> inci
565 L spn _ ->
566 L spn _ ->
566 if isOneLineSpan spn
567 if isOneLineSpan spn
567 then inci
568 then inci
@@ -629,9 +630,8 @@ p_hsExpr' s = \case
629 HsIf NoExt _ if' then' else' ->
630 HsIf NoExt _ if' then' else' ->
630 p_if exprPlacement p_hsExpr if' then' else'
631 p_if exprPlacement p_hsExpr if' then' else'
631 HsMultiIf NoExt guards -> do
632 HsMultiIf NoExt guards -> do
632− txt "if"
633+ txt "if "
633− breakpoint
634− inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
634+ inci . inci . sitcc $ sep newline (located' (p_grhs RightArrow)) guards
635 HsLet NoExt localBinds e ->
635 HsLet NoExt localBinds e ->
636 p_let p_hsExpr localBinds e
636 p_let p_hsExpr localBinds e
637 HsDo NoExt ctx es -> do
637 HsDo NoExt ctx es -> do