Standalone-derived anyclass instances aren't as permissive as empty instances
Note that these are accepted:
class Foo (a :: TYPE ('TupleRep '[]))
instance Foo (a :: TYPE ('TupleRep '[]))
instance Foo (##)
But if you try to write these same instances using DeriveAnyClass
and StandaloneDeriving
, they'll be rejected for no good reason:
deriving instance Foo (a :: TYPE ('TupleRep '[]))
{-
• Can't make a derived instance of ‘Foo a’:
The last argument of the instance must be a data or newtype application
-}
deriving instance Foo (##)
{-
• Can't make a derived instance of ‘Foo (# #)’:
The last argument of the instance cannot be an unboxed tuple
-}
The latter error is a vestige of #12512 (closed), and should be easy enough to rectify. The former error is a bit tricker to fix, since much of the code in TcDeriv
/TcDerivInfer
assumes that the type to which the class is applied to in the instead head is a datatype or newtype TyCon
. It's apparent that this doesn't hold true in the presence of DeriveAnyClass
, however, so that code should be refactored to reflect this.
For practical reasons, however, it might be best to wait until after #12144 (closed) is fixed to tackle this one, since that splits out some logic in TcDerivInfer
for DeriveAnyClass
so as to make it no longer rely on the aforementioned TyCon
invariant.
Trac metadata
Trac field | Value |
---|---|
Version | 8.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler (Type checker) |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |