Skip to content

Template Haskell doesn't allow `newName "type"`

Using type as a name is, of course, forbidden. OTOH, type_1 is allowed as a name.

However, using GHC 7.10.1 and ghc --make T.hs on files:

-- T.hs
{-# LANGUAGE TemplateHaskell #-}
module T where
import Q
test

-- Q.hs
module Q where

import Language.Haskell.TH

test :: Q [Dec]
test = do
  t <- newName "type"
  return
    [FunD t
      [Clause
         []
         (NormalB $ LitE $ CharL 't')
         []]]

Leads to the following error:

$ ghc --make -ddump-splices T.hs
[2 of 2] Compiling T                ( T.hs, T.o )

T.hs:6:1:
    Illegal variable name: ‘type’
    When splicing a TH declaration: ident_0 type_1 = type_1

The above example works fine for GHC 7.8.4, so it's a regression.

Reference: https://github.com/yesodweb/persistent/issues/412

Trac metadata
Trac field Value
Version 7.10.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