1
1
mirror of https://github.com/google/ormolu.git synced 2024-11-23 22:27:16 +03:00

Fix guards

This commit is contained in:
mrkkrp 2019-05-23 12:18:40 +02:00 committed by Mark Karpov
parent 61f49600f8
commit b129979516
3 changed files with 37 additions and 8 deletions

View File

@ -0,0 +1,14 @@
foo :: Int -> Int
foo x
| x == 5 = 10
| otherwise = 12
bar :: Int -> Int
bar x
| x == 5 =
foo x
+ foo 10
| x == 6 =
foo x
+ foo 20
| otherwise = foo 100

View File

@ -0,0 +1,12 @@
foo :: Int -> Int
foo x
| x == 5 = 10
| otherwise = 12
bar :: Int -> Int
bar x
| x == 5 = foo x
+ foo 10
| x == 6 = foo x
+ foo 20
| otherwise = foo 100

View File

@ -80,10 +80,10 @@ p_match style Match {..} = do
inci' (velt' (located' p_pat <$> m_pats))
return inci'
inci' $ do
space
let GRHSs {..} = m_grhss
unless (length grhssGRHSs > 1) . txt $
case style of
unless (length grhssGRHSs > 1) $ do
space
txt $ case style of
Function _ -> "="
_ -> "->"
let combinedSpans = combineSrcSpans' $
@ -101,9 +101,6 @@ p_match style Match {..} = do
line (txt "where")
inci (located grhssLocalBinds p_hsLocalBinds)
getGRHSSpan :: GRHS GhcPs (LHsExpr GhcPs) -> SrcSpan
getGRHSSpan (GRHS _ body) = getSpan body
p_grhs :: GRHS GhcPs (LHsExpr GhcPs) -> R ()
p_grhs (GRHS guards body) =
case guards of
@ -111,9 +108,9 @@ p_grhs (GRHS guards body) =
xs -> do
txt "| "
velt $ withSep comma (located' p_stmt) xs
txt " ->"
txt " ="
breakpoint
p_body
inci p_body
where
p_body = located body p_hsExpr
@ -237,3 +234,9 @@ p_hsExpr = \case
EViewPat {} -> notImplemented "EViewPat"
ELazyPat {} -> notImplemented "ELazyPat"
HsWrap {} -> notImplemented "HsWrap"
----------------------------------------------------------------------------
-- Helpers
getGRHSSpan :: GRHS GhcPs (LHsExpr GhcPs) -> SrcSpan
getGRHSSpan (GRHS _ body) = getSpan body