ConstrainedClassMethods makes GeneralizedNewtypeDeriving fail
Example:
{-# language GeneralizedNewtypeDeriving #-}
{-# language ConstrainedClassMethods #-}
instance ToDoc Int where toDoc = undefined
newtype P = P Int deriving ( ToDoc )
type Doc = ()
class ToDoc a where
toDoc :: ToDoc a => a -> Doc
compile with ghc-8.0.2:
C.hs:6:30: error:
• Couldn't match type ‘Int’ with ‘P’
arising from the coercion of the method ‘toDoc’
from type ‘ToDoc Int => Int -> Doc’ to type ‘ToDoc P => P -> Doc’
• When deriving the instance for (ToDoc P)
With ghc-8.0.1, it is fine.
When I drop the constraint on the method declaration, ghc-8.0.2 compiles the program.
This repetition of the class constraint in the method declaration actually came from a copy-paste error, so this issue does not affect my code, but it's still puzzling. Repeating the class constraint should not change the meaning of the program?
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |