Skip to content

Don't ignore addTopDecls in module finalizers

The following program fails to compile because f is not found.

-- main.hs
import M

main = print (f 0)
-- M.hs
{-# LANGUAGE TemplateHaskell #-}
module M where

import Language.Haskell.TH.Syntax

g :: IO ()
g = $(do addModFinalizer (do d <- [d| f x = (2 :: Int) |]; addTopDecls d)
         [| return ()|]
     )
$ runghc main.hs

main.hs:3:15: Not in scope: ‘f’

This bug is problematic to produce top-level declarations which depend on the output of reify for local variables, which can only run in a finalizer.

Edited by Facundo Domínguez
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information