GeneralizedNewtypeDeriving should support classes with ambiguous types
The following module has a class with an ambiguous type:
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Ambig where
class C a where
c :: Int
data A = A
instance C A where c = 5
newtype B = B A deriving C
Thanks to TypeApplications, this typeclass is still usable. However, GeneralizedNewtypeDeriving fails on it:
Ambig.hs:12:26: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘c’
prevents the constraint ‘(C a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance C A -- Defined at Ambig.hs:10:10
instance C B -- Defined at Ambig.hs:12:26
• In the third argument of ‘GHC.Prim.coerce’, namely ‘c’
In the expression: GHC.Prim.coerce @(Int) @(Int) c
In an equation for ‘c’: c = GHC.Prim.coerce @(Int) @(Int) c
When typechecking the code for ‘c’
in a derived instance for ‘C B’:
To see the code I am typechecking, use -ddump-deriv
|
12 | newtype B = B A deriving C
|
It shouldn't.
Trac metadata
Trac field | Value |
---|---|
Version | 8.6.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |