git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Warn when import X hiding (..) imports nothing
commit0d5ad255958b19b8ab82ce9b3d9904bceab7edfe authorGary Burgess <gary.burgess@gmail.com> dateSat 28 Nov 2015, 18:32 (11 years ago) parent948e45d
2 files changed+16−2
src/Language/PureScript/Errors.hs+5 src/Language/PureScript/Sugar/Names/Imports.hs+11−2
src/Language/PureScript/Errors.hs+5
@@ -147,6 +147,7 @@ data SimpleErrorMessage
147147 | DuplicateSelectiveImport ModuleName
148148 | DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
149149 | IntOutOfRange Integer String Integer Integer
150+ | RedundantEmptyHidingImport ModuleName
150151 deriving (Show)
151152
152153-- | Error message hints, providing more detailed information about failure.
@@ -286,6 +287,7 @@ errorCode em = case unwrapErrorMessage em of
286287 DuplicateSelectiveImport{} -> "DuplicateSelectiveImport"
287288 DuplicateImport{} -> "DuplicateImport"
288289 IntOutOfRange{} -> "IntOutOfRange"
290+ RedundantEmptyHidingImport{} -> "RedundantEmptyHidingImport"
289291
290292
291293-- |
@@ -794,6 +796,9 @@ prettyPrintSingleError full level e = do
794796 paras [ line $ "Integer value " ++ show value ++ " is out of range for the " ++ backend ++ " backend."
795797 , line $ "Acceptable values fall within the range " ++ show lo ++ " to " ++ show hi ++ " (inclusive)." ]
796798
799+ renderSimpleErrorMessage (RedundantEmptyHidingImport mn) =
800+ line $ "The import for module " ++ runModuleName mn ++ " is redundant as all members have been explicitly hidden."
801+
797802 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
798803 renderHint (ErrorUnifyingTypes t1 t2) detail =
799804 paras [ detail
src/Language/PureScript/Sugar/Names/Imports.hs+11−2
@@ -56,7 +56,7 @@ findImports = foldM (go Nothing) M.empty
5656 go _ result (PositionedDeclaration pos _ d) = warnAndRethrowWithPosition pos $ go (Just pos) result d
5757 go _ result _ = return result
5858
59− -- Ensure that classes don't appear in an `import X hiding (...)`
59+ -- Ensure that modules don't appear in an `import X hiding (...)`
6060 checkImportRefType :: ImportDeclarationType -> m ()
6161 checkImportRefType (Hiding refs) = traverse_ checkImportRef refs
6262 checkImportRefType _ = return ()
@@ -129,7 +129,16 @@ resolveImport currentModule importModule exps imps impQual =
129129 resolveByType :: ImportDeclarationType -> m Imports
130130 resolveByType Implicit = importAll importExplicit
131131 resolveByType (Explicit explImports) = checkRefs explImports >> foldM importExplicit imps explImports
132− resolveByType (Hiding hiddenImports) = checkRefs hiddenImports >> importAll (importNonHidden hiddenImports)
132+ resolveByType (Hiding hiddenImports) = do
133+ checkRefs 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'
133142
134143 -- Check that a 'DeclarationRef' refers to an importable symbol
135144 checkRefs :: [DeclarationRef] -> m ()