summaryrefslogtreecommitdiff
path: root/compiler/rename/RnExpr.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2017-09-13 09:37:13 -0400
committerRyan Scott <ryan.gl.scott@gmail.com>2017-09-13 09:37:13 -0400
commit9ff9c35895ecc072f289c93addd1faad884bf122 (patch)
tree30707ea1b2139ecd555f5352d85cee0bf17f0718 /compiler/rename/RnExpr.hs
parent0ebc8dc3525ddaa04a0c9e4c0c1aef70fd3fe725 (diff)
downloadhaskell-9ff9c35895ecc072f289c93addd1faad884bf122.tar.gz
Check if -XStaticPointers is enabled when renaming static expressions
Summary: Trying to use `static` expressions without the `-XStaticPointers` extension enabled can lead to runtime errors. Normally, such a situation isn't possible, but Template Haskell provides a backdoor that allows it to happen, as shown in #14204. To prevent this, we ensure that `-XStaticPointers` is enabled when renaming `static` expressions. Test Plan: make test TEST=T14204 Reviewers: facundominguez, austin, bgamari, simonpj Reviewed By: facundominguez, simonpj Subscribers: simonpj, rwbarton, thomie GHC Trac Issues: #14204 Differential Revision: https://phabricator.haskell.org/D3931
Diffstat (limited to 'compiler/rename/RnExpr.hs')
-rw-r--r--compiler/rename/RnExpr.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rename/RnExpr.hs b/compiler/rename/RnExpr.hs
index 5ccefb8467..99e3f7068a 100644
--- a/compiler/rename/RnExpr.hs
+++ b/compiler/rename/RnExpr.hs
@@ -375,6 +375,16 @@ wired-in. See the Notes about the NameSorts in Name.hs.
-}
rnExpr e@(HsStatic _ expr) = do
+ -- Normally, you wouldn't be able to construct a static expression without
+ -- first enabling -XStaticPointers in the first place, since that extension
+ -- is what makes the parser treat `static` as a keyword. But this is not a
+ -- sufficient safeguard, as one can construct static expressions by another
+ -- mechanism: Template Haskell (see #14204). To ensure that GHC is
+ -- absolutely prepared to cope with static forms, we check for
+ -- -XStaticPointers here as well.
+ unlessXOptM LangExt.StaticPointers $
+ addErr $ hang (text "Illegal static expression:" <+> ppr e)
+ 2 (text "Use StaticPointers to enable this extension")
(expr',fvExpr) <- rnLExpr expr
stage <- getStage
case stage of