summaryrefslogtreecommitdiff
path: root/compiler/parser
diff options
context:
space:
mode:
authorJan Stolarek <jan.stolarek@p.lodz.pl>2015-10-20 14:09:13 +0200
committerJan Stolarek <jan.stolarek@p.lodz.pl>2015-10-20 20:27:27 +0200
commit1750ebc2e40bab85246717326d3d5c60f132e652 (patch)
treefc7317ebcff4e667f38340b4dd5be58579e0226b /compiler/parser
parentae4acbd1ba4168b867a1b5fe8de50c0199dfc1f4 (diff)
downloadhaskell-1750ebc2e40bab85246717326d3d5c60f132e652.tar.gz
Reject top-level typed TH splices. Fixes #10945
When TemplateHaskell language extension is enabled it is valid to have top-level expressions. Each such expression is treated as a contents of a splice. The problem arises with typed splices. They are not valid at the top level and therefore we should interpret them not as a splice but as a top-level expression (aka. implicit splice). So saying: $$foo is equivalent of: $( $$foo ) This patch makes sure that this is indeed the case. Until now we incorrectly treated typed splices as explicit splices.
Diffstat (limited to 'compiler/parser')
-rw-r--r--compiler/parser/RdrHsSyn.hs15
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/parser/RdrHsSyn.hs b/compiler/parser/RdrHsSyn.hs
index 8bc4f6c076..e64a57519d 100644
--- a/compiler/parser/RdrHsSyn.hs
+++ b/compiler/parser/RdrHsSyn.hs
@@ -263,11 +263,18 @@ mkSpliceDecl :: LHsExpr RdrName -> HsDecl RdrName
-- but if she wrote, say,
-- f x then behave as if she'd written $(f x)
-- ie a SpliceD
+--
+-- Typed splices are not allowed at the top level, thus we do not represent them
+-- as spliced declaration. See #10945
mkSpliceDecl lexpr@(L loc expr)
- | HsSpliceE splice <- expr = SpliceD (SpliceDecl (L loc splice) ExplicitSplice)
- | otherwise = SpliceD (SpliceDecl (L loc splice) ImplicitSplice)
- where
- splice = mkUntypedSplice lexpr
+ | HsSpliceE splice@(HsUntypedSplice {}) <- expr
+ = SpliceD (SpliceDecl (L loc splice) ExplicitSplice)
+
+ | HsSpliceE splice@(HsQuasiQuote {}) <- expr
+ = SpliceD (SpliceDecl (L loc splice) ExplicitSplice)
+
+ | otherwise
+ = SpliceD (SpliceDecl (L loc (mkUntypedSplice lexpr)) ImplicitSplice)
mkRoleAnnotDecl :: SrcSpan
-> Located RdrName -- type being annotated