Skip to content

Data family instances aren't eta-reduced correctly

(I originally discovered this when debugging #17296 (closed)/!1877 (closed), but this doesn't rely on !1877 (closed) to reproduce.)

Take this code:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Bug where

import Data.Kind
import Language.Haskell.TH hiding (Type)
import System.IO

data family Foo a
data instance Foo :: Type -> Type where
  MkFoo :: Foo a

$(do i <- reify ''Foo
     runIO $ hPutStrLn stderr $ pprint i
     pure [])

And compile it with a devel2-flavoured compiler. (I'm on commit d0924b15.) You'll get the following panic:

$ ~/Software/ghc3/inplace/bin/ghc-stage2 Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o, Bug.dyn_o )

Bug.hs:1:1: error:
    Exception when trying to run compile-time code:
      ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.9.0.20191003:
        zipEqual: unequal lists:zipTyEnv

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

    Code: do i <- reify ''Foo
             runIO $ hPutStrLn stderr $ pprint i
             pure []
  |
1 | {-# LANGUAGE GADTs #-}
  | ^
Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information