Opened 4 years ago

Closed 4 years ago

#11809 closed bug (fixed)

Template Haskell record splices are not renamer-resolved correctly.

Reported by: bollmann Owned by: bollmann
Priority: normal Milestone: 8.0.1
Component: Template Haskell Version: 8.0.1
Keywords: Template Haskell Renamer Records Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2091
Wiki Page:


While working on ticket #8761, 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 -}
 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 Phab:D1940 for #8761, 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.

Change History (5)

comment:1 Changed 4 years ago by bollmann

Differential Rev(s): Phab:D2091
Status: newpatch

comment:2 Changed 4 years ago by bgamari

Status: patchmerge

comment:3 Changed 4 years ago by bgamari

Milestone: 8.0.1

comment:4 Changed 4 years ago by Ben Gamari <ben@…>

In 2f82da7/ghc:

Fix Template Haskell bug reported in #11809.

Record selectors of data types spliced in with Template Haskell are not
renamer-resolved correctly in GHC HEAD. The culprit is
`newRecordSelector` which violates notes `Note [Binders in Template
Haskell] in Convert.hs` and `Note [Looking up Exact RdrNames] in
RnEnv.hs`. This commit fixes `newRecordSelector` accordingly.

Test Plan: ./validate

Reviewers: thomie, mpickering, bgamari, austin, simonpj, goldfire

Reviewed By: goldfire

Differential Revision:

GHC Trac Issues: #11809

comment:5 Changed 4 years ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.