on master help sign in
Preserve empty where clause
commitab4885ff0f912e21e1852c00d6a96f9cd2b1a576 authormrkkrp <mark.karpov@tweag.io> dateSun 21 Jul 2019, 00:26 (7 years ago) parent174a084
3 files changed+17−8
data/examples/declaration/value/function/where-out.hs+4 data/examples/declaration/value/function/where.hs+4 src/Ormolu/Printer/Meat/Declaration/Value.hs+9−8
data/examples/declaration/value/function/where-out.hs+4
@@ -13,3 +13,7 @@ baz x = q
1313 y = x
1414 z = y
1515 q = z
16+
17+emptyWhere :: Int
18+emptyWhere = 5
19+ where
data/examples/declaration/value/function/where.hs+4
@@ -13,3 +13,7 @@ baz x = q
1313 y = x
1414 z = y
1515 q = z
16+
17+emptyWhere :: Int
18+emptyWhere = 5
19+ where
src/Ormolu/Printer/Meat/Declaration/Value.hs+9−8
@@ -201,14 +201,15 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
201201 else EqualSign
202202 newlineSep (located' (p_grhs' pretty groupStyle)) grhssGRHSs
203203 let whereLocation = combineSrcSpans patGrhssSpan $ getLoc grhssLocalBinds
204− unless
205− (GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds))
206− (inciLocalBinds . switchLayout whereLocation $ do
207− breakpoint
208− txt "where"
209− breakpoint
210− inci (located grhssLocalBinds p_hsLocalBinds)
211− )
204+ whereIsEmpty = GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds)
205+ unless (GHC.eqEmptyLocalBinds (unLoc grhssLocalBinds))
206+ . inciLocalBinds
207+ . switchLayout whereLocation $ do
208+ if whereIsEmpty then newline else breakpoint
209+ txt "where"
210+ unless whereIsEmpty $ do
211+ breakpoint
212+ inci (located grhssLocalBinds p_hsLocalBinds)
212213 case style of
213214 Lambda -> placeHanging placement $
214215 switchLayout patGrhssSpan p_body