Skip to content

Referencing a newName in a VarE without definition triggers "the impossible happened"

Test case:

{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH

_ = $(newName "x" >>= varE)

Result:

$ runghc test.hs 
ghc: panic! (the 'impossible' happened)
  (GHC version 7.4.1 for x86_64-unknown-linux):
	nameModule x_aSd{v}

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

Similar results from ghci:

$ ghci
GHCi, version 7.4.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :set -XTemplateHaskell
Prelude> import Language.Haskell.TH
Prelude Language.Haskell.TH> $(newName "x" >>= varE)
Loading package array-0.4.0.0 ... linking ... done.
Loading package deepseq-1.3.0.0 ... linking ... done.
Loading package containers-0.4.2.1 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
ghc: panic! (the 'impossible' happened)
  (GHC version 7.4.1 for x86_64-unknown-linux):
	nameModule x_aSm{v}

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

Note that referencing an undefined name via mkName generates a reasonable error message rather than "the impossible happened":

Prelude Language.Haskell.TH> $(varE $ mkName "x")

<interactive>:6:3:
    Not in scope: `x'
    In the result of the splice:
      $(varE $ mkName "x")
    To see what the splice expanded to, use -ddump-splices
    In the expression: $(varE $ mkName "x")
    In an equation for `it': it = $(varE $ mkName "x")
Trac metadata
Trac field Value
Version 7.4.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