Opened 3 years ago

Closed 3 years ago

#6031 closed bug (fixed)

Cannot derive instances for empty datatypes defined in other modules

Reported by: dreixel Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.5
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: deriving/should_compile/T6031
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

In file A.hs:

module A where

data Empty

In file B.hs:

{-# LANGUAGE StandaloneDeriving #-}

module B where

import A

deriving instance Show Empty

GHC 7.5.20120421 reports:

    Can't make a derived instance of `Show Empty':
      The data constructors of `Empty' are not all in scope
        so you cannot derive an instance for it
    In the stand-alone deriving instance for `Show Empty'

But Empty has no constructors, and the problem does not arise if Empty is declared in B.

I guess the problem is in this part of the code of TcDeriv:

      	   ; let hidden_data_cons = not (isWiredInName (tyConName rep_tc)) &&
                                    (isAbstractTyCon rep_tc || 
                                     any not_in_scope (tyConDataCons rep_tc))
      	         not_in_scope dc  = null (lookupGRE_Name rdr_env (dataConName dc))
      	   ; unless (isNothing mtheta || not hidden_data_cons)
      	   	    (bale_out (derivingHiddenErr tycon))

Change History (2)

comment:1 Changed 3 years ago by simonpj@…

commit bf6f7085c62370081d4fe421202ec31c9e51bcb4

Author: Simon Peyton Jones <[email protected]>
Date:   Sun Apr 22 16:24:07 2012 +0100

    Empty data types should not be "trimmed" by TidyPgm
    
    That in turn means that you can derive Show etc in other modules,
    fixing Trac #6031

 compiler/main/TidyPgm.lhs |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

comment:2 Changed 3 years ago by simonpj

  • difficulty set to Unknown
  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to deriving/should_compile/T6031

Thanks for pointing this out. Fixed.

Note: See TracTickets for help on using tickets.