summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_fail/T9858a.hs
blob: c61b29baeeb5bc3e59e66dc3686fdd1d8ef9e0d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE Haskell2010 #-}
-- From comment:76 in #9858
-- This exploit still works in GHC 7.10.1.
-- By Shachaf Ben-Kiki, Ørjan Johansen and Nathan van Doorn

{-# LANGUAGE Safe #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ImpredicativeTypes #-}

module T9858a where

import Data.Typeable

type E = (:~:)
type PX = Proxy (((),()) => ())
type PY = Proxy (() -> () -> ())

data family F p a b

newtype instance F a b PX = ID (a -> a)
newtype instance F a b PY = UC (a -> b)

{-# NOINLINE ecast #-}
ecast :: E p q -> f p -> f q
ecast Refl = id

supercast :: F a b PX -> F a b PY
supercast = case cast e of
    Just e' -> ecast e'
  where
    e = Refl
    e :: E PX PX

uc :: a -> b
uc = case supercast (ID id) of UC f -> f