Opened 3 years ago

Last modified 3 years ago

#12818 new bug

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

Reported by: facundo.dominguez Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 8.0.1
Keywords: Cc: mboes, simonpj
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #11832 Differential Rev(s): Phab:D2519
Wiki Page:

Description

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.

Change History (1)

comment:1 Changed 3 years ago by facundo.dominguez

Note: See TracTickets for help on using tickets.