Skip to content

Spurious "defined but not used" warnings for constructors of types deriving Read

Consider the following code:

  data D = D { ds :: String, db :: Bool }
    deriving (Read, Show)

  main :: IO ()
  main = do
    let s = "D { ds = \"oi\", db = True }"
    print (ds (read s))
    print (db (read s))

With -Wall, ghc emits the following warning:

  Warning: Defined but not used: data constructor `D'

I think this warning is not justified, because the D constructor is used to parse s.

The testcase above was derived from a program where D held a bunch of configuration fields for the program, and s was read from configuration file.

I would think the fix should be a rule along the lines of: if a data type derives from Read, then all of its constructors and field names are considered used.

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