ghc: panic! occurred with use of isInstance, newName and a type splice
Compiling the below code:
{-# LANGUAGE TemplateHaskell #-}
module Test where
import Language.Haskell.TH
import Control.Monad.Instances ()
instanceVar = $(do
xName <- newName "x"
instanceType <- [t| (Int -> $(varT xName)) |]
instanceOfFunctor <- isInstance ''Functor [instanceType]
stringE $ show instanceOfFunctor
)
Results in the following error:
[1 of 1] Compiling Test ( test.hs, interpreted )
test.hs:6:17:
Exception when trying to run compile-time code:
ghc: panic! (the 'impossible' happened)
(GHC version 7.4.1 for x86_64-apple-darwin):
nameModule x_a1ws{tv}
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
Code: do { xName <- newName "x";
instanceType <- [t| Int -> $(varT xName) |]
pending [(splice, varT xName)];
instanceOfFunctor <- isInstance ''Functor [instanceType];
.... }
In the expression:
$(do { xName <- newName "x";
instanceType <- [t| Int -> $(varT xName) |];
instanceOfFunctor <- isInstance ''Functor [instanceType];
.... })
In an equation for `instanceVar':
instanceVar
= $(do { xName <- newName "x";
instanceType <- [t| Int -> $(varT xName) |];
.... })
Failed, modules loaded: none.
While the code is not correct (replacing the instanceType
line with
instanceType <- [t| (->) Int |]
fixes the problem), a better error message would be desirable.
Trac metadata
Trac field | Value |
---|---|
Version | 7.4.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Template Haskell |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |