Skip to content

TH + out-of-scope variable panic

This silly program, which splices an out-of-scope variable, causes a panic:

{-# OPTIONS_GHC -fdefer-out-of-scope-variables #-}
{-# LANGUAGE TemplateHaskell #-}
module X where

import Language.Haskell.TH

a :: Code Q Int
a = [|| outOfScope ||]
{-# LANGUAGE TemplateHaskell #-}
module Y where

import X

b = $$(a)
<no location info>: error:
    panic! (the 'impossible' happened)
  GHC version 9.5.20221216:
	unfilled unbound-variable evidence
  a241
  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/Tc/Utils/TcMType.hs:307:27 in ghc:GHC.Tc.Utils.TcMType
  CallStack (from HasCallStack):
    panic, called at compiler/GHC/Utils/Error.hs:454:29 in ghc:GHC.Utils.Error
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information