Opened 3 years ago

Closed 13 months ago

#10684 closed bug (fixed)

Error cascade when unrelated class derivation fails

Reported by: ezyang Owned by:
Priority: low Milestone: 8.4.1
Component: Compiler (Type checker) Version: 7.11
Keywords: Cc: RyanGlScott
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: deriving/should_fail/T10684
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D3771
Wiki Page:


Pretty minor bug, but I thought I'd point it out:

module A where
import Data.Typeable
data A = A deriving (Show, Typeable)
data B = B A deriving (Show)

I get two errors when I expect one:

    Can't make a derived instance of `Typeable A':
      You need -XDeriveDataTypeable to derive an instance for this class
    In the data declaration for `A'

    No instance for (Show A)
      arising from the 'deriving' clause of a data type declaration
    Possible fix:
      add an instance declaration for (Show A)
      or use a standalone 'deriving instance' declaration,
           so you can specify the instance context yourself
    When deriving the instance for (Show B)

The failed Typeable derivation also causes the Show derivation to fail, which causes an error later in the file.

Change History (5)

comment:1 Changed 22 months ago by RyanGlScott

Cc: RyanGlScott added

Since all datatypes now have Typeable derived implicitly, here's a modern version of this bug:

module A where
import GHC.Generics
data A = A deriving (Show, Generic)
data B = B A deriving (Show)

comment:2 Changed 21 months ago by simonpj

See #12801 for another example

comment:3 Changed 13 months ago by RyanGlScott

Differential Rev(s): Phab:D3771
Status: newpatch

comment:4 Changed 13 months ago by Ryan Scott <…>

In 6bb32ba/ghc:

Fix #10684 by processing deriving clauses with finer grain

Previously, one could experience error cascades with deriving clauses
when one class in a set of many failed to derive, causing the other derived
classes to be skipped entirely and resulting in other errors down the line.
The solution is to process each class in a data type's set of deriving clauses
individually, and engineer it so that failure to derive an individual class
within that set doesn't cancel out the others.

Test Plan: make test TEST="T10684 T12801"

Reviewers: austin, bgamari, simonpj

Reviewed By: simonpj

Subscribers: simonpj, rwbarton, thomie

GHC Trac Issues: #10684, #12801

Differential Revision:

comment:5 Changed 13 months ago by RyanGlScott

Milestone: 8.4.1
Resolution: fixed
Status: patchclosed
Test Case: deriving/should_fail/T10684
Note: See TracTickets for help on using tickets.