Skip to content

Incorrect "defined but not used" warning for data types using deriving

Consider:

module Main() where

import System

data Foo = Bar | Baz
           deriving (Show,Read)

main = do
    [x] <- getArgs
    print (read x :: Foo)

When we compile:

$ ghc -c Test.hs -fwarn-unused-binds
Test.hs:6:11: Warning: Defined but not used: data constructor `Bar'
Test.hs:6:17: Warning: Defined but not used: data constructor `Baz'

This is incorrect. If a data type derives Read, Enum or Bounded (and for Bounded, is either the first or last element), then the values are used - even if not by name.

Trac metadata
Trac field Value
Version 6.10.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC ndmitchell@gmail.com
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information