Skip to content

Allow reify to find top-level bindings in later declaration groups

Some time ago, at Tweag we were considering inspecting the types of declarations added with addTopDecls like this:

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

main :: IO ()
main =
    $(do
      ds <- [d| f = True |]
      addTopDecls ds
      addModFinalizer $ do
        VarI _ t _ <- reify (mkName "f")
        runIO $ hPutStrLn stderr ("f :: " ++ show t)
      [| return () |]
     )

f is not in scope when the finalizer is added. But its type would be known when the finalizer runs.

This worked before the patch https://phabricator.haskell.org/D2286. There is a patch that we submitted to address this https://phabricator.haskell.org/D2519, but it turned out later that we didn't need it and the patch was considered less than ideal.

We are opening this ticket to keep track of the nuance in case someone finds the patch useful later.

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC mboes, simonpj
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information