Skip to content

GHC panic when using DeriveAnyClass with functor-like class and datatype with a type variable in a contravariant position

The following code

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE KindSignatures #-}
module Example where

class C (a :: * -> *)
data T a = MkT (a -> Int) deriving C

fails to compile with the following GHC panic:

$ /opt/ghc/8.0.1/bin/ghc Example.hs
[1 of 1] Compiling Example          ( Example.hs, Example.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.0.1 for x86_64-unknown-linux):
	contravariant

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

The culprit is that when DeriveAnyClass comes up with the constraints for typeclass instances whose argument is of kind * -> *, it calls deepSubtypesContaining, which immediately bails out when it sees a type variable in a contravariant or "bad" position. I'm less sure of what the fix should be.

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information