Opened 6 years ago

Last modified 2 years ago

#7336 new bug

Defined but not used is not detected for data types with instances

Reported by: maeder Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.1
Keywords: Cc: cactus
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case: rename/should_compile/T7336
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

module Unused () where

data U = U deriving Show

does _not_ report

Unused.hs:3:6: Warning:
    Defined but not used: type constructor or class `U'

Unused.hs:3:10: Warning: Defined but not used: data constructor `U'

This message is only displayed without "deriving". I know, instances are always exported, but these instances cannot be used.

Considering that all types may get Typeable instances, no unused warning would ever be issued for data types.

Change History (3)

comment:1 Changed 5 years ago by simonpj

difficulty: Unknown
Resolution: fixed
Status: newclosed
Test Case: rename/should_compile/T7336

Good point. Here's a fix:

commit 910a642294eb3547d0cbb3d5735ad81b964f137b
Author: Simon Peyton Jones <simonpj@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

comment:2 in reply to:  1 Changed 3 years ago by thomie

Cc: cactus added
Resolution: fixed
Status: closednew

Commit 22ddcfff16476a6d19190f10743a78bde0b2c28f/ghc mentions:

"T7336 is expected to be broken because of a regression introduced by pattern synonym implementation"

comment:3 Changed 2 years ago by thomie

Type of failure: None/UnknownIncorrect warning at compile-time
Note: See TracTickets for help on using tickets.