on master help sign in
Merge pull request #663 from wyager/master
7faaa74Adam Bergmark
Data/Aeson/Types/FromJSON.hs+9−1
@@ -107,6 +107,7 @@ import Data.Time.Locale.Compat (defaultTimeLocale)
107import Data.Traversable as Tr (sequence)
107import Data.Traversable as Tr (sequence)
108import Data.Vector (Vector)
108import Data.Vector (Vector)
109import Data.Version (Version, parseVersion)
109import Data.Version (Version, parseVersion)
110+import Data.Void (Void)
110import Data.Word (Word16, Word32, Word64, Word8)
111import Data.Word (Word16, Word32, Word64, Word8)
111import Foreign.Storable (Storable)
112import Foreign.Storable (Storable)
112import Foreign.C.Types (CTime (..))
113import Foreign.C.Types (CTime (..))
@@ -786,6 +787,11 @@ pmval .!= val = fromMaybe val <$> pmval
786-- Generic parseJSON
787-- Generic parseJSON
787-------------------------------------------------------------------------------
788-------------------------------------------------------------------------------
788
789
790+instance GFromJSON arity V1 where
791+ -- Whereof we cannot format, thereof we cannot parse:
792+ gParseJSON _ _ _ = fail "Attempted to parse empty type"
793+
794+
789instance OVERLAPPABLE_ (GFromJSON arity a) => GFromJSON arity (M1 i c a) where
795instance OVERLAPPABLE_ (GFromJSON arity a) => GFromJSON arity (M1 i c a) where
790 -- Meta-information, which is not handled elsewhere, is just added to the
796 -- Meta-information, which is not handled elsewhere, is just added to the
791 -- parsed value:
797 -- parsed value:
@@ -1198,7 +1204,9 @@ instance (FromJSON a, FromJSON b) => FromJSON (Either a b) where
1198 parseJSON = parseJSON2
1204 parseJSON = parseJSON2
1199 {-# INLINE parseJSON #-}
1205 {-# INLINE parseJSON #-}
1200
1206
1201−
1207+instance FromJSON Void where
1208+ parseJSON _ = fail "Cannot parse Void"
1209+ {-# INLINE parseJSON #-}
1202
1210
1203instance FromJSON Bool where
1211instance FromJSON Bool where
1204 parseJSON = withBool "Bool" pure
1212 parseJSON = withBool "Bool" pure
Data/Aeson/Types/ToJSON.hs+14
@@ -91,6 +91,7 @@ import Data.Time.Format (FormatTime, formatTime)
91import Data.Time.Locale.Compat (defaultTimeLocale)
91import Data.Time.Locale.Compat (defaultTimeLocale)
92import Data.Vector (Vector)
92import Data.Vector (Vector)
93import Data.Version (Version, showVersion)
93import Data.Version (Version, showVersion)
94+import Data.Void (Void, absurd)
94import Data.Word (Word16, Word32, Word64, Word8)
95import Data.Word (Word16, Word32, Word64, Word8)
95import Foreign.Storable (Storable)
96import Foreign.Storable (Storable)
96import Foreign.C.Types (CTime (..))
97import Foreign.C.Types (CTime (..))
@@ -702,6 +703,12 @@ instance ( AllNullary (a :+: b) allNullary
702-- possible but makes error messages a bit harder to understand for missing
703-- possible but makes error messages a bit harder to understand for missing
703-- instances.
704-- instances.
704
705
706+instance GToJSON Value arity V1 where
707+ -- Empty values do not exist, which makes the job of formatting them
708+ -- rather easy:
709+ gToJSON _ _ x = x `seq` error "case: V1"
710+ {-# INLINE gToJSON #-}
711+
705instance ToJSON a => GToJSON Value arity (K1 i a) where
712instance ToJSON a => GToJSON Value arity (K1 i a) where
706 -- Constant values are encoded using their ToJSON instance:
713 -- Constant values are encoded using their ToJSON instance:
707 gToJSON _opts _ = toJSON . unK1
714 gToJSON _opts _ = toJSON . unK1
@@ -1221,6 +1228,13 @@ instance (ToJSON a, ToJSON b) => ToJSON (Either a b) where
1221 toEncoding = toEncoding2
1228 toEncoding = toEncoding2
1222 {-# INLINE toEncoding #-}
1229 {-# INLINE toEncoding #-}
1223
1230
1231+instance ToJSON Void where
1232+ toJSON = absurd
1233+ {-# INLINE toJSON #-}
1234+
1235+ toEncoding = absurd
1236+ {-# INLINE toEncoding #-}
1237+
1224
1238
1225instance ToJSON Bool where
1239instance ToJSON Bool where
1226 toJSON = Bool
1240 toJSON = Bool
aeson.cabal+4−2
@@ -135,7 +135,8 @@ library
135
135
136 if !impl(ghc >= 7.10)
136 if !impl(ghc >= 7.10)
137 -- `Numeric.Natural` is available in base only since GHC 7.10 / base 4.8
137 -- `Numeric.Natural` is available in base only since GHC 7.10 / base 4.8
138− build-depends: nats >= 1 && < 1.2
138+ build-depends: nats >= 1 && < 1.2,
139+ void >= 0.7.2 && < 0.8
139
140
140 ghc-options: -Wall
141 ghc-options: -Wall
141
142
@@ -227,7 +228,8 @@ test-suite tests
227 transformers-compat >= 0.3
228 transformers-compat >= 0.3
228
229
229 if !impl(ghc >= 7.10)
230 if !impl(ghc >= 7.10)
230− build-depends: nats >=1 && <1.2
231+ build-depends: nats >=1 && <1.2,
232+ void >=0.7.2 && <0.8
231
233
232 if impl(ghc >= 7.8)
234 if impl(ghc >= 7.8)
233 build-depends: hashable-time >= 0.2 && <0.3
235 build-depends: hashable-time >= 0.2 && <0.3