diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2012-10-29 23:25:25 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2012-10-29 23:25:25 +0000 |
commit | 910a642294eb3547d0cbb3d5735ad81b964f137b (patch) | |
tree | 73af8af49ebd4de7411f9f32ab206944245de9c4 /compiler/rename | |
parent | f8c23ff396eb3552b74d8045db28aa96ab519596 (diff) | |
download | haskell-910a642294eb3547d0cbb3d5735ad81b964f137b.tar.gz |
Do not treat a constructor in a *pattern* as a *use* of that constructor
Occurrences in terms are uses, in patterns they are not.
In this way we get unused-constructor warnings from modules like this
module M( f, g, T ) where
data T = T1 | T2 Bool
f x = T2 x
g T1 = True
g (T2 x) = x
Here a T1 value cannot be constructed, so we can warn. The use
in a pattern doesn't count. See Note [Patterns are not uses]
in RnPat.
Interestingly this change exposed three module in GHC itself
that had unused constructors, which I duly removed:
* ghc/Main.hs
* compiler/ghci/ByteCodeAsm
* compiler/nativeGen/PPC/RegInfo
Their changes are in this patch.
Diffstat (limited to 'compiler/rename')
-rw-r--r-- | compiler/rename/RnPat.lhs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/compiler/rename/RnPat.lhs b/compiler/rename/RnPat.lhs index c3b40fe0f2..9738585aa4 100644 --- a/compiler/rename/RnPat.lhs +++ b/compiler/rename/RnPat.lhs @@ -121,10 +121,26 @@ wrapSrcSpanCps fn (L loc a) lookupConCps :: Located RdrName -> CpsRn (Located Name) lookupConCps con_rdr = CpsRn (\k -> do { con_name <- lookupLocatedOccRn con_rdr - ; (r, fvs) <- k con_name - ; return (r, fvs `plusFV` unitFV (unLoc con_name)) }) + ; k con_name }) + -- We do not add the constructor name to the free vars + -- See Note [Patterns are not uses] \end{code} +Note [Patterns are not uses] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Consider + module Foo( f, g ) where + data T = T1 | T2 + + f T1 = True + f T2 = False + + g _ = T1 + +Arguaby we should report T2 as unused, even though it appears in a +pattern, because it never occurs in a constructed position. See +Trac #7336. + %********************************************************* %* * Name makers |