Skip to content

Exception when DeriveFunctor fails

The following program

{-# LANGUAGE DeriveFunctor #-}

data Foo a = Foo
data Bar a = Bar [Foo a]
  deriving (Functor)

Gives the error message

foo.hs:5:13:ghc: panic! (the 'impossible' happened)
  (GHC version 7.8.1 for x86_64-unknown-linux):
	Prelude.(!!): index too large

While it should give

foo.hs:4:13:No instance for (Functor Foo)

The use of [] in [Foo a] is not essential, it can be any type constructor that is an instance of Functor. Without the extra type constructor an error is correctly reported.

The cause seems to be in the error message. If it wraps to the next line, then ghc dies with:

foo-with-a-longer-filename.hs:5:13:
    No instance for (Functorghc: panic! (the 'impossible' happened)

When using stand alone deriving ghc does not crash.

Trac metadata
Trac field Value
Version 7.8.1
Type Bug
TypeOfFailure OtherFailure
Priority low
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