Skip to content

TH gives "Illegal binding of built-in syntax" error

If you try to splice in a definition that borrows an already existing Name using Template Haskell, GHC gives a confusing error message:

{-# LANGUAGE TemplateHaskell #-}
module Bug where

import Language.Haskell.TH

$(pure [ValD (VarP 'succ) (NormalB (ConE 'True)) []])
$ /opt/ghc/8.2.1/bin/runghc Bug.hs

Bug.hs:6:3: error: Illegal binding of built-in syntax: succ
  |
6 | $(pure [ValD (VarP 'succ) (NormalB (ConE 'True)) []])
  |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm not exactly sure what should happen here. My hunch was that my spliced-in succ would shadow the succ that's already in-scope. But in any case, the error message you get currently is quite awful, so at the very least that should be improved.

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