summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkeithw <unknown>1999-06-25 12:26:27 +0000
committerkeithw <unknown>1999-06-25 12:26:27 +0000
commit0016c183135c2e64136788f7362c4b164da29b55 (patch)
treedf7ef7add71906b38b9f15ed34a000147147128d
parent10b66230065ac2426509b60eb2da0a314b34d0e3 (diff)
downloadhaskell-0016c183135c2e64136788f7362c4b164da29b55.tar.gz
[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.
-rw-r--r--ghc/compiler/rename/Rename.lhs12
-rw-r--r--ghc/compiler/rename/RnEnv.lhs28
2 files changed, 21 insertions, 19 deletions
diff --git a/ghc/compiler/rename/Rename.lhs b/ghc/compiler/rename/Rename.lhs
index a5769238fb..bfb55af01d 100644
--- a/ghc/compiler/rename/Rename.lhs
+++ b/ghc/compiler/rename/Rename.lhs
@@ -31,8 +31,7 @@ import RnEnv ( availName, availNames, availsToNameSet,
import Module ( Module, ModuleName, pprModule, mkSearchPath, mkThisModule )
import Name ( Name, isLocallyDefined,
NamedThing(..), ImportReason(..), Provenance(..),
- pprOccName, nameOccName,
- getNameProvenance, occNameUserString,
+ pprOccName, getNameProvenance,
maybeWiredInTyConName, maybeWiredInIdName, isWiredInName
)
import Id ( idType )
@@ -493,8 +492,7 @@ reportUnusedNames gbl_env avail_env (ExportEnv export_avails _) mentioned_names
reportableUnusedName :: Name -> Bool
reportableUnusedName name
- = explicitlyImported (getNameProvenance name) &&
- not (startsWithUnderscore (occNameUserString (nameOccName name)))
+ = explicitlyImported (getNameProvenance name)
where
explicitlyImported (LocalDef _ _) = True
-- Report unused defns of local vars
@@ -503,12 +501,6 @@ reportableUnusedName name
explicitlyImported other = False
-- 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 imp_decls
| opt_D_dump_rn_trace ||
diff --git a/ghc/compiler/rename/RnEnv.lhs b/ghc/compiler/rename/RnEnv.lhs
index 430a3677c5..b2c810131f 100644
--- a/ghc/compiler/rename/RnEnv.lhs
+++ b/ghc/compiler/rename/RnEnv.lhs
@@ -24,6 +24,7 @@ import Name ( Name, Provenance(..), ExportFlag(..), NamedThing(..),
mkLocalName, mkImportedLocalName, mkGlobalName, isSystemName,
nameOccName, setNameModule, nameModule,
pprOccName, isLocallyDefined, nameUnique, nameOccName,
+ occNameUserString,
setNameProvenance, getNameProvenance, pprNameProvenance
)
import NameSet
@@ -723,24 +724,33 @@ warnUnusedBinds warn_when_local names
-------------------------
warnUnusedGroup :: (Bool -> Bool) -> [Name] -> RnM d ()
-warnUnusedGroup _ []
- = returnRn ()
-
warnUnusedGroup emit_warning names
| not (emit_warning is_local) = returnRn ()
| otherwise
- = pushSrcLocRn def_loc $
- addWarnRn $
- sep [msg <> colon, nest 4 (fsep (punctuate comma (map ppr names)))]
+ = case filter isReportable names of
+ [] -> returnRn ()
+ repnames -> warn repnames
where
- name1 = head names
- (is_local, def_loc, msg)
- = case getNameProvenance name1 of
+ warn repnames = pushSrcLocRn def_loc $
+ addWarnRn $
+ 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")
NonLocalDef (UserImport mod loc _) _ ->
(True, loc, text "Imported from" <+> quotes (ppr mod) <+>
text "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}
\begin{code}