git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Warn when import X hiding (..) imports nothing
0d5ad25Gary Burgess
src/Language/PureScript/Errors.hs+5
@@ -147,6 +147,7 @@ data SimpleErrorMessage
147 | DuplicateSelectiveImport ModuleName
147 | DuplicateSelectiveImport ModuleName
148 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
148 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
149 | IntOutOfRange Integer String Integer Integer
149 | IntOutOfRange Integer String Integer Integer
150+ | RedundantEmptyHidingImport ModuleName
150 deriving (Show)
151 deriving (Show)
151
152
152-- | Error message hints, providing more detailed information about failure.
153-- | Error message hints, providing more detailed information about failure.
@@ -286,6 +287,7 @@ errorCode em = case unwrapErrorMessage em of
286 DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
287 DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
287 DuplicateImport{} -> "DuplicateImport"
288 DuplicateImport{} -> "DuplicateImport"
288 IntOutOfRange{} -> "IntOutOfRange"
289 IntOutOfRange{} -> "IntOutOfRange"
290+ RedundantEmptyHidingImport{} -> "RedundantEmptyHidingImport"
289
291
290
292
291-- |
293-- |
@@ -794,6 +796,9 @@ prettyPrintSingleError full level e = do
794 paras [ line $ "Integer value " ++ show value ++ " is out of range for the " ++ backend ++ " backend."
796 paras [ line $ "Integer value " ++ show value ++ " is out of range for the " ++ backend ++ " backend."
795 , line $ "Acceptable values fall within the range " ++ show lo ++ " to " ++ show hi ++ " (inclusive)." ]
797 , line $ "Acceptable values fall within the range " ++ show lo ++ " to " ++ show hi ++ " (inclusive)." ]
796
798
799+ renderSimpleErrorMessage (RedundantEmptyHidingImport mn) =
800+ line $ "The import for module " ++ runModuleName mn ++ " is redundant as all members have been explicitly hidden."
801+
797 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
802 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
798 renderHint (ErrorUnifyingTypes t1 t2) detail =
803 renderHint (ErrorUnifyingTypes t1 t2) detail =
799 paras [ detail
804 paras [ detail
src/Language/PureScript/Sugar/Names/Imports.hs+11−2
@@ -56,7 +56,7 @@ findImports = foldM (go Nothing) M.empty
56 go _ result (PositionedDeclaration pos _ d) = warnAndRethrowWithPosition pos $ go (Just pos) result d
56 go _ result (PositionedDeclaration pos _ d) = warnAndRethrowWithPosition pos $ go (Just pos) result d
57 go _ result _ = return result
57 go _ result _ = return result
58
58
59− -- Ensure that classes don't appear in an `import X hiding (...)`
59+ -- Ensure that modules don't appear in an `import X hiding (...)`
60 checkImportRefType :: ImportDeclarationType -> m ()
60 checkImportRefType :: ImportDeclarationType -> m ()
61 checkImportRefType (Hiding refs) = traverse_ checkImportRef refs
61 checkImportRefType (Hiding refs) = traverse_ checkImportRef refs
62 checkImportRefType _ = return ()
62 checkImportRefType _ = return ()
@@ -129,7 +129,16 @@ resolveImport currentModule importModule exps imps impQual =
129 resolveByType :: ImportDeclarationType -> m Imports
129 resolveByType :: ImportDeclarationType -> m Imports
130 resolveByType Implicit = importAll importExplicit
130 resolveByType Implicit = importAll importExplicit
131 resolveByType (Explicit explImports) = checkRefs explImports >> foldM importExplicit imps explImports
131 resolveByType (Explicit explImports) = checkRefs explImports >> foldM importExplicit imps explImports
132+ resolveByType (Hiding hiddenImports) = do
133+ checkRefs hiddenImports
132− resolveByType (Hiding hiddenImports) = checkRefs hiddenImports >> importAll (importNonHidden hiddenImports)
134+ imps' <- importAll (importNonHidden hiddenImports)
135+ let isEmptyImport
136+ = M.null (importedTypes imps')
137+ && M.null (importedDataConstructors imps')
138+ && M.null (importedTypeClasses imps')
139+ && M.null (importedValues imps')
140+ when isEmptyImport $ tell . errorMessage $ RedundantEmptyHidingImport importModule
141+ return imps'
133
142
134 -- Check that a 'DeclarationRef' refers to an importable symbol
143 -- Check that a 'DeclarationRef' refers to an importable symbol
135 checkRefs :: [DeclarationRef] -> m ()
144 checkRefs :: [DeclarationRef] -> m ()