git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove RedundantUnqualifiedImport
caf2354Gary Burgess
src/Language/PureScript/Errors.hs−6
@@ -139,7 +139,6 @@ data SimpleErrorMessage
139 | DeprecatedQualifiedSyntax ModuleName ModuleName
139 | DeprecatedQualifiedSyntax ModuleName ModuleName
140 | DeprecatedClassImport ModuleName (ProperName 'ClassName)
140 | DeprecatedClassImport ModuleName (ProperName 'ClassName)
141 | DeprecatedClassExport (ProperName 'ClassName)
141 | DeprecatedClassExport (ProperName 'ClassName)
142− | RedundantUnqualifiedImport ModuleName ImportDeclarationType
143 | DuplicateSelectiveImport ModuleName
142 | DuplicateSelectiveImport ModuleName
144 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
143 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
145 | DuplicateImportRef String
144 | DuplicateImportRef String
@@ -323,7 +322,6 @@ errorCode em = case unwrapErrorMessage em of
323 DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
322 DeprecatedQualifiedSyntax{} -> "DeprecatedQualifiedSyntax"
324 DeprecatedClassImport{} -> "DeprecatedClassImport"
323 DeprecatedClassImport{} -> "DeprecatedClassImport"
325 DeprecatedClassExport{} -> "DeprecatedClassExport"
324 DeprecatedClassExport{} -> "DeprecatedClassExport"
326− RedundantUnqualifiedImport{} -> "RedundantUnqualifiedImport"
327 DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
325 DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
328 DuplicateImport{} -> "DuplicateImport"
326 DuplicateImport{} -> "DuplicateImport"
329 DuplicateImportRef{} -> "DuplicateImportRef"
327 DuplicateImportRef{} -> "DuplicateImportRef"
@@ -452,7 +450,6 @@ errorSuggestion err = case err of
452 UnusedImport{} -> emptySuggestion
450 UnusedImport{} -> emptySuggestion
453 RedundantEmptyHidingImport{} -> emptySuggestion
451 RedundantEmptyHidingImport{} -> emptySuggestion
454 DuplicateImport{} -> emptySuggestion
452 DuplicateImport{} -> emptySuggestion
455− RedundantUnqualifiedImport{} -> emptySuggestion
456 DeprecatedQualifiedSyntax name qualName -> suggest $
453 DeprecatedQualifiedSyntax name qualName -> suggest $
457 "import " ++ runModuleName name ++ " as " ++ runModuleName qualName
454 "import " ++ runModuleName name ++ " as " ++ runModuleName qualName
458 UnusedExplicitImport mn _ qual refs -> suggest $ importSuggestion mn refs qual
455 UnusedExplicitImport mn _ qual refs -> suggest $ importSuggestion mn refs qual
@@ -944,9 +941,6 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
944 , line "The deprecated syntax will be removed in PureScript 0.9."
941 , line "The deprecated syntax will be removed in PureScript 0.9."
945 ]
942 ]
946
943
947− renderSimpleErrorMessage (RedundantUnqualifiedImport name imp) =
948− line $ "Import of " ++ prettyPrintImport name imp Nothing ++ " is redundant due to a whole-module import"
949−
950 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
944 renderSimpleErrorMessage (DuplicateSelectiveImport name) =
951 line $ "There is an existing import of " ++ runModuleName name ++ ", consider merging the import lists"
945 line $ "There is an existing import of " ++ runModuleName name ++ ", consider merging the import lists"
952
946
src/Language/PureScript/Sugar/Names/Imports.hs+23−25
@@ -12,9 +12,10 @@ module Language.PureScript.Sugar.Names.Imports
12import Prelude ()
12import Prelude ()
13import Prelude.Compat
13import Prelude.Compat
14
14
15−import Data.List (find, delete, (\\))
16−import Data.Maybe (fromMaybe, isJust, isNothing, fromJust)
17import Data.Foldable (traverse_, for_)
15import Data.Foldable (traverse_, for_)
16+import Data.Function (on)
17+import Data.List (find, sortBy, groupBy, (\\))
18+import Data.Maybe (fromMaybe, isNothing, fromJust)
18import Data.Traversable (for)
19import Data.Traversable (for)
19
20
20import Control.Arrow (first)
21import Control.Arrow (first)
@@ -68,29 +69,23 @@ resolveImports env (Module ss coms currentModule decls exps) =
68
69
69 for_ (M.toList imports) $ \(mn, imps) -> do
70 for_ (M.toList imports) $ \(mn, imps) -> do
70
71
71− -- Better ordering for the warnings: the list is in last-import-first
72− -- order, but we want the first appearence of an import to be the primary,
73− -- and warnings to appear for later imports
74− let imps' = reverse imps
75−
76− warned <- foldM (checkDuplicateImports mn) [] (selfCartesianSubset imps')
72+ warned <- foldM (checkDuplicateImports mn) [] (selfCartesianSubset imps)
77−
73+
78− let unqual = filter (\(_, _, q) -> isJust q) (imps' \\ warned)
74+ let unwarned = imps \\ warned
79−
75+ duplicates
80− warned' <- (warned ++) <$>
76+ = join
77+ . map tail
81− if (length unqual < 2)
78+ . filter ((> 1) . length)
82− then return []
79+ . groupBy ((==) `on` defQual)
83− else case find (\(_, typ, _) -> isImplicit typ) unqual of
80+ . sortBy (compare `on` defQual)
84− Just i ->
81+ $ unwarned
85− for (delete i unqual) $ \i'@(pos, typ, _) -> do
82+
86− warn pos $ RedundantUnqualifiedImport mn typ
83+ warned' <-
87− return i'
88− Nothing ->
89− for (tail unqual) $ \i@(pos, _, _) -> do
84+ for duplicates $ \i@(pos, _, _) -> do
90− warn pos $ DuplicateSelectiveImport mn
85+ warn pos $ DuplicateSelectiveImport mn
91− return i
86+ return i
92−
87+
93− for_ (imps' \\ warned') $ \(pos, typ, _) ->
88+ for_ (imps \\ (warned ++ warned')) $ \(pos, typ, _) ->
94 let (dupeRefs, dupeDctors) = findDuplicateRefs $ case typ of
89 let (dupeRefs, dupeDctors) = findDuplicateRefs $ case typ of
95 Explicit refs -> refs
90 Explicit refs -> refs
96 Hiding refs -> refs
91 Hiding refs -> refs
@@ -105,6 +100,9 @@ resolveImports env (Module ss coms currentModule decls exps) =
105 return (Module ss coms currentModule decls' exps, resolved)
100 return (Module ss coms currentModule decls' exps, resolved)
106
101
107 where
102 where
103+ defQual :: ImportDef -> Maybe ModuleName
104+ defQual (_, _, q) = q
105+
108 selfCartesianSubset :: [a] -> [(a, a)]
106 selfCartesianSubset :: [a] -> [(a, a)]
109 selfCartesianSubset (x : xs) = [(x, y) | y <- xs] ++ selfCartesianSubset xs
107 selfCartesianSubset (x : xs) = [(x, y) | y <- xs] ++ selfCartesianSubset xs
110 selfCartesianSubset [] = []
108 selfCartesianSubset [] = []