For funs with multiple matches, use the match id as id (fixes #234)

pull/247/head
Lennart Spitzner 2019-06-15 14:38:48 +02:00
parent b95bc09a9d
commit 3288ef3bd4
2 changed files with 21 additions and 2 deletions

View File

@ -660,3 +660,11 @@ foo = bar
arg4 arg4
arg5 -- this is the fifth argument arg5 -- this is the fifth argument
arg6 -- this is the sixth argument arg6 -- this is the sixth argument
#test issue 234
True `nand` True = False
nand _ _ = True
nor False False = True
_ `nor` _ = False

View File

@ -294,7 +294,7 @@ layoutPatternBind
-> BriDocNumbered -> BriDocNumbered
-> LMatch GhcPs (LHsExpr GhcPs) -> LMatch GhcPs (LHsExpr GhcPs)
-> ToBriDocM BriDocNumbered -> ToBriDocM BriDocNumbered
layoutPatternBind mIdStr binderDoc lmatch@(L _ match) = do layoutPatternBind funId binderDoc lmatch@(L _ match) = do
let pats = m_pats match let pats = m_pats match
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */ #if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
let (GRHSs _ grhss whereBinds) = m_grhss match let (GRHSs _ grhss whereBinds) = m_grhss match
@ -303,6 +303,17 @@ layoutPatternBind mIdStr binderDoc lmatch@(L _ match) = do
#endif #endif
patDocs <- pats `forM` \p -> fmap return $ colsWrapPat =<< layoutPat p patDocs <- pats `forM` \p -> fmap return $ colsWrapPat =<< layoutPat p
let isInfix = isInfixMatch match let isInfix = isInfixMatch match
mIdStr <- case match of
#if MIN_VERSION_ghc(8,6,0) /* ghc-8.6 */
Match _ (FunRhs matchId _ _) _ _ -> Just <$> lrdrNameToTextAnn matchId
#elif MIN_VERSION_ghc(8,4,0) /* ghc-8.4 */
Match (FunRhs matchId _ _) _ _ -> Just <$> lrdrNameToTextAnn matchId
#elif MIN_VERSION_ghc(8,2,0) /* ghc-8.4 */
Match (FunRhs matchId _ _) _ _ _ -> Just <$> lrdrNameToTextAnn matchId
#else
Match (FunBindMatch matchId _) _ _ _ -> Just <$> lrdrNameToTextAnn matchId
#endif
_ -> pure Nothing
let mIdStr' = fixPatternBindIdentifier match <$> mIdStr let mIdStr' = fixPatternBindIdentifier match <$> mIdStr
patDoc <- docWrapNodePrior lmatch $ case (mIdStr', patDocs) of patDoc <- docWrapNodePrior lmatch $ case (mIdStr', patDocs) of
(Just idStr, p1 : pr) | isInfix -> docCols (Just idStr, p1 : pr) | isInfix -> docCols
@ -321,7 +332,7 @@ layoutPatternBind mIdStr binderDoc lmatch@(L _ match) = do
clauseDocs <- docWrapNodeRest lmatch $ layoutGrhs `mapM` grhss clauseDocs <- docWrapNodeRest lmatch $ layoutGrhs `mapM` grhss
mWhereDocs <- layoutLocalBinds whereBinds mWhereDocs <- layoutLocalBinds whereBinds
let mWhereArg = mWhereDocs <&> \d -> (mkAnnKey lmatch, d) let mWhereArg = mWhereDocs <&> \d -> (mkAnnKey lmatch, d)
let alignmentToken = if null pats then Nothing else mIdStr let alignmentToken = if null pats then Nothing else funId
hasComments <- hasAnyCommentsBelow lmatch hasComments <- hasAnyCommentsBelow lmatch
layoutPatternBindFinal alignmentToken layoutPatternBindFinal alignmentToken
binderDoc binderDoc