on master help sign in
Fix guards
b129979mrkkrp
data/examples/declaration/value/function/guards-out.hsnew file+14
@@ -0,0 +1,14 @@
1+foo :: Int -> Int
2+foo x
3+ | x == 5 = 10
4+ | otherwise = 12
5+
6+bar :: Int -> Int
7+bar x
8+ | x == 5 =
9+ foo x
10+ + foo 10
11+ | x == 6 =
12+ foo x
13+ + foo 20
14+ | otherwise = foo 100
data/examples/declaration/value/function/guards.hsnew file+12
@@ -0,0 +1,12 @@
1+foo :: Int -> Int
2+foo x
3+ | x == 5 = 10
4+ | otherwise = 12
5+
6+bar :: Int -> Int
7+bar x
8+ | x == 5 = foo x
9+ + foo 10
10+ | x == 6 = foo x
11+ + foo 20
12+ | otherwise = foo 100
src/Ormolu/Printer/Meat/Declaration/Value.hs+11−8
@@ -80,10 +80,10 @@ p_match style Match {..} = do
80 inci' (velt' (located' p_pat <$> m_pats))
80 inci' (velt' (located' p_pat <$> m_pats))
81 return inci'
81 return inci'
82 inci' $ do
82 inci' $ do
83− space
84 let GRHSs {..} = m_grhss
83 let GRHSs {..} = m_grhss
85− unless (length grhssGRHSs > 1) . txt $
84+ unless (length grhssGRHSs > 1) $ do
85+ space
86− case style of
86+ txt $ case style of
87 Function _ -> "="
87 Function _ -> "="
88 _ -> "->"
88 _ -> "->"
89 let combinedSpans = combineSrcSpans' $
89 let combinedSpans = combineSrcSpans' $
@@ -101,9 +101,6 @@ p_match style Match {..} = do
101 line (txt "where")
101 line (txt "where")
102 inci (located grhssLocalBinds p_hsLocalBinds)
102 inci (located grhssLocalBinds p_hsLocalBinds)
103
103
104−getGRHSSpan :: GRHS GhcPs (LHsExpr GhcPs) -> SrcSpan
105−getGRHSSpan (GRHS _ body) = getSpan body
106−
107p_grhs :: GRHS GhcPs (LHsExpr GhcPs) -> R ()
104p_grhs :: GRHS GhcPs (LHsExpr GhcPs) -> R ()
108p_grhs (GRHS guards body) =
105p_grhs (GRHS guards body) =
109 case guards of
106 case guards of
@@ -111,9 +108,9 @@ p_grhs (GRHS guards body) =
111 xs -> do
108 xs -> do
112 txt "| "
109 txt "| "
113 velt $ withSep comma (located' p_stmt) xs
110 velt $ withSep comma (located' p_stmt) xs
114− txt " ->"
111+ txt " ="
115 breakpoint
112 breakpoint
116− p_body
113+ inci p_body
117 where
114 where
118 p_body = located body p_hsExpr
115 p_body = located body p_hsExpr
119
116
@@ -237,3 +234,9 @@ p_hsExpr = \case
237 EViewPat {} -> notImplemented "EViewPat"
234 EViewPat {} -> notImplemented "EViewPat"
238 ELazyPat {} -> notImplemented "ELazyPat"
235 ELazyPat {} -> notImplemented "ELazyPat"
239 HsWrap {} -> notImplemented "HsWrap"
236 HsWrap {} -> notImplemented "HsWrap"
237+
238+----------------------------------------------------------------------------
239+-- Helpers
240+
241+getGRHSSpan :: GRHS GhcPs (LHsExpr GhcPs) -> SrcSpan
242+getGRHSSpan (GRHS _ body) = getSpan body