Commit d774b4e2 authored by Ryan Scott's avatar Ryan Scott
Browse files

Fix #13968 by consulting isBuiltInOcc_maybe

We were unconditionally reporting `Illegal binding of built-in syntax`
in an error message, but this error doesn't make sense in certain Template
Haskell scenarios which can trigger it. Let's give a more sensible error
message by first checking if the name we're binding really is built-in syntax,
using the handy `isBuiltInOcc_maybe` function.

Test Plan: make test TEST=T13968

Reviewers: bgamari, austin, goldfire

Reviewed By: goldfire

Subscribers: goldfire, rwbarton, thomie

GHC Trac Issues: #13968

Differential Revision:
parent 362339dd
......@@ -53,7 +53,7 @@ import HscTypes
import TcEnv
import TcRnMonad
import RdrHsSyn ( setRdrNameSpace )
import TysWiredIn ( starKindTyConName, unicodeStarKindTyConName )
import TysWiredIn
import Name
import NameSet
import NameEnv
......@@ -1573,5 +1573,17 @@ opDeclErr n
badOrigBinding :: RdrName -> SDoc
badOrigBinding name
= text "Illegal binding of built-in syntax:" <+> ppr (rdrNameOcc name)
-- The rdrNameOcc is because we don't want to print Prelude.(,)
| Just _ <- isBuiltInOcc_maybe occ
= text "Illegal binding of built-in syntax:" <+> ppr occ
-- Use an OccName here because we don't want to print Prelude.(,)
| otherwise
= text "Cannot redefine a Name retrieved by a Template Haskell quote:"
<+> ppr name
-- This can happen when one tries to use a Template Haskell splice to
-- define a top-level identifier with an already existing name, e.g.,
-- $(pure [ValD (VarP 'succ) (NormalB (ConE 'True)) []])
-- (See Trac #13968.)
occ = rdrNameOcc name
{-# LANGUAGE TemplateHaskell #-}
module T13968 where
import Language.Haskell.TH
$(pure [ValD (VarP 'succ) (NormalB (ConE 'True)) []])
T13968.hs:6:3: error:
Cannot redefine a Name retrieved by a Template Haskell quote: succ
......@@ -390,3 +390,4 @@ test('T13642', normal, compile_fail, ['-v0'])
test('T13781', normal, compile, ['-v0'])
test('T13782', normal, compile, [''])
test('T13856', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
test('T13968', normal, compile_fail, ['-v0'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment