Commit 0016c183 authored by keithw's avatar keithw
Browse files

[project @ 1999-06-25 12:26:27 by keithw]

Fix `defined but not used' warning to omit *all* identifiers beginning
with underscore, not just top-level ones, following Haskell report.
parent 10b66230
...@@ -31,8 +31,7 @@ import RnEnv ( availName, availNames, availsToNameSet, ...@@ -31,8 +31,7 @@ import RnEnv ( availName, availNames, availsToNameSet,
import Module ( Module, ModuleName, pprModule, mkSearchPath, mkThisModule ) import Module ( Module, ModuleName, pprModule, mkSearchPath, mkThisModule )
import Name ( Name, isLocallyDefined, import Name ( Name, isLocallyDefined,
NamedThing(..), ImportReason(..), Provenance(..), NamedThing(..), ImportReason(..), Provenance(..),
pprOccName, nameOccName, pprOccName, getNameProvenance,
getNameProvenance, occNameUserString,
maybeWiredInTyConName, maybeWiredInIdName, isWiredInName maybeWiredInTyConName, maybeWiredInIdName, isWiredInName
) )
import Id ( idType ) import Id ( idType )
...@@ -493,8 +492,7 @@ reportUnusedNames gbl_env avail_env (ExportEnv export_avails _) mentioned_names ...@@ -493,8 +492,7 @@ reportUnusedNames gbl_env avail_env (ExportEnv export_avails _) mentioned_names
reportableUnusedName :: Name -> Bool reportableUnusedName :: Name -> Bool
reportableUnusedName name reportableUnusedName name
= explicitlyImported (getNameProvenance name) && = explicitlyImported (getNameProvenance name)
not (startsWithUnderscore (occNameUserString (nameOccName name)))
where where
explicitlyImported (LocalDef _ _) = True explicitlyImported (LocalDef _ _) = True
-- Report unused defns of local vars -- Report unused defns of local vars
...@@ -503,12 +501,6 @@ reportableUnusedName name ...@@ -503,12 +501,6 @@ reportableUnusedName name
explicitlyImported other = False explicitlyImported other = False
-- Don't report others -- Don't report others
-- Haskell 98 encourages compilers to suppress warnings about
-- unused names in a pattern if they start with "_".
startsWithUnderscore ('_' : _) = True
-- Suppress warnings for names starting with an underscore
startsWithUnderscore other = False
rnStats :: [RenamedHsDecl] -> RnMG () rnStats :: [RenamedHsDecl] -> RnMG ()
rnStats imp_decls rnStats imp_decls
| opt_D_dump_rn_trace || | opt_D_dump_rn_trace ||
......
...@@ -24,6 +24,7 @@ import Name ( Name, Provenance(..), ExportFlag(..), NamedThing(..), ...@@ -24,6 +24,7 @@ import Name ( Name, Provenance(..), ExportFlag(..), NamedThing(..),
mkLocalName, mkImportedLocalName, mkGlobalName, isSystemName, mkLocalName, mkImportedLocalName, mkGlobalName, isSystemName,
nameOccName, setNameModule, nameModule, nameOccName, setNameModule, nameModule,
pprOccName, isLocallyDefined, nameUnique, nameOccName, pprOccName, isLocallyDefined, nameUnique, nameOccName,
occNameUserString,
setNameProvenance, getNameProvenance, pprNameProvenance setNameProvenance, getNameProvenance, pprNameProvenance
) )
import NameSet import NameSet
...@@ -723,24 +724,33 @@ warnUnusedBinds warn_when_local names ...@@ -723,24 +724,33 @@ warnUnusedBinds warn_when_local names
------------------------- -------------------------
warnUnusedGroup :: (Bool -> Bool) -> [Name] -> RnM d () warnUnusedGroup :: (Bool -> Bool) -> [Name] -> RnM d ()
warnUnusedGroup _ []
= returnRn ()
warnUnusedGroup emit_warning names warnUnusedGroup emit_warning names
| not (emit_warning is_local) = returnRn () | not (emit_warning is_local) = returnRn ()
| otherwise | otherwise
= pushSrcLocRn def_loc $ = case filter isReportable names of
addWarnRn $ [] -> returnRn ()
sep [msg <> colon, nest 4 (fsep (punctuate comma (map ppr names)))] repnames -> warn repnames
where where
name1 = head names warn repnames = pushSrcLocRn def_loc $
(is_local, def_loc, msg) addWarnRn $
= case getNameProvenance name1 of sep [msg <> colon, nest 4 (fsep (punctuate comma (map ppr repnames)))]
name1 = head names
(is_local, def_loc, msg)
= case getNameProvenance name1 of
LocalDef loc _ -> (True, loc, text "Defined but not used") LocalDef loc _ -> (True, loc, text "Defined but not used")
NonLocalDef (UserImport mod loc _) _ -> NonLocalDef (UserImport mod loc _) _ ->
(True, loc, text "Imported from" <+> quotes (ppr mod) <+> (True, loc, text "Imported from" <+> quotes (ppr mod) <+>
text "but not used") text "but not used")
other -> (False, getSrcLoc name1, text "Strangely defined but not used") other -> (False, getSrcLoc name1, text "Strangely defined but not used")
isReportable = not . startsWithUnderscore . occNameUserString . nameOccName
-- Haskell 98 encourages compilers to suppress warnings about
-- unused names in a pattern if they start with "_".
startsWithUnderscore ('_' : _) = True
-- Suppress warnings for names starting with an underscore
startsWithUnderscore other = False
\end{code} \end{code}
\begin{code} \begin{code}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment