diff --git a/src-unittests/IdentityTests.hs b/src-unittests/IdentityTests.hs index 4ac6662..b968755 100644 --- a/src-unittests/IdentityTests.hs +++ b/src-unittests/IdentityTests.hs @@ -669,3 +669,13 @@ regressionTests = do x1' <- docSeq [prepElem, return x1] return $ x1' Seq.<| xR |] + it "type signature multiline forcing issue" $ do + roundTripEqual $ + [text| + layoutWriteNewlineBlock + :: ( MonadMultiWriter Text.Builder.Builder m + , MonadMultiState LayoutState m + , MonadMultiWriter (Seq String) m + ) + => m () + |] diff --git a/src/Language/Haskell/Brittany/Layouters/Type.hs b/src/Language/Haskell/Brittany/Layouters/Type.hs index d936b3f..a92147d 100644 --- a/src/Language/Haskell/Brittany/Layouters/Type.hs +++ b/src/Language/Haskell/Brittany/Layouters/Type.hs @@ -39,6 +39,9 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of d <- docSharedWrapper layoutType kind return $ (lrdrNameToText lrdrName, Just $ d) cntxtDocs <- cntxts `forM` docSharedWrapper layoutType + let maybeForceML = case typ2 of + (L _ HsFunTy{}) -> docForceMultiline + _ -> id let tyVarDocLineList = tyVarDocs >>= \case (tname, Nothing) -> [docLit $ Text.pack " " <> tname] @@ -119,7 +122,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of ] , docCols ColTyOpPrefix [ docLit $ Text.pack "=> " - , docAddBaseY (BrIndentSpecial 3) $ docForceMultiline $ typeDoc + , docAddBaseY (BrIndentSpecial 3) $ maybeForceML $ typeDoc ] ] ) @@ -212,6 +215,9 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of ] in docPar open $ docLines $ list ++ [close] ] + let maybeForceML = case typ1 of + (L _ HsFunTy{}) -> docForceMultiline + _ -> id docAlt -- (Foo a b c) => a b -> c [ docSeq @@ -226,16 +232,16 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of (docForceSingleline contextDoc) ( docCols ColTyOpPrefix [ docLit $ Text.pack "=> " - , docAddBaseY (BrIndentSpecial 3) $ docForceMultiline typeDoc + , docAddBaseY (BrIndentSpecial 3) $ maybeForceML typeDoc ] ) ] HsFunTy typ1 typ2 -> do typeDoc1 <- docSharedWrapper layoutType typ1 typeDoc2 <- docSharedWrapper layoutType typ2 - let shouldForceML = case typ2 of - (L _ HsFunTy{}) -> True - _ -> False + let maybeForceML = case typ2 of + (L _ HsFunTy{}) -> docForceMultiline + _ -> id hasComments <- hasAnyCommentsBelow ltype docAlt $ [ docSeq @@ -250,8 +256,7 @@ layoutType ltype@(L _ typ) = docWrapNode ltype $ case typ of ( docCols ColTyOpPrefix [ docWrapNodeRest ltype $ appSep $ docLit $ Text.pack "->" , docAddBaseY (BrIndentSpecial 3) - $ if shouldForceML then docForceMultiline typeDoc2 - else typeDoc2 + $ maybeForceML typeDoc2 ] ) ]