summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2008-01-16 15:16:12 +0000
committersimonpj@microsoft.com <unknown>2008-01-16 15:16:12 +0000
commitd3d2b45d5b07064f73d76b33ce571e3f10cc3f42 (patch)
tree3e92c07ec7ead03a77d7305dff436b43969a1ed5
parent47adb8b6c491df7e51fd34e6bb45dfe3d6fe681a (diff)
downloadhaskell-d3d2b45d5b07064f73d76b33ce571e3f10cc3f42.tar.gz
Complain sensibly if you try to use scoped type variables in Template Haskell
This fixes Trac #2024; worth merging onto 6.8 branch.
-rw-r--r--compiler/deSugar/DsMeta.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/deSugar/DsMeta.hs b/compiler/deSugar/DsMeta.hs
index 3317ffaa72..985916719f 100644
--- a/compiler/deSugar/DsMeta.hs
+++ b/compiler/deSugar/DsMeta.hs
@@ -424,7 +424,7 @@ repTy (HsForAllTy _ tvs ctxt ty) =
repTy (HsTyVar n)
| isTvOcc (nameOccName n) = do
- tv1 <- lookupBinder n
+ tv1 <- lookupTvOcc n
repTvar tv1
| otherwise = do
tc1 <- lookupOcc n
@@ -917,6 +917,18 @@ lookupOcc n
Just (Splice _) -> pprPanic "repE:lookupOcc" (ppr n)
}
+lookupTvOcc :: Name -> DsM (Core TH.Name)
+-- Type variables can't be staged and are not lexically scoped in TH
+lookupTvOcc n
+ = do { mb_val <- dsLookupMetaEnv n ;
+ case mb_val of
+ Just (Bound x) -> return (coreVar x)
+ other -> failWithDs msg
+ }
+ where
+ msg = vcat [ ptext SLIT("Illegal lexically-scoped type variable") <+> quotes (ppr n)
+ , ptext SLIT("Lexically scoped type variables are not supported by Template Haskell") ]
+
globalVar :: Name -> DsM (Core TH.Name)
-- Not bound by the meta-env
-- Could be top-level; or could be local