mirror of
https://github.com/ilyakooo0/ormolu.git
synced 2024-10-27 03:28:33 +03:00
Fix backticks and parens in multiline function declarations
Function id obtained through pattern matching on ‘FunBind’ should not be used to print the actual equations because the different ‘RdrNames’ used in the equations may have different “decorations” (such as backticks and paretheses) associated with them. It is necessary to use per-equation names obtained from ‘m_ctxt’ of ‘Match’.
This commit is contained in:
parent
75869e1590
commit
5955c514ee
@ -0,0 +1,7 @@
|
||||
x `op1` (Just 0) = True
|
||||
op1 x (Just _) = False
|
||||
op1 x Nothing = undefined
|
||||
|
||||
op2 1 y = False
|
||||
x `op2` y =
|
||||
True
|
@ -0,0 +1,7 @@
|
||||
x `op1` (Just 0) = True
|
||||
op1 x (Just _) = False
|
||||
op1 x Nothing = undefined
|
||||
|
||||
op2 1 y = False
|
||||
x `op2` y =
|
||||
True
|
@ -0,0 +1,9 @@
|
||||
(!=!) 2 y = 1
|
||||
x !=! y = 2
|
||||
|
||||
x ?=? [] = 123
|
||||
(?=?) x (_ : []) = 456
|
||||
x ?=? _ = f x x
|
||||
where
|
||||
f x 7 = 789
|
||||
x `f` _ = 101
|
@ -0,0 +1,9 @@
|
||||
(!=!) 2 y = 1
|
||||
x !=! y = 2
|
||||
|
||||
x ?=? [] = 123
|
||||
(?=?) x (_:[]) = 456
|
||||
x ?=? _ = f x x
|
||||
where
|
||||
f x 7 = 789
|
||||
x `f` _ = 101
|
@ -13,5 +13,4 @@ pattern HeadC' x <-
|
||||
pattern Simple <-
|
||||
"Simple"
|
||||
where
|
||||
Simple =
|
||||
"Complicated"
|
||||
Simple = "Complicated"
|
||||
|
@ -69,8 +69,7 @@ p_funBind
|
||||
:: Located RdrName
|
||||
-> MatchGroup GhcPs (LHsExpr GhcPs)
|
||||
-> R ()
|
||||
p_funBind name mgroup =
|
||||
p_matchGroup (Function name) mgroup
|
||||
p_funBind name = p_matchGroup (Function name)
|
||||
|
||||
p_matchGroup
|
||||
:: MatchGroupStyle
|
||||
@ -86,11 +85,35 @@ p_matchGroup'
|
||||
-> MatchGroup GhcPs (Located body)
|
||||
-> R ()
|
||||
p_matchGroup' placer pretty style MG {..} =
|
||||
sep newline (located' (\m@Match {..} ->
|
||||
p_match' placer pretty style (isInfixMatch m) (matchStrictness m) m_pats m_grhss))
|
||||
(unLoc mg_alts)
|
||||
sep newline (located' p_Match) (unLoc mg_alts)
|
||||
where
|
||||
p_Match m@Match {..} =
|
||||
p_match'
|
||||
placer
|
||||
pretty
|
||||
(adjustMatchGroupStyle m style)
|
||||
(isInfixMatch m)
|
||||
(matchStrictness m)
|
||||
m_pats
|
||||
m_grhss
|
||||
p_Match _ = notImplemented "XMatch"
|
||||
p_matchGroup' _ _ _ (XMatchGroup NoExt) = notImplemented "XMatchGroup"
|
||||
|
||||
-- | Function id obtained through pattern matching on 'FunBind' should not
|
||||
-- be used to print the actual equations because the different ‘RdrNames’
|
||||
-- used in the equations may have different “decorations” (such as backticks
|
||||
-- and paretheses) associated with them. It is necessary to use per-equation
|
||||
-- names obtained from 'm_ctxt' of 'Match'. This function replaces function
|
||||
-- name inside of 'Function' accordingly.
|
||||
|
||||
adjustMatchGroupStyle
|
||||
:: Match GhcPs body
|
||||
-> MatchGroupStyle
|
||||
-> MatchGroupStyle
|
||||
adjustMatchGroupStyle m = \case
|
||||
Function _ -> (Function . mc_fun . m_ctxt) m
|
||||
style -> style
|
||||
|
||||
matchStrictness :: Match id body -> SrcStrictness
|
||||
matchStrictness match =
|
||||
case m_ctxt match of
|
||||
|
Loading…
Reference in New Issue
Block a user