Skip to content

Untyped TemplateHaskell as a bedrock for macros (Was: Bug in renaming of TemplateHaskell quotes)

(Extracted from #24713 (comment 563662).) The following program

{-# LANGUAGE TemplateHaskell #-}

main = do
  print $ $(let x = 10::Int in [| let x = 1 in $[| x |] |])
  print $ $(let x = 10::Int in let q = [| x |] in [| let x = 1 in $q |])

should print 10 twice in a usable procedural macro system such as Leans, but in current TH it prints 1\n10.

That is due to a bug feature in the renamer, which converts the latter into the former, but then analyses [| x |] in the environment of its splice site $q.

This is easily fixed by introducing a TcLvlEnv field to RnPendingUntyped that carries the renaming environment before entering the outer quote.

Edited by Sebastian Graf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information