Some tidying up of type pretty-printing
[ghc.git] / testsuite / tests / typecheck / should_fail / TcCoercibleFail.hs
1 {-# LANGUAGE RoleAnnotations, RankNTypes, ScopedTypeVariables #-}
2
3 import Data.Coerce (coerce, Coercible)
4 import Data.Ord (Down)
5
6 newtype Age = Age Int deriving Show
7
8 type role Map nominal _
9 data Map a b = Map a b deriving Show
10
11 foo1 = coerce $ one :: ()
12
13 foo2 :: forall m. Monad m => m Age
14 foo2 = coerce $ (return one :: m Int)
15
16 foo3 = coerce $ Map one () :: Map Age ()
17
18 foo4 = coerce $ one :: Down Int
19
20 newtype Void = Void Void
21 foo5 = coerce :: Void -> ()
22
23
24 ------------------------------------
25 -- This next one generates an exponentally big type as it
26 -- tries to unwrap. See comment:15 in Trac #11518
27 -- Adding asserions that force the types can make us
28 -- run out of space.
29 newtype VoidBad a = VoidBad (VoidBad (a,a))
30 foo5' = coerce :: (VoidBad ()) -> ()
31
32 ------------------------------------
33 -- This shoul fail with a context stack overflow
34 newtype Fix f = Fix (f (Fix f))
35 foo6 = coerce :: Fix (Either Int) -> Fix (Either Age)
36 foo7 = coerce :: Fix (Either Int) -> ()
37
38
39 one :: Int
40 one = 1
41 main = return ()