Commit 4356dacb authored by kanetw's avatar kanetw Committed by Austin Seipp
Browse files

Forbid annotations when Safe Haskell safe mode is enabled.

For now, this fails compliation immediately with an error. If desired, this
can be a warning that annotations in Safe Haskell are ignored.
Signed-off-by: kanetw's avatarDavid Kraeutmann <>

Reviewed By: goldfire, austin

Differential Revision:

GHC Trac Issues: #10826
parent dbb4e415
......@@ -12,6 +12,8 @@ module TcAnnotations ( tcAnnotations, annCtxt ) where
#ifdef GHCI
import {-# SOURCE #-} TcSplice ( runAnnotation )
import Module
import DynFlags
import Control.Monad ( when )
import HsSyn
......@@ -47,7 +49,14 @@ tcAnnotation (L loc ann@(HsAnnotation _ provenance expr)) = do
let target = annProvenanceToTarget mod provenance
-- Run that annotation and construct the full Annotation data structure
setSrcSpan loc $ addErrCtxt (annCtxt ann) $ runAnnotation target expr
setSrcSpan loc $ addErrCtxt (annCtxt ann) $ do
-- See #10826 -- Annotations allow one to bypass Safe Haskell.
dflags <- getDynFlags
when (safeLanguageOn dflags) $ failWithTc safeHsErr
runAnnotation target expr
safeHsErr = vcat [ ptext (sLit "Annotations are not compatible with Safe Haskell.")
, ptext (sLit "See") ]
annProvenanceToTarget :: Module -> AnnProvenance Name -> AnnTarget Name
annProvenanceToTarget _ (ValueAnnProvenance (L _ name)) = NamedTarget name
......@@ -100,6 +100,15 @@
See <xref linkend="injective-ty-fams"/> for details.
Due to a <ulink href="">
security issue
</ulink>, Safe Haskell now forbids annotations in programs marked as
......@@ -946,6 +946,12 @@
Additionally, the use of <link linkend="annotations">annotations</link>
is forbidden, as that would allow bypassing Safe Haskell restrictions.
See <ulink url="">ticket #10826</ulink>.
{-# LANGUAGE Safe #-}
module Test (hook) where
import System.IO.Unsafe
{-# ANN hook (unsafePerformIO (putStrLn "Woops.")) #-}
hook = undefined
T10826.hs:6:1: error:
Annotations are not compatible with Safe Haskell.
In the annotation:
{-# ANN hook (unsafePerformIO (putStrLn "Woops.")) #-}
......@@ -18,7 +18,7 @@ test('annfail10', req_interp, compile_fail, [''])
test('annfail11', normal, compile_fail, [''])
test('annfail12', req_interp, compile_fail, ['-v0'])
test('annfail13', normal, compile_fail, [''])
test('T10826', normal, compile_fail, [''])
Helpful things to C+P:
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