From a5a24b4220ec926696dd2ea0b3a3a87f6eeaa3e5 Mon Sep 17 00:00:00 2001 From: Phil Hazelden Date: Fri, 10 Aug 2018 09:49:47 +0100 Subject: [PATCH] Fix imports of type operators. Previously, we could only import a type operator with no subsequent list, i.e. import Foo ( (:.) ) was fine, but import Foo ( (:.)(..) ) import Foo ( (:.)((:.) ) import Foo ( (:.)(A, b) ) would all break. Brittany would attempt to output them as import Foo ( :.(..) ) import Foo ( :.((:.) ) import Foo ( :.(A, b) ) I believe the problem was that although `ieName <$> lie` was returning an `IEWrappedName` with the same contents as used in `layoutWrapped`, it had different location annotations; and the parentheses are apparently saved in the location annotations. --- src-literatetests/10-tests.blt | 3 +++ src-literatetests/14-extensions.blt | 1 + .../Haskell/Brittany/Internal/Layouters/IE.hs | 13 ++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src-literatetests/10-tests.blt b/src-literatetests/10-tests.blt index 561bd64..db6cbde 100644 --- a/src-literatetests/10-tests.blt +++ b/src-literatetests/10-tests.blt @@ -727,6 +727,9 @@ import Test ( T , T5(T5, t5) , T6((<|>)) , (+) + , (:.) + , (:.)(..) + , (:.)(T7, (:.), t7) ) #test hiding diff --git a/src-literatetests/14-extensions.blt b/src-literatetests/14-extensions.blt index a1c930b..0e71918 100644 --- a/src-literatetests/14-extensions.blt +++ b/src-literatetests/14-extensions.blt @@ -79,4 +79,5 @@ module Test (type (++), (++), pattern Foo) where import Test ( type (++) , (++) , pattern Foo + , pattern (:.) ) diff --git a/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs b/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs index 56462b5..42329cf 100644 --- a/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs +++ b/src/Language/Haskell/Brittany/Internal/Layouters/IE.hs @@ -41,19 +41,19 @@ layoutIE :: ToBriDoc IE layoutIE lie@(L _ ie) = docWrapNode lie $ case ie of IEVar x -> layoutWrapped lie x IEThingAbs x -> layoutWrapped lie x - IEThingAll _ -> docSeq [ienDoc, docLit $ Text.pack "(..)"] - IEThingWith _ (IEWildcard _) _ _ -> - docSeq [ienDoc, docLit $ Text.pack "(..)"] - IEThingWith _ _ ns _ -> do + IEThingAll x -> docSeq [layoutWrapped lie x, docLit $ Text.pack "(..)"] + IEThingWith x (IEWildcard _) _ _ -> + docSeq [layoutWrapped lie x, docLit $ Text.pack "(..)"] + IEThingWith x _ ns _ -> do hasComments <- hasAnyCommentsBelow lie runFilteredAlternative $ do addAlternativeCond (not hasComments) $ docSeq - $ [ienDoc, docLit $ Text.pack "("] + $ [layoutWrapped lie x, docLit $ Text.pack "("] ++ intersperse docCommaSep (map nameDoc ns) ++ [docParenR] addAlternative $ docAddBaseY BrIndentRegular $ docPar - ienDoc + (layoutWrapped lie x) (layoutItems (splitFirstLast ns)) where nameDoc = (docLit =<<) . lrdrNameToTextAnn . prepareName @@ -75,7 +75,6 @@ layoutIE lie@(L _ ie) = docWrapNode lie $ case ie of ] _ -> docEmpty where - ienDoc = docLit =<< lrdrNameToTextAnn (ieName <$> lie) #if MIN_VERSION_ghc(8,2,0) /* ghc-8.2, 8.4, .. */ layoutWrapped _ = \case L _ (IEName n) -> docLit =<< lrdrNameToTextAnn n -- 2.30.2