Opened 11 years ago

Closed 9 years ago

#1954 closed merge (fixed)

Incorrect "Defined but not used" warning when using GeneralizedNewtypeDeriving

Reported by: magnus Owned by: igloo
Priority: normal Milestone: 6.12 branch
Component: Compiler Version: 6.8.1
Keywords: Cc: ndmitchell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: rename/should_compile/T1954
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


When compiling

{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -Wall -Werror #-}
module Bug(P, runP) where

import Control.Monad.Identity(Identity, runIdentity)

newtype P a = P { unP :: Identity a } deriving Monad

runP :: P a -> a
runP = runIdentity . unP

I get

Bug.hs:7:14: Warning: Defined but not used: data constructor `P'

although the constructor is used in the derived Monad instance. This is obviously not a show stopper, but it forces me to rewrite what to me looks like an OK program if I want to stick to the given OPTIONS_GHC.

Change History (10)

comment:1 Changed 11 years ago by igloo

Milestone: 6.8 branch

Thanks for the report

comment:2 Changed 11 years ago by simonpj

See also #1982

comment:3 Changed 10 years ago by igloo

Milestone: 6.8 branch6.10 branch

comment:4 Changed 10 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:5 Changed 10 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:6 Changed 9 years ago by igloo

Milestone: 6.10 branch6.12 branch

comment:7 Changed 9 years ago by NeilMitchell

Cc: ndmitchell@… added
Type of failure: None/Unknown

I have encountered this bug a few times - there is no simple workaround.

comment:8 Changed 9 years ago by NeilMitchell

For the person who reaches this bug next, -fno-warn-unused-binds disables this warning, without having to go for -w.

comment:9 Changed 9 years ago by simonpj

Owner: set to igloo
Test Case: rename/should_compile/T1954
Type: bugmerge

Thanks for the reminder. It was pretty easy to fix

Tue Mar  9 09:35:55 PST 2010
  * Fix Trac #1954: newtype deriving caused 'defined but not used' error
  We were getting a bogus claim that a newtype "data constructor" was
  unused.  The fix is easy, although I had to add a field to the constructor
  See Note [Newtype deriving and unused constructors] in TcDeriv

    M ./compiler/typecheck/TcDeriv.lhs -3 +25
    M ./compiler/typecheck/TcEnv.lhs -8 +15
    M ./compiler/typecheck/TcInstDcls.lhs -1 +1

Could be merged to 6.12, but not if it causes any trouble.


comment:10 Changed 9 years ago by igloo

Resolution: fixed
Status: newclosed


Note: See TracTickets for help on using tickets.