• Simon Peyton Jones's avatar
    Do not treat a constructor in a *pattern* as a *use* of that constructor · 910a6422
    Simon Peyton Jones authored
    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.
    910a6422
RnPat.lhs 24.2 KB