Skip to content

TemplateHaskell and Data.Typeable - tcIfaceGlobal (local): not found

The following code produces an ghc panic error:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}

module TH where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Data.Typeable


usingType :: forall a. Typeable a => a -> Q [Dec]
usingType _ = do
    -- Try to get anything using typeRep.
    let name = (tyConName $ typeRepTyCon $ typeRep (Proxy :: Proxy a)) `seq` "The name!"
    -- theF = "The name!"
    return [FunD (mkName "theF") [Clause [] (NormalB $ LitE $ StringL name )  []]]
{-# LANGUAGE TemplateHaskell #-}

module Main where
import TH 

data A = A Int

-- Changing the argument to (A 3) does not help.
$(usingType (undefined :: A))

main = putStrLn $ theF

The error:

ghc: panic! (the 'impossible' happened)
  (GHC version 8.0.1 for x86_64-unknown-linux):
	tcIfaceGlobal (local): not found:
  $tcA
  [r5m0 :-> Type constructor ‘A’, r5m3 :-> Data constructor ‘A’,
   r5m9 :-> Identifier ‘A’]
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