git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1679 from purescript/warn-empty-hiding

Warn when import X hiding (..) imports nothing

commitdb3419ca14811a7baae558198646ef3042f5d1a2 authorGary Burgess <gary.burgess@gmail.com> dateMon 30 Nov 2015, 18:06 (11 years ago) parent9b305060d5ad25
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
@@ -149,6 +149,7 @@ data SimpleErrorMessage
149149 | DuplicateImportRef String
150150 | DuplicateExportRef String
151151 | IntOutOfRange Integer String Integer Integer
152+ | RedundantEmptyHidingImport ModuleName
152153 deriving (Show)
153154
154155-- | Error message hints, providing more detailed information about failure.
@@ -290,6 +291,7 @@ errorCode em = case unwrapErrorMessage em of
290291 DuplicateImportRef{} -> "DuplicateImportRef"
291292 DuplicateExportRef{} -> "DuplicateExportRef"
292293 IntOutOfRange{} -> "IntOutOfRange"
294+ RedundantEmptyHidingImport{} -> "RedundantEmptyHidingImport"
293295
294296
295297-- |
@@ -804,6 +806,9 @@ prettyPrintSingleError full level e = do
804806 paras [ line $ "Integer value " ++ show value ++ " is out of range for the " ++ backend ++ " backend."
805807 , line $ "Acceptable values fall within the range " ++ show lo ++ " to " ++ show hi ++ " (inclusive)." ]
806808
809+ renderSimpleErrorMessage (RedundantEmptyHidingImport mn) =
810+ line $ "The import for module " ++ runModuleName mn ++ " is redundant as all members have been explicitly hidden."
811+
807812 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
808813 renderHint (ErrorUnifyingTypes t1 t2) detail =
809814 paras [ detail
src/Language/PureScript/Sugar/Names/Imports.hs+11−2
@@ -58,7 +58,7 @@ findImports = foldM (go Nothing) M.empty
5858 go _ result (PositionedDeclaration pos _ d) = warnAndRethrowWithPosition pos $ go (Just pos) result d
5959 go _ result _ = return result
6060
61− -- Ensure that classes don't appear in an `import X hiding (...)`
61+ -- Ensure that modules don't appear in an `import X hiding (...)`
6262 checkImportRefType :: ImportDeclarationType -> m ()
6363 checkImportRefType (Hiding refs) = traverse_ checkImportRef refs
6464 checkImportRefType _ = return ()
@@ -171,7 +171,16 @@ resolveImport currentModule importModule exps imps impQual =
171171 resolveByType :: ImportDeclarationType -> m Imports
172172 resolveByType Implicit = importAll importExplicit
173173 resolveByType (Explicit explImports) = checkRefs explImports >> foldM importExplicit imps explImports
174− resolveByType (Hiding hiddenImports) = checkRefs hiddenImports >> importAll (importNonHidden hiddenImports)
174+ resolveByType (Hiding hiddenImports) = do
175+ checkRefs hiddenImports
176+ imps' <- importAll (importNonHidden hiddenImports)
177+ let isEmptyImport
178+ = M.null (importedTypes imps')
179+ && M.null (importedDataConstructors imps')
180+ && M.null (importedTypeClasses imps')
181+ && M.null (importedValues imps')
182+ when isEmptyImport $ tell . errorMessage $ RedundantEmptyHidingImport importModule
183+ return imps'
175184
176185 -- Check that a 'DeclarationRef' refers to an importable symbol
177186 checkRefs :: [DeclarationRef] -> m ()