Ticket #3221 (closed bug: fixed)

Opened 4 years ago

Last modified 4 years ago

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

Reported by: NeilMitchell Owned by:
Priority: normal Milestone: 6.12 branch
Component: Compiler Version: 6.10.2
Keywords: Cc: ndmitchell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: rename/should_compile/T3221 Blocked By:
Blocking: Related Tickets:

Description

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.

Change History

Changed 4 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.12 branch

Changed 4 years ago by simonpj

  • status changed from new to closed
  • testcase set to rename/should_compile/T3221
  • resolution set to fixed

Fixed by

Wed May 27 19:21:57 BST 2009  simonpj@microsoft.com
  * Fix Trac #3221: renamer warnings for deriving clauses
  
  This patch arranges to gather the variables used by 'deriving' clauses,
  so that unused bindings are correctly reported.

Simon

Note: See TracTickets for help on using tickets.