on master help sign in
Preserve empty where clause
ab4885fmrkkrp
data/examples/declaration/value/function/where-out.hs+4
@@ -13,3 +13,7 @@ baz x = q
13 y = x
13 y = x
14 z = y
14 z = y
15 q = z
15 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
13 y = x
13 y = x
14 z = y
14 z = y
15 q = z
15 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
201 else EqualSign
201 else EqualSign
202 newlineSep (located' (p_grhs' pretty groupStyle)) grhssGRHSs
202 newlineSep (located' (p_grhs' pretty groupStyle)) grhssGRHSs
203 let whereLocation = combineSrcSpans patGrhssSpan $ getLoc grhssLocalBinds
203 let whereLocation = combineSrcSpans patGrhssSpan $ getLoc grhssLocalBinds
204− unless
205− (GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds))
204+ whereIsEmpty = GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds)
205+ unless (GHC.eqEmptyLocalBinds (unLoc grhssLocalBinds))
206+ . inciLocalBinds
206− (inciLocalBinds . switchLayout whereLocation $ do
207+ . switchLayout whereLocation $ do
207− breakpoint
208+ if whereIsEmpty then newline else breakpoint
208− txt "where"
209+ txt "where"
210+ unless whereIsEmpty $ do
209− breakpoint
211+ breakpoint
210− inci (located grhssLocalBinds p_hsLocalBinds)
212+ inci (located grhssLocalBinds p_hsLocalBinds)
211− )
212 case style of
213 case style of
213 Lambda -> placeHanging placement $
214 Lambda -> placeHanging placement $
214 switchLayout patGrhssSpan p_body
215 switchLayout patGrhssSpan p_body