Opened 5 years ago

Closed 5 years ago

Last modified 2 years ago

#9444 closed bug (invalid)

-ddump-deriv doesn't dump failed newtype-deriving

Reported by: goldfire Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.2
Keywords: deriving Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

When I say

{-# LANGUAGE GeneralizedNewtypeDeriving, TypeFamilies #-}
{-# OPTIONS_GHC -ddump-deriv #-}

type family F a
type instance F Int = Bool

class C a where
  meth :: a -> F a

instance C Int where
  meth = (> 0)

newtype Age = MkAge Int
  deriving C

I get an error (which I should), but I don't get the derived C instance, as requested by -ddump-deriv. The output should include this helpful information.

Change History (3)

comment:1 Changed 5 years ago by simonpj

Think about

data T = MkT Int Int Bool (Int -> Bool) deriving( Read )

You probably don't want to see the parser code generated by a derived Read instance. What you want to know is that the derived instance needs Read on each constructor argument.

T9444.hs:6:37:
    No instance for (Read (Int -> Bool))
      arising from the first field of ‘MkT’ (type ‘Int -> Int’)
    Possible fix:
      use a standalone 'deriving instance' declaration,
        so you can specify the instance context yourself
    When deriving the instance for (Read T)

It's the same for deriving C. What you need to know is that we need a Coercible (Int -> F Int) (Age -> F Age) for each method of C. (Here there is just one.) And that is what fails:

T9444.hs:16:12:
    Could not coerce from ‘Bool’ to ‘F Age’
      because ‘Bool’
          and ‘F Age’
          are different types.
      arising from the coercion of the method ‘meth’
                   from type ‘Int -> F Int’
                     to type ‘Age -> F Age’
    Possible fix:
      use a standalone 'deriving instance' declaration,
        so you can specify the instance context yourself
    When deriving the instance for (C Age)

I think it's a pretty good error message! I suppose the arising from part could say:

   arising from the derived definition of method 'meth':
     instance ... => C Age where
       meth = coerce meth

but I'm not sure that will be much better, would it?

Simon

comment:2 Changed 5 years ago by goldfire

Resolution: invalid
Status: newclosed

Never mind -- closing this ticket.

comment:3 Changed 2 years ago by RyanGlScott

Keywords: deriving added
Note: See TracTickets for help on using tickets.