on master help sign in
Correctly print lambda case with guards
commit55653112640365d91e055a094222ad90eccd8d58 authorUtku Demir <me@utdemir.com> dateThu 20 Jun 2019, 16:23 (7 years ago) parent6b73283
3 files changed+10−8
data/examples/declaration/value/function/lambda-case-out.hs+1 data/examples/declaration/value/function/lambda-case.hs+1 src/Ormolu/Printer/Meat/Declaration/Value.hs+8−8
data/examples/declaration/value/function/lambda-case-out.hs+1
@@ -2,4 +2,5 @@
22foo :: Int -> Int
33foo = \case
44 5 -> 10
5+ i | i > 5 -> 11
56 _ -> 12
data/examples/declaration/value/function/lambda-case.hs+1
@@ -3,4 +3,5 @@
33foo :: Int -> Int
44foo = \case
55 5 -> 10
6+ i | i > 5 -> 11
67 _ -> 12
src/Ormolu/Printer/Meat/Declaration/Value.hs+8−8
@@ -128,7 +128,10 @@ p_match style isInfix m_pats m_grhss = do
128128 Function name -> Just $ getLoc name
129129 _ -> Nothing
130130 Just pats -> Just . getLoc $ NE.last pats
131−
131+ isCase = \case
132+ Case -> True
133+ LambdaCase -> True
134+ _ -> False
132135 inci' $ do
133136 let GRHSs {..} = m_grhss
134137 hasGuards = withGuards grhssGRHSs
@@ -136,7 +139,7 @@ p_match style isInfix m_pats m_grhss = do
136139 case style of
137140 Function _ -> txt " ="
138141 PatternBind -> txt " ="
139− Case -> unless hasGuards (txt " ->")
142+ s | isCase s && hasGuards -> return ()
140143 _ -> txt " ->"
141144 let grhssSpan = combineSrcSpans' $
142145 getGRHSSpan . unLoc <$> NE.fromList grhssGRHSs
@@ -147,12 +150,9 @@ p_match style isInfix m_pats m_grhss = do
147150 Hanging -> inci
148151 p_body = do
149152 let groupStyle =
150− case style of
151− Case ->
152− if hasGuards
153− then RightArrow
154− else EqualSign
155− _ -> EqualSign
153+ if isCase style && hasGuards
154+ then RightArrow
155+ else EqualSign
156156 newlineSep (located' (p_grhs groupStyle)) grhssGRHSs
157157 unless
158158 (GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds))