Ticket #1954 (closed merge: fixed)

Opened 6 years ago

Last modified 3 years ago

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 Difficulty: Unknown
Test Case: rename/should_compile/T1954 Blocked By:
Blocking: Related Tickets:

Description

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

Changed 6 years ago by igloo

  • milestone set to 6.8 branch

Thanks for the report

Changed 6 years ago by simonpj

See also #1982

Changed 5 years ago by igloo

  • milestone changed from 6.8 branch to 6.10 branch

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 4 years ago by igloo

  • milestone changed from 6.10 branch to 6.12 branch

Changed 3 years ago by NeilMitchell

  • cc ndmitchell@… added
  • failure set to None/Unknown

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

Changed 3 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.

Changed 3 years ago by simonpj

  • owner set to igloo
  • testcase set to rename/should_compile/T1954
  • type changed from bug to merge

Thanks for the reminder. It was pretty easy to fix

Tue Mar  9 09:35:55 PST 2010  simonpj@microsoft.com
  * 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
  TcEnv.NewTypeDerived
  
  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.

Simon

Changed 3 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Merged

Note: See TracTickets for help on using tickets.