diff options
author | simonpj@microsoft.com <unknown> | 2009-05-28 15:23:59 +0000 |
---|---|---|
committer | simonpj@microsoft.com <unknown> | 2009-05-28 15:23:59 +0000 |
commit | 46f02d59813499ba2aa44e7831e0b69ec6d8f25d (patch) | |
tree | 1c98798d0e1035f79fe79aeddc9e686b8bda2322 /compiler | |
parent | e16df2647fde526846e4c13470250ee5b475bdd2 (diff) | |
download | haskell-46f02d59813499ba2aa44e7831e0b69ec6d8f25d.tar.gz |
Fix Trac #3262: suppress name-shadow warning for _names
Adopt Max's suggestion for name shadowing, by suppressing shadowing
warnings for variables starting with "_". A tiny bit of refactoring
along the way.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/basicTypes/NameSet.lhs | 2 | ||||
-rw-r--r-- | compiler/basicTypes/OccName.lhs | 15 | ||||
-rw-r--r-- | compiler/rename/RnEnv.lhs | 4 | ||||
-rw-r--r-- | compiler/typecheck/TcInstDcls.lhs | 2 |
4 files changed, 12 insertions, 11 deletions
diff --git a/compiler/basicTypes/NameSet.lhs b/compiler/basicTypes/NameSet.lhs index 7eb5da5a26..46bcee72ab 100644 --- a/compiler/basicTypes/NameSet.lhs +++ b/compiler/basicTypes/NameSet.lhs @@ -189,7 +189,7 @@ findUses dus uses = rhs_uses `unionNameSets` uses get (Just defs, rhs_uses) uses | defs `intersectsNameSet` uses -- Used - || not (all (reportIfUnused . nameOccName) (nameSetToList defs)) + || any (startsWithUnderscore . nameOccName) (nameSetToList defs) -- At least one starts with an "_", -- so treat the group as used = rhs_uses `unionNameSets` uses diff --git a/compiler/basicTypes/OccName.lhs b/compiler/basicTypes/OccName.lhs index c2aae5d6f8..10cf91eb79 100644 --- a/compiler/basicTypes/OccName.lhs +++ b/compiler/basicTypes/OccName.lhs @@ -65,7 +65,7 @@ module OccName ( occNameFS, occNameString, occNameSpace, isVarOcc, isTvOcc, isTcOcc, isDataOcc, isDataSymOcc, isSymOcc, isValOcc, - parenSymOcc, reportIfUnused, + parenSymOcc, startsWithUnderscore, isTcClsNameSpace, isTvNameSpace, isDataConNameSpace, isVarNameSpace, isValNameSpace, @@ -463,13 +463,12 @@ parenSymOcc occ doc | isSymOcc occ = parens doc \begin{code} -reportIfUnused :: OccName -> Bool --- ^ Haskell 98 encourages compilers to suppress warnings about --- unused names in a pattern if they start with @_@: this implements --- that test -reportIfUnused occ = case occNameString occ of - ('_' : _) -> False - _other -> True +startsWithUnderscore :: OccName -> Bool +-- ^ Haskell 98 encourages compilers to suppress warnings about unsed +-- names in a pattern if they start with @_@: this implements that test +startsWithUnderscore occ = case occNameString occ of + ('_' : _) -> True + _other -> False \end{code} diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs index 56f18ab763..b4dafd3548 100644 --- a/compiler/rename/RnEnv.lhs +++ b/compiler/rename/RnEnv.lhs @@ -904,6 +904,8 @@ checkShadowedNames doc_str (global_env,local_env) loc_rdr_names ; mappM_ check_shadow loc_rdr_names } where check_shadow (loc, occ) + | startsWithUnderscore occ = return () -- Do not report shadowing for "_x" + -- See Trac #3262 | Just n <- mb_local = complain [ptext (sLit "bound at") <+> ppr (nameSrcLoc n)] | otherwise = do { gres' <- filterM is_shadowed_gre gres ; complain (map pprNameProvenance gres') } @@ -1007,7 +1009,7 @@ warnUnusedBinds names = mappM_ warnUnusedName (filter reportable names) | isWiredInName name = False -- Don't report unused wired-in names -- Otherwise we get a zillion warnings -- from Data.Tuple - | otherwise = reportIfUnused (nameOccName name) + | otherwise = not (startsWithUnderscore (nameOccName name)) ------------------------- diff --git a/compiler/typecheck/TcInstDcls.lhs b/compiler/typecheck/TcInstDcls.lhs index 2435395546..cf03e7116b 100644 --- a/compiler/typecheck/TcInstDcls.lhs +++ b/compiler/typecheck/TcInstDcls.lhs @@ -860,7 +860,7 @@ tcInstanceMethod loc clas tyvars dfun_dicts theta inst_tys (Nothing, NoDefMeth) -> do -- No default method in the class { warn <- doptM Opt_WarnMissingMethods ; warnTc (warn -- Warn only if -fwarn-missing-methods - && reportIfUnused (getOccName sel_id)) + && not (startsWithUnderscore (getOccName sel_id))) -- Don't warn about _foo methods omitted_meth_warn ; return (error_rhs, emptyBag) } |