From 2b77142617a35afa0f935b1e9cc49ec0c11e83fe Mon Sep 17 00:00:00 2001
From: Lennart Spitzner <hexagoxel@hexagoxel.de>
Date: Wed, 3 May 2023 19:53:19 +0000
Subject: [PATCH] Fix layout of type-level list literal

---
 data/11-extensions/datakinds.blt              | 30 +++++---
 .../Brittany/Internal/ToBriDoc/Type.hs        | 76 +++++++++----------
 2 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/data/11-extensions/datakinds.blt b/data/11-extensions/datakinds.blt
index 8ed5076..57ca3e5 100644
--- a/data/11-extensions/datakinds.blt
+++ b/data/11-extensions/datakinds.blt
@@ -8,23 +8,23 @@ test = Proxy @'[ 'True ]
 test :: Proxy '[True]
 test = Proxy @'[True]
 #test 3
-test :: Proxy '[ 'True , False ]
-test = Proxy @'[ 'True , False ]
+test :: Proxy '[ 'True, False ]
+test = Proxy @'[ 'True, False ]
 #test 4
-test :: Proxy '[True , False]
-test = Proxy @'[True , False]
+test :: Proxy '[True, False]
+test = Proxy @'[True, False]
 #test 5
-test :: Proxy '[True , 'False]
-test = Proxy @'[True , 'False]
+test :: Proxy '[True, 'False]
+test = Proxy @'[True, 'False]
 #test 6
-test :: Proxy '[ 'True , 'False ]
-test = Proxy @'[ 'True , 'False ]
+test :: Proxy '[ 'True, 'False ]
+test = Proxy @'[ 'True, 'False ]
 #test 7
-test :: Proxy '[ 'Just 'True , False ]
-test = Proxy @'[ 'Just 'True , False ]
+test :: Proxy '[ 'Just 'True, False ]
+test = Proxy @'[ 'Just 'True, False ]
 #test 8
-test :: Proxy '[Just True , False]
-test = Proxy @'[Just True , False]
+test :: Proxy '[Just True, False]
+test = Proxy @'[Just True, False]
 #test 9
 test :: Proxy '[('True)]
 test = Proxy @'[('True)]
@@ -72,3 +72,9 @@ test
                            True]
 test = Proxy @'[{- comment -}
                               True]
+
+#test explicit-list-type non-promoted
+type Foo = '[Bool, Bool, Bool]
+
+#test explicit-list-type promoted
+type Foo = '[ 'Bool, Bool, Bool ]
diff --git a/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Type.hs b/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Type.hs
index 832694e..58e4d80 100644
--- a/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Type.hs
+++ b/source/library/Language/Haskell/Brittany/Internal/ToBriDoc/Type.hs
@@ -443,52 +443,46 @@ layoutType ltype@(L _ typ) = docHandleComms ltype $ case typ of
 
     typDocs <- typs `forM` (shareDoc . docHandleListElemComms layoutType)
     let hasComments = hasAnyCommentsBelow ltype
-    docAlt
-      [ docSeq
-      $ [docLit $ Text.pack "'[", sepIfHeadPromoted]
-      ++ List.intersperse specialCommaSep (docForceSingleline <$> typDocs)
-      ++ [sepIfHeadPromoted, docLit $ Text.pack "]"]
-      , case splitFirstLast typDocs of
-        FirstLastEmpty -> docSeq
-          [ docLit $ Text.pack "'[]" -- TODO92 comments AnnOpenS
+    case splitFirstLast typDocs of
+      FirstLastEmpty -> docSeq
+        [ docLit $ Text.pack "'[]" -- TODO92 comments AnnOpenS
+        ]
+      FirstLastSingleton e -> docAlt
+        [ docSeq
+          [ docLit $ Text.pack "'["
+          , sepIfHeadPromoted
+          , docForceSingleline e -- TODO92 comments AnnOpenS
+          , sepIfHeadPromoted
+          , docLit $ Text.pack "]"
           ]
-        FirstLastSingleton e -> docAlt
+        , docSetBaseY $ docLines
           [ docSeq
             [ docLit $ Text.pack "'["
-            , sepIfHeadPromoted
-            , docForceSingleline e -- TODO92 comments AnnOpenS
-            , sepIfHeadPromoted
-            , docLit $ Text.pack "]"
-            ]
-          , docSetBaseY $ docLines
-            [ docSeq
-              [ docLit $ Text.pack "'["
-              , docSeparator
-              , docSetBaseY $ e -- TODO92 comments AnnOpenS
-              ]
-            , docLit $ Text.pack " ]"
+            , docSeparator
+            , docSetBaseY $ e -- TODO92 comments AnnOpenS
             ]
+          , docLit $ Text.pack " ]"
           ]
-        FirstLast e1 ems eN -> runFilteredAlternative $ do
-          addAlternativeCond (not hasComments)
-            $ docSeq
-            $ [docLit $ Text.pack "'[", sepIfHeadPromoted]
-            ++ List.intersperse
-                 specialCommaSep
-                 (docForceSingleline
-                 <$> (e1 : ems ++ [eN]) -- TODO92 comments AnnOpenS
-                 )
-            ++ [docLit $ Text.pack " ]"]
-          addAlternative
-            $ let
-                start = docCols ColList [appSep $ docLit $ Text.pack "'[", e1]
-                linesM = ems <&> \d -> docCols ColList [specialCommaSep, d]
-                lineN = docCols
-                  ColList
-                  [specialCommaSep, eN] -- TODO92 comments AnnOpenS
-                end = docLit $ Text.pack " ]"
-              in docSetBaseY $ docLines $ [start] ++ linesM ++ [lineN] ++ [end]
-      ]
+        ]
+      FirstLast e1 ems eN -> runFilteredAlternative $ do
+        addAlternativeCond (not hasComments)
+          $ docSeq
+          $ [docLit $ Text.pack "'[", sepIfHeadPromoted]
+          ++ List.intersperse
+               docCommaSep
+               (docForceSingleline
+               <$> (e1 : ems ++ [eN]) -- TODO92 comments AnnOpenS
+               )
+          ++ [sepIfHeadPromoted, docLit $ Text.pack "]"]
+        addAlternative
+          $ let
+              start = docCols ColList [appSep $ docLit $ Text.pack "'[", e1]
+              linesM = ems <&> \d -> docCols ColList [specialCommaSep, d]
+              lineN = docCols
+                ColList
+                [specialCommaSep, eN] -- TODO92 comments AnnOpenS
+              end = docLit $ Text.pack " ]"
+            in docSetBaseY $ docLines $ [start] ++ linesM ++ [lineN] ++ [end]
   HsExplicitTupleTy{} -> -- TODO
     briDocByExactInlineOnly "HsExplicitTupleTy{}" ltype
   HsTyLit _ lit -> case lit of