Opened 3 years ago

Last modified 16 months ago

#12452 new bug

TemplateHaskell - variables in top level splices and loading modules.

Reported by: mkloczko Owned by:
Priority: normal Milestone:
Component: Template Haskell Version: 8.0.1
Keywords: TemplateHaskell Cc:
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: #12451 Differential Rev(s):
Wiki Page:


The following code fails when loading Main module:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}

module TH where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Data.Typeable

usingType :: a -> Q [Dec]
usingType _ = do
    let name = "The name!"
    -- theF = "The name!"
    return [FunD (mkName "theF") [Clause [] (NormalB $ LitE $ StringL name )  []]]
{-# LANGUAGE TemplateHaskell #-}

module Main where
import TH 

data A = A Int

-- Runs with `usingType (undefined :: A)` instead
$(usingType (A 3) )

main = putStrLn $ theF

The error:

$ ghc --make Main.hs
[1 of 2] Compiling TH               ( TH.hs, TH.o )
[2 of 2] Compiling Main             ( Main.hs, Main.o )
attempting to use module ‘Main’ (Main.hs) which is not loaded

Change History (2)

comment:1 Changed 3 years ago by goldfire

Component: CompilerTemplate Haskell

comment:2 Changed 16 months ago by RyanGlScott

Note: See TracTickets for help on using tickets.