git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1679 from purescript/warn-empty-hiding
db3419cGary Burgess
src/Language/PureScript/Errors.hs+5
@@ -149,6 +149,7 @@ data SimpleErrorMessage
149 | DuplicateImportRef String
149 | DuplicateImportRef String
150 | DuplicateExportRef String
150 | DuplicateExportRef String
151 | IntOutOfRange Integer String Integer Integer
151 | IntOutOfRange Integer String Integer Integer
152+ | RedundantEmptyHidingImport ModuleName
152 deriving (Show)
153 deriving (Show)
153
154
154-- | Error message hints, providing more detailed information about failure.
155-- | Error message hints, providing more detailed information about failure.
@@ -290,6 +291,7 @@ errorCode em = case unwrapErrorMessage em of
290 DuplicateImportRef{} -> "DuplicateImportRef"
291 DuplicateImportRef{} -> "DuplicateImportRef"
291 DuplicateExportRef{} -> "DuplicateExportRef"
292 DuplicateExportRef{} -> "DuplicateExportRef"
292 IntOutOfRange{} -> "IntOutOfRange"
293 IntOutOfRange{} -> "IntOutOfRange"
294+ RedundantEmptyHidingImport{} -> "RedundantEmptyHidingImport"
293
295
294
296
295-- |
297-- |
@@ -804,6 +806,9 @@ prettyPrintSingleError full level e = do
804 paras [ line $ "Integer value " ++ show value ++ " is out of range for the " ++ backend ++ " backend."
806 paras [ line $ "Integer value " ++ show value ++ " is out of range for the " ++ backend ++ " backend."
805 , line $ "Acceptable values fall within the range " ++ show lo ++ " to " ++ show hi ++ " (inclusive)." ]
807 , line $ "Acceptable values fall within the range " ++ show lo ++ " to " ++ show hi ++ " (inclusive)." ]
806
808
809+ renderSimpleErrorMessage (RedundantEmptyHidingImport mn) =
810+ line $ "The import for module " ++ runModuleName mn ++ " is redundant as all members have been explicitly hidden."
811+
807 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
812 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
808 renderHint (ErrorUnifyingTypes t1 t2) detail =
813 renderHint (ErrorUnifyingTypes t1 t2) detail =
809 paras [ detail
814 paras [ detail
src/Language/PureScript/Sugar/Names/Imports.hs+11−2
@@ -58,7 +58,7 @@ findImports = foldM (go Nothing) M.empty
58 go _ result (PositionedDeclaration pos _ d) = warnAndRethrowWithPosition pos $ go (Just pos) result d
58 go _ result (PositionedDeclaration pos _ d) = warnAndRethrowWithPosition pos $ go (Just pos) result d
59 go _ result _ = return result
59 go _ result _ = return result
60
60
61− -- Ensure that classes don't appear in an `import X hiding (...)`
61+ -- Ensure that modules don't appear in an `import X hiding (...)`
62 checkImportRefType :: ImportDeclarationType -> m ()
62 checkImportRefType :: ImportDeclarationType -> m ()
63 checkImportRefType (Hiding refs) = traverse_ checkImportRef refs
63 checkImportRefType (Hiding refs) = traverse_ checkImportRef refs
64 checkImportRefType _ = return ()
64 checkImportRefType _ = return ()
@@ -171,7 +171,16 @@ resolveImport currentModule importModule exps imps impQual =
171 resolveByType :: ImportDeclarationType -> m Imports
171 resolveByType :: ImportDeclarationType -> m Imports
172 resolveByType Implicit = importAll importExplicit
172 resolveByType Implicit = importAll importExplicit
173 resolveByType (Explicit explImports) = checkRefs explImports >> foldM importExplicit imps explImports
173 resolveByType (Explicit explImports) = checkRefs explImports >> foldM importExplicit imps explImports
174+ resolveByType (Hiding hiddenImports) = do
175+ checkRefs hiddenImports
174− resolveByType (Hiding hiddenImports) = checkRefs hiddenImports >> importAll (importNonHidden 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'
175
184
176 -- Check that a 'DeclarationRef' refers to an importable symbol
185 -- Check that a 'DeclarationRef' refers to an importable symbol
177 checkRefs :: [DeclarationRef] -> m ()
186 checkRefs :: [DeclarationRef] -> m ()