[GHC] #7336: Defined but not used is not detected for data types with instances
GHC
cvs-ghc at haskell.org
Wed Oct 31 10:39:45 CET 2012
#7336: Defined but not used is not detected for data types with instances
------------------------------------------+---------------------------------
Reporter: maeder | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.1
Resolution: fixed | Keywords:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: None/Unknown | Difficulty: Unknown
Testcase: rename/should_compile/T7336 | Blockedby:
Blocking: | Related:
------------------------------------------+---------------------------------
Changes (by simonpj):
* status: new => closed
* difficulty: => Unknown
* resolution: => fixed
* testcase: => rename/should_compile/T7336
Comment:
Good point. Here's a fix:
{{{
commit 910a642294eb3547d0cbb3d5735ad81b964f137b
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Mon Oct 29 23:25:25 2012 +0000
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.
}}}
The fix does not treat "deriving" specially; it simply changes the way
that constructors appearing in pattern matches are treated. Nice and
simple, and it showed up some unused constructors in GHC itself (see the
commit message).
Thanks for the suggestion.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7336#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list