GHC panic (tyConStupidTheta) when reifying `type data` constructor
I recently tried to reify a data constructor declared with TypeData
using Template Haskell. This led me to try the following:
{-# LANGUAGE TypeData #-}
module Foo where
import Language.Haskell.TH
type data T = MkT
$(pure [])
mkT :: String
mkT = $(reify ''MkT >>= stringE . show)
This causes GHC 9.6.1-alpha1 to panic:
$ ghc-9.6.0.20230111 Foo.hs
[1 of 1] Compiling Foo ( Foo.hs, Foo.o )
Foo.hs:12:7: error: [GHC-87897]
• Exception when trying to run compile-time code:
panic! (the 'impossible' happened)
GHC version 9.6.0.20230111:
tyConStupidTheta
MkT
Call stack:
CallStack (from HasCallStack):
callStackDoc, called at compiler/GHC/Utils/Panic.hs:189:37 in ghc:GHC.Utils.Panic
pprPanic, called at compiler/GHC/Core/TyCon.hs:2649:17 in ghc:GHC.Core.TyCon
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
Code: (reify ''MkT >>= stringE . show)
• In the untyped splice: $(reify ''MkT >>= stringE . show)
|
12 | mkT = $(reify ''MkT >>= stringE . show)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Relatedly, it's rather strange to have to write this:
reify ''MkT
Since MkT
is a data constructor, I would have expected to write reify 'MkT
instead. However, that flat-out does not work:
$ ghc-9.6.0.20230111 Foo.hs
[1 of 1] Compiling Foo ( Foo.hs, Foo.o )
Foo.hs:12:15: error: [GHC-76037]
• Not in scope: data constructor ‘MkT’
• In the Template Haskell quotation 'MkT
In the untyped splice: $(reify 'MkT >>= stringE . show)
Suggested fix: Perhaps use variable ‘mkT’ (line 12)
|
12 | mkT = $(reify 'MkT >>= stringE . show)
| ^^^^