Skip to content

Commit 794ede2

Browse files
committed
Deserialize all TypeRep arrow representations
Previously, `TypeRep (a -> b)` could only be deserialized if `a` and `b` both had kind `*`. Change that to allow any kinds of the form `TYPE rep`. Fixes #27
1 parent 6da9858 commit 794ede2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/Data/Binary/Class.hs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
{-# LANGUAGE PolyKinds #-}
1010
#endif
1111

12+
#if MIN_VERSION_base(4,10,0)
13+
{-# LANGUAGE MultiWayIf #-}
14+
#endif
15+
1216
#if MIN_VERSION_base(4,8,0)
1317
#define HAS_NATURAL
1418
#define HAS_VOID
@@ -77,7 +81,7 @@ import Data.List (unfoldr, foldl')
7781
import Type.Reflection
7882
import Type.Reflection.Unsafe
7983
import Data.Kind (Type)
80-
import GHC.Exts (RuntimeRep(..), VecCount, VecElem)
84+
import GHC.Exts (TYPE, RuntimeRep(..), VecCount, VecElem)
8185
#endif
8286
import qualified Data.ByteString as B
8387
#if MIN_VERSION_bytestring(0,10,4)
@@ -981,14 +985,18 @@ getSomeTypeRep = do
981985
]
982986
3 -> do SomeTypeRep arg <- getSomeTypeRep
983987
SomeTypeRep res <- getSomeTypeRep
984-
case typeRepKind arg `eqTypeRep` (typeRep :: TypeRep Type) of
985-
Just HRefl ->
986-
case typeRepKind res `eqTypeRep` (typeRep :: TypeRep Type) of
987-
Just HRefl -> return $ SomeTypeRep $ Fun arg res
988-
Nothing -> failure "Kind mismatch" []
989-
Nothing -> failure "Kind mismatch" []
988+
if
989+
| App argkcon _ <- typeRepKind arg
990+
, App reskcon _ <- typeRepKind res
991+
, Just HRefl <- argkcon `eqTypeRep` tYPErep
992+
, Just HRefl <- reskcon `eqTypeRep` tYPErep
993+
-> return $ SomeTypeRep $ Fun arg res
994+
| otherwise -> failure "Kind mismatch" []
990995
_ -> failure "Invalid SomeTypeRep" []
991996
where
997+
tYPErep :: TypeRep TYPE
998+
tYPErep = typeRep
999+
9921000
failure description info =
9931001
fail $ unlines $ [ "GHCi.TH.Binary.getSomeTypeRep: "++description ]
9941002
++ map (" "++) info

0 commit comments

Comments
 (0)