on master help sign in
Fix comparison of prelude imports
commit733e8086d4555b2b260a76901d85f0ff86fc16fc authormrkkrp <mark.karpov@tweag.io> dateSun 30 Jun 2019, 22:37 (7 years ago) parent8c27549
3 files changed+14−5
data/examples/import/qualified-prelude-out.hs+4 data/examples/import/qualified-prelude.hs+4 src/Ormolu/Imports.hs+6−5
data/examples/import/qualified-prelude-out.hsnew file+4
@@ -0,0 +1,4 @@
1+module P where
2+
3+import Prelude hiding ((.), id)
4+import qualified Prelude
data/examples/import/qualified-prelude.hsnew file+4
@@ -0,0 +1,4 @@
1+module P where
2+
3+import Prelude hiding (id, (.))
4+import qualified Prelude
src/Ormolu/Imports.hs+6−5
@@ -10,6 +10,7 @@ where
1010
1111import Data.Bifunctor
1212import Data.Function (on)
13+import Data.Generics (gcompare)
1314import Data.List (sortBy)
1415import GHC hiding (GhcPs, IE)
1516import HsExtension
@@ -31,11 +32,11 @@ sortImports = sortBy compareIdecl . fmap (fmap sortImportLists)
3132
3233compareIdecl :: LImportDecl GhcPs -> LImportDecl GhcPs -> Ordering
3334compareIdecl (L _ m0) (L _ m1) =
34− if isPrelude n0
35− then GT
36− else if isPrelude n1
37− then LT
38− else n0 `compare` n1
35+ case (isPrelude n0, isPrelude n1) of
36+ (False, False) -> n0 `compare` n1
37+ (True, False) -> GT
38+ (False, True) -> LT
39+ (True, True) -> m0 `gcompare` m1
3940 where
4041 n0 = unLoc (ideclName m0)
4142 n1 = unLoc (ideclName m1)