DeriveAnyClass instances may skip TypeError constraints
In the presence of TypeError, one can derive instances with DeriveAnyClass that would be rejected otherwise. A simplistic example would be:
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE UndecidableSuperClasses #-}
module T
where
import GHC.TypeLits(TypeError, ErrorMessage(..))
class TypeError ('Text "BOOM") => C a where
f :: a -> ()
f _ = ()
data T = T
deriving(C)
Of course, any attempt to use the instance leads to a type-error. However, the instance is rejected right away using a normal instance declaration or StandaloneDeriving.
While this is a toy example, it can actually happen when using Generics and default-signatures, where one would puts a TypeError in an instance head for one of the Generics constructors to give a better error message.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.2.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |