Fix layout of type-level list literal

ghc92
Lennart Spitzner 2023-05-03 19:53:19 +00:00
parent 84e703d7f3
commit 2b77142617
2 changed files with 53 additions and 53 deletions

View File

@ -8,23 +8,23 @@ test = Proxy @'[ 'True ]
test :: Proxy '[True] test :: Proxy '[True]
test = Proxy @'[True] test = Proxy @'[True]
#test 3 #test 3
test :: Proxy '[ 'True , False ] test :: Proxy '[ 'True, False ]
test = Proxy @'[ 'True , False ] test = Proxy @'[ 'True, False ]
#test 4 #test 4
test :: Proxy '[True , False] test :: Proxy '[True, False]
test = Proxy @'[True , False] test = Proxy @'[True, False]
#test 5 #test 5
test :: Proxy '[True , 'False] test :: Proxy '[True, 'False]
test = Proxy @'[True , 'False] test = Proxy @'[True, 'False]
#test 6 #test 6
test :: Proxy '[ 'True , 'False ] test :: Proxy '[ 'True, 'False ]
test = Proxy @'[ 'True , 'False ] test = Proxy @'[ 'True, 'False ]
#test 7 #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 8
test :: Proxy '[Just True , False] test :: Proxy '[Just True, False]
test = Proxy @'[Just True , False] test = Proxy @'[Just True, False]
#test 9 #test 9
test :: Proxy '[('True)] test :: Proxy '[('True)]
test = Proxy @'[('True)] test = Proxy @'[('True)]
@ -72,3 +72,9 @@ test
True] True]
test = Proxy @'[{- comment -} test = Proxy @'[{- comment -}
True] True]
#test explicit-list-type non-promoted
type Foo = '[Bool, Bool, Bool]
#test explicit-list-type promoted
type Foo = '[ 'Bool, Bool, Bool ]

View File

@ -443,52 +443,46 @@ layoutType ltype@(L _ typ) = docHandleComms ltype $ case typ of
typDocs <- typs `forM` (shareDoc . docHandleListElemComms layoutType) typDocs <- typs `forM` (shareDoc . docHandleListElemComms layoutType)
let hasComments = hasAnyCommentsBelow ltype let hasComments = hasAnyCommentsBelow ltype
docAlt case splitFirstLast typDocs of
[ docSeq FirstLastEmpty -> docSeq
$ [docLit $ Text.pack "'[", sepIfHeadPromoted] [ docLit $ Text.pack "'[]" -- TODO92 comments AnnOpenS
++ List.intersperse specialCommaSep (docForceSingleline <$> typDocs) ]
++ [sepIfHeadPromoted, docLit $ Text.pack "]"] FirstLastSingleton e -> docAlt
, case splitFirstLast typDocs of [ docSeq
FirstLastEmpty -> docSeq [ docLit $ Text.pack "'["
[ docLit $ Text.pack "'[]" -- TODO92 comments AnnOpenS , sepIfHeadPromoted
, docForceSingleline e -- TODO92 comments AnnOpenS
, sepIfHeadPromoted
, docLit $ Text.pack "]"
] ]
FirstLastSingleton e -> docAlt , docSetBaseY $ docLines
[ docSeq [ docSeq
[ docLit $ Text.pack "'[" [ docLit $ Text.pack "'["
, sepIfHeadPromoted , docSeparator
, docForceSingleline e -- TODO92 comments AnnOpenS , docSetBaseY $ e -- TODO92 comments AnnOpenS
, sepIfHeadPromoted
, docLit $ Text.pack "]"
]
, docSetBaseY $ docLines
[ docSeq
[ docLit $ Text.pack "'["
, docSeparator
, docSetBaseY $ e -- TODO92 comments AnnOpenS
]
, docLit $ Text.pack " ]"
] ]
, docLit $ Text.pack " ]"
] ]
FirstLast e1 ems eN -> runFilteredAlternative $ do ]
addAlternativeCond (not hasComments) FirstLast e1 ems eN -> runFilteredAlternative $ do
$ docSeq addAlternativeCond (not hasComments)
$ [docLit $ Text.pack "'[", sepIfHeadPromoted] $ docSeq
++ List.intersperse $ [docLit $ Text.pack "'[", sepIfHeadPromoted]
specialCommaSep ++ List.intersperse
(docForceSingleline docCommaSep
<$> (e1 : ems ++ [eN]) -- TODO92 comments AnnOpenS (docForceSingleline
) <$> (e1 : ems ++ [eN]) -- TODO92 comments AnnOpenS
++ [docLit $ Text.pack " ]"] )
addAlternative ++ [sepIfHeadPromoted, docLit $ Text.pack "]"]
$ let addAlternative
start = docCols ColList [appSep $ docLit $ Text.pack "'[", e1] $ let
linesM = ems <&> \d -> docCols ColList [specialCommaSep, d] start = docCols ColList [appSep $ docLit $ Text.pack "'[", e1]
lineN = docCols linesM = ems <&> \d -> docCols ColList [specialCommaSep, d]
ColList lineN = docCols
[specialCommaSep, eN] -- TODO92 comments AnnOpenS ColList
end = docLit $ Text.pack " ]" [specialCommaSep, eN] -- TODO92 comments AnnOpenS
in docSetBaseY $ docLines $ [start] ++ linesM ++ [lineN] ++ [end] end = docLit $ Text.pack " ]"
] in docSetBaseY $ docLines $ [start] ++ linesM ++ [lineN] ++ [end]
HsExplicitTupleTy{} -> -- TODO HsExplicitTupleTy{} -> -- TODO
briDocByExactInlineOnly "HsExplicitTupleTy{}" ltype briDocByExactInlineOnly "HsExplicitTupleTy{}" ltype
HsTyLit _ lit -> case lit of HsTyLit _ lit -> case lit of