Erroneous "The exact Name ‘foo’ is not in scope" error in Template Haskell
Summary
When reifying in the example below
{-# LANGUAGE TemplateHaskell #-}
module TH_reifyNewName where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
do
n <- newName "x"
addModFinalizer $ reify n >>= runIO . print
[d| $(varP n) = 42 |]
GHC spits out two errors
The exact Name ‘x_aFi’ is not in scope
Probable cause: you used a unique Template Haskell name (NameU),
perhaps via newName, but did not bind it
If that's it, then -ddump-splices might be useful
and
‘x’ is not in the type environment at a reify
As noted in #12249, the first error message is bogus – the name x
actually is in scope. This is ultimately caused by lookupGlobalOccRn_maybe
adding an error, when it looks like it shouldn't be (a comment above it claims that it should never fail)
Expected behavior
We would expect just to have the one error here about x
not being in the type environment.
Environment
- GHC version used: ghc-HEAD