Skip to content

Illegal variable name in quote of a record using DuplicateRecordFields

When I try to construct a record in a TH quote, and that record was declared with DuplicateRecordFields, the field name in the quote is mangled and makes the quoted expression unusable.

{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE TemplateHaskell #-}
module V where

data F = F { f :: Int }

a = $([| F { f = 3 } |])

Error message:

V.hs:7:6: error: [GHC-55017]
    • Illegal variable name: ‘$sel:f:F’
      When splicing a TH expression: V.F{(V.$sel:f:F) = 3}
    • In the untyped splice: $([| F {f = 3} |])
  |
7 | a = $([| F { f = 3 } |])
  |      ^^^^^^^^^^^^^^^^^^^

Tested with GHC 9.6 alpha1

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