summaryrefslogtreecommitdiff
path: root/testsuite/tests/deriving/should_fail/T7148a.hs
diff options
context:
space:
mode:
authorRichard Eisenberg <eir@cis.upenn.edu>2013-08-02 15:50:51 +0100
committerRichard Eisenberg <eir@cis.upenn.edu>2013-08-02 15:50:51 +0100
commit929155faa511569eb626d49a32264442c5caa14f (patch)
tree0197b1b0e5144206099f749c4eb8659ad05c8766 /testsuite/tests/deriving/should_fail/T7148a.hs
parent5207c0ff005e579ba634d6b1aa248c825e957014 (diff)
downloadhaskell-929155faa511569eb626d49a32264442c5caa14f.tar.gz
Add tests for roles.
Many of the files modified are just wibbles to output, because now tycons have roles attached to them, which are produced in the debugging dumps.
Diffstat (limited to 'testsuite/tests/deriving/should_fail/T7148a.hs')
-rw-r--r--testsuite/tests/deriving/should_fail/T7148a.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/testsuite/tests/deriving/should_fail/T7148a.hs b/testsuite/tests/deriving/should_fail/T7148a.hs
new file mode 100644
index 0000000000..6441058b24
--- /dev/null
+++ b/testsuite/tests/deriving/should_fail/T7148a.hs
@@ -0,0 +1,37 @@
+{-# LANGUAGE TypeFamilies, ScopedTypeVariables,
+ GeneralizedNewtypeDeriving #-}
+
+module T7148a where
+
+import Control.Monad.ST
+data Proxy a = Proxy
+type family Result a b
+
+class Convert a where
+ coerce :: Proxy b -> a -> Result a b
+
+newtype SAFE a = SAFE a
+type instance Result (SAFE a) b = a
+
+instance Convert (SAFE a) where
+ coerce _ (SAFE a) = a
+
+newtype IS_NO_LONGER a = IS_NO_LONGER a deriving Convert
+type instance Result (IS_NO_LONGER a) b = b
+
+--infered type is
+unsafeCoerce :: forall a b. a -> b
+unsafeCoerce = coerce (Proxy :: Proxy b) . IS_NO_LONGER . SAFE
+
+--use it safely
+id' :: a -> a
+id' = unsafeCoerce
+
+--segfault (with high probability)
+crash :: segfault
+crash = unsafeCoerce . tail . tail . tail . unsafeCoerce $ True
+
+
+--time for side effects
+unsafePerformIO :: IO a -> a
+unsafePerformIO x = runST $ unsafeCoerce x \ No newline at end of file