From 3288ef3bd4982c055f86d6b984a3e6880402d370 Mon Sep 17 00:00:00 2001
From: Lennart Spitzner <hexagoxel@hexagoxel.de>
Date: Sat, 15 Jun 2019 14:38:48 +0200
Subject: [PATCH] For funs with multiple matches, use the match id as id (fixes
 #234)

---
 src-literatetests/15-regressions.blt              |  8 ++++++++
 .../Haskell/Brittany/Internal/Layouters/Decl.hs   | 15 +++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src-literatetests/15-regressions.blt b/src-literatetests/15-regressions.blt
index d402ca7..be4bc55 100644
--- a/src-literatetests/15-regressions.blt
+++ b/src-literatetests/15-regressions.blt
@@ -660,3 +660,11 @@ foo = bar
   arg4
   arg5 -- this is the fifth argument
   arg6 -- this is the sixth argument
+
+#test issue 234
+
+True `nand` True = False
+nand _ _         = True
+
+nor False False = True
+_ `nor` _       = False
diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs b/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs
index 9366a6f..c7a7d04 100644
--- a/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs
+++ b/src/Language/Haskell/Brittany/Internal/Layouters/Decl.hs
@@ -294,7 +294,7 @@ layoutPatternBind
   -> BriDocNumbered
   -> LMatch GhcPs (LHsExpr GhcPs)
   -> ToBriDocM BriDocNumbered
-layoutPatternBind mIdStr binderDoc lmatch@(L _ match) = do
+layoutPatternBind funId binderDoc lmatch@(L _ match) = do
   let pats                     = m_pats match
 #if MIN_VERSION_ghc(8,6,0)   /* ghc-8.6 */
   let (GRHSs _ grhss whereBinds) = m_grhss match
@@ -303,6 +303,17 @@ layoutPatternBind mIdStr binderDoc lmatch@(L _ match) = do
 #endif
   patDocs <- pats `forM` \p -> fmap return $ colsWrapPat =<< layoutPat p
   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
   patDoc <- docWrapNodePrior lmatch $ case (mIdStr', patDocs) of
     (Just idStr, p1 : pr) | isInfix -> docCols
@@ -321,7 +332,7 @@ layoutPatternBind mIdStr binderDoc lmatch@(L _ match) = do
   clauseDocs <- docWrapNodeRest lmatch $ layoutGrhs `mapM` grhss
   mWhereDocs <- layoutLocalBinds whereBinds
   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
   layoutPatternBindFinal alignmentToken
                          binderDoc