Skip to content

Derived DataKinds Typeable instance collision leads to SafeHaskell violation

The derived Typeable instances for a kind (with DataKinds) is equal to the instance of a type with the same name:

λ> data T = T
λ> typeRep (Proxy :: Proxy T) == typeRep (Proxy :: Proxy 'T)
True

This can be used to violate SafeHaskell easily:

{-# LANGUAGE AutoDeriveTypeable, DataKinds, TypeFamilies, RankNTypes #-}

module Unsafe where

import Data.Typeable

data T = T

data family F p

newtype instance F (Proxy  T) = ID (forall a. a -> a)
newtype instance F (Proxy 'T) = UC (forall a b. a -> b)

uc :: a -> b
uc = case cast (ID id) of Just (UC f) -> f
$ ghc -XSafe Unsafe.hs -e "uc 'a' :: Int"
97
Trac metadata
Trac field Value
Version 7.8.4
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information