Skip to content

Template Haskell record splices are not renamer-resolved correctly.

While working on ticket #8761 (closed), I noticed that splicing in record selectors with Template Haskell seems to cause renamer issues in GHC HEAD.

Consider the following TH splice:

{- Test splicing in a data type with records -}
[d|
 data D a = MkD { unD :: a }

 someD = MkD "Hello"
 getD  = unD someD      -- unD should resolve to the record selector above!
 |]

getD' = unD someD       -- dito here outside of the splice!

While GHC 7.10.3 accepts this splice and renames it correctly, GHC HEAD fails with the following error message (with -ddump-splices enabled):

[1 of 1] Compiling Error            ( Error.hs, Error.o )
Error.hs:(6,1)-(11,3): Splicing declarations
    [d| someD_apF = MkD_apD "Hello"
        getD_apG = unD someD_apF
        
        data D_apC a_apH = MkD_apD {unD :: a_apH} |]
  ======>
    data D_a4SA a_a4SD = MkD_a4SB {unD_a4SC :: a_a4SD}
    someD_a4Sy = MkD_a4SB "Hello"
    getD_a4Sz = unD_a4SC someD_a4Sy

Error.hs:6:1: error:
    The exact Name ‘unD_a4SC’ is not in scope
      Probable cause: you used a unique Template Haskell name (NameU), 
      perhaps via newName, but did not bind it
      If that's it, then -ddump-splices might be useful

I'm not sure as to what introduced this bug, but investigating it I found that the notes

  • NOTE [Binders in Template Haskell] in Convert.hs, and
  • NOTE [Looking up Exact RdrNames] in RnEnv.hs

are not respected by function newRecordSelector in rename/RnNames.hs. I've fixed this function accordingly in D1940 for #8761 (closed), but since that patch is not going to be part of 8.0.1, Richard suggested to fix it separately in this ticket.

I'm submitting a patch in due course.

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
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information