Commit 0f79b0ef authored by Michael Sloan's avatar Michael Sloan Committed by Ben Gamari

Fix handling of unbound constructor names in TH #14627

Also adds a comment to UnboundVarE clarifying that it also is used for
unbound constructor identifiers, since that isn't very clear from the
name.

Test Plan: testsuite/tests/th/T14627.hs

Reviewers: goldfire, bgamari

Reviewed By: goldfire

Subscribers: rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D4923
parent 234093cf
......@@ -913,7 +913,11 @@ cvtl e = wrapL (cvt e)
flds
; return $ mkRdrRecordUpd e' flds' }
cvt (StaticE e) = fmap (HsStatic noExt) $ cvtl e
cvt (UnboundVarE s) = do { s' <- vName s; return $ HsVar noExt (noLoc s') }
cvt (UnboundVarE s) = do -- Use of 'vcName' here instead of 'vName' is
-- important, because UnboundVarE may contain
-- constructor names - see #14627.
{ s' <- vcName s
; return $ HsVar noExt (noLoc s') }
cvt (LabelE s) = do { return $ HsOverLabel noExt Nothing (fsLit s) }
{- Note [Dropping constructors]
......
......@@ -1620,7 +1620,12 @@ data Exp
| RecConE Name [FieldExp] -- ^ @{ T { x = y, z = w } }@
| RecUpdE Exp [FieldExp] -- ^ @{ (f x) { z = w } }@
| StaticE Exp -- ^ @{ static e }@
| UnboundVarE Name -- ^ @{ _x }@ (hole)
| UnboundVarE Name -- ^ @{ _x }@
--
-- This is used for holes or unresolved
-- identifiers in AST quotes. Note that
-- it could either have a variable name
-- or constructor name.
| LabelE String -- ^ @{ #x }@ ( Overloaded label )
deriving( Show, Eq, Ord, Data, Generic )
......
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH.Syntax
[d| f = Bool |] >>= addTopDecls >> return []
main = return ()
T14627.hs:4:1: error: Data constructor not in scope: Bool
......@@ -422,3 +422,4 @@ test('T15331', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
test('T9693', expect_broken(9693), ghci_script, ['T9693.script'])
test('T14471', normal, compile, [''])
test('TH_rebindableAdo', normal, compile, [''])
test('T14627', normal, compile_fail, [''])
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