on master help sign in
[#98] Fix where blocks with do notation
f8b9207Rupert Horlick
data/examples/declaration/value/function/do-where-out.hsnew file+5
@@ -0,0 +1,5 @@
1+f :: Maybe Int
2+f = do
3+ return c
4+ where
5+ c = 0
data/examples/declaration/value/function/do-where.hsnew file+5
@@ -0,0 +1,5 @@
1+f :: Maybe Int
2+f = do
3+ return c
4+ where
5+ c = 0
src/Ormolu/Printer/Meat/Declaration/Value.hs+11−5
@@ -128,6 +128,10 @@ p_match style isInfix m_pats m_grhss = do
128 _ -> txt " ->"
128 _ -> txt " ->"
129 let combinedSpans = combineSrcSpans' $
129 let combinedSpans = combineSrcSpans' $
130 getGRHSSpan . unL <$> NE.fromList grhssGRHSs
130 getGRHSSpan . unL <$> NE.fromList grhssGRHSs
131+ placement = blockPlacement grhssGRHSs
132+ inciLocalBinds = case placement of
133+ Normal -> id
134+ Hanging -> inci
131 p_body = do
135 p_body = do
132 let groupStyle =
136 let groupStyle =
133 case style of
137 case style of
@@ -137,11 +141,13 @@ p_match style isInfix m_pats m_grhss = do
137 else EqualSign
141 else EqualSign
138 _ -> EqualSign
142 _ -> EqualSign
139 newlineSep (located' (p_grhs groupStyle)) grhssGRHSs
143 newlineSep (located' (p_grhs groupStyle)) grhssGRHSs
144+ unless
140− unless (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds)) $ do
145+ (GHC.isEmptyLocalBindsPR (unL grhssLocalBinds))
146+ (inciLocalBinds $ do
141− newline
147+ newline
142− line (txt "where")
148+ line (txt "where")
143− inci (located grhssLocalBinds p_hsLocalBinds)
149+ inci (located grhssLocalBinds p_hsLocalBinds)
144− placement = blockPlacement grhssGRHSs
150+ )
145 case style of
151 case style of
146 Lambda -> placeHanging placement $
152 Lambda -> placeHanging placement $
147 switchLayout combinedSpans p_body
153 switchLayout combinedSpans p_body