on master help sign in
Fix OverlappingInstances deprecation warning
8e1dbc7Bas van Dijk
Data/Aeson/TH.hs+11−3
@@ -1,7 +1,11 @@
1−{-# LANGUAGE CPP, FlexibleInstances, IncoherentInstances, NamedFieldPuns,
1+{-# LANGUAGE CPP, FlexibleInstances, NamedFieldPuns,
2− NoImplicitPrelude, OverlappingInstances, TemplateHaskell,
2+ NoImplicitPrelude, TemplateHaskell,
3 UndecidableInstances #-}
3 UndecidableInstances #-}
4
4
5+#if __GLASGOW_HASKELL__ < 710
6+{-# LANGUAGE OverlappingInstances #-}
7+#endif
8+
5{-|
9{-|
6Module: Data.Aeson.TH
10Module: Data.Aeson.TH
7Copyright: (c) 2011-2015 Bryan O'Sullivan
11Copyright: (c) 2011-2015 Bryan O'Sullivan
@@ -955,7 +959,11 @@ parseTypeMismatch tName conName expected actual =
955class (FromJSON a) => LookupField a where
959class (FromJSON a) => LookupField a where
956 lookupField :: String -> String -> Object -> T.Text -> Parser a
960 lookupField :: String -> String -> Object -> T.Text -> Parser a
957
961
962+instance
963+#if __GLASGOW_HASKELL__ >= 710
964+ {-# OVERLAPPABLE #-}
965+#endif
958−instance (FromJSON a) => LookupField a where
966+ (FromJSON a) => LookupField a where
959 lookupField tName rec obj key =
967 lookupField tName rec obj key =
960 case H.lookup key obj of
968 case H.lookup key obj of
961 Nothing -> unknownFieldFail tName rec (T.unpack key)
969 Nothing -> unknownFieldFail tName rec (T.unpack key)
Data/Aeson/Types/Generic.hs+35−7
@@ -1,10 +1,14 @@
1{-# LANGUAGE CPP, DefaultSignatures, EmptyDataDecls, FlexibleInstances,
1{-# LANGUAGE CPP, DefaultSignatures, EmptyDataDecls, FlexibleInstances,
2− FunctionalDependencies, KindSignatures, OverlappingInstances,
2+ FunctionalDependencies, KindSignatures,
3 ScopedTypeVariables, TypeOperators, UndecidableInstances,
3 ScopedTypeVariables, TypeOperators, UndecidableInstances,
4 ViewPatterns, NamedFieldPuns, FlexibleContexts, PatternGuards,
4 ViewPatterns, NamedFieldPuns, FlexibleContexts, PatternGuards,
5 RecordWildCards #-}
5 RecordWildCards #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
7
7
8+#if __GLASGOW_HASKELL__ < 710
9+{-# LANGUAGE OverlappingInstances #-}
10+#endif
11+
8-- |
12-- |
9-- Module: Data.Aeson.Types.Generic
13-- Module: Data.Aeson.Types.Generic
10-- Copyright: (c) 2012-2015 Bryan O'Sullivan
14-- Copyright: (c) 2012-2015 Bryan O'Sullivan
@@ -45,7 +49,11 @@ import Data.Monoid (mempty)
45--------------------------------------------------------------------------------
49--------------------------------------------------------------------------------
46-- Generic toJSON
50-- Generic toJSON
47
51
52+instance
53+#if __GLASGOW_HASKELL__ >= 710
54+ {-# OVERLAPPABLE #-}
55+#endif
48−instance (GToJSON a) => GToJSON (M1 i c a) where
56+ (GToJSON a) => GToJSON (M1 i c a) where
49 -- Meta-information, which is not handled elsewhere, is ignored:
57 -- Meta-information, which is not handled elsewhere, is ignored:
50 gToJSON opts = gToJSON opts . unM1
58 gToJSON opts = gToJSON opts . unM1
51 {-# INLINE gToJSON #-}
59 {-# INLINE gToJSON #-}
@@ -338,7 +346,11 @@ instance (Selector s, GToJSON a) => RecordTo (S1 s a) where
338 recordToEncoding = fieldToEncoding
346 recordToEncoding = fieldToEncoding
339 {-# INLINE recordToEncoding #-}
347 {-# INLINE recordToEncoding #-}
340
348
349+instance
350+#if __GLASGOW_HASKELL__ >= 710
351+ {-# OVERLAPPING #-}
352+#endif
341−instance (Selector s, ToJSON a) => RecordTo (S1 s (K1 i (Maybe a))) where
353+ (Selector s, ToJSON a) => RecordTo (S1 s (K1 i (Maybe a))) where
342 recordToPairs opts (M1 k1) | omitNothingFields opts
354 recordToPairs opts (M1 k1) | omitNothingFields opts
343 , K1 Nothing <- k1 = empty
355 , K1 Nothing <- k1 = empty
344 recordToPairs opts m1 = fieldToPair opts m1
356 recordToPairs opts m1 = fieldToPair opts m1
@@ -389,7 +401,11 @@ instance ( WriteProduct a
389 encodeProduct opts b
401 encodeProduct opts b
390 {-# INLINE encodeProduct #-}
402 {-# INLINE encodeProduct #-}
391
403
404+instance
405+#if __GLASGOW_HASKELL__ >= 710
406+ {-# OVERLAPPABLE #-}
407+#endif
392−instance (GToJSON a) => WriteProduct a where
408+ (GToJSON a) => WriteProduct a where
393 writeProduct opts mv ix _ = VM.unsafeWrite mv ix . gToJSON opts
409 writeProduct opts mv ix _ = VM.unsafeWrite mv ix . gToJSON opts
394 {-# INLINE writeProduct #-}
410 {-# INLINE writeProduct #-}
395
411
@@ -435,7 +451,11 @@ gbuilder opts = fromEncoding . gToEncoding opts
435--------------------------------------------------------------------------------
451--------------------------------------------------------------------------------
436-- Generic parseJSON
452-- Generic parseJSON
437
453
454+instance
455+#if __GLASGOW_HASKELL__ >= 710
456+ {-# OVERLAPPABLE #-}
457+#endif
438−instance (GFromJSON a) => GFromJSON (M1 i c a) where
458+ (GFromJSON a) => GFromJSON (M1 i c a) where
439 -- Meta-information, which is not handled elsewhere, is just added to the
459 -- Meta-information, which is not handled elsewhere, is just added to the
440 -- parsed value:
460 -- parsed value:
441 gParseJSON opts = fmap M1 . gParseJSON opts
461 gParseJSON opts = fmap M1 . gParseJSON opts
@@ -660,7 +680,11 @@ instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
660 label = fieldLabelModifier opts $ selName (undefined :: t s a p)
680 label = fieldLabelModifier opts $ selName (undefined :: t s a p)
661 {-# INLINE parseRecord #-}
681 {-# INLINE parseRecord #-}
662
682
683+instance
684+#if __GLASGOW_HASKELL__ >= 710
685+ {-# OVERLAPPING #-}
686+#endif
663−instance (Selector s, FromJSON a) => FromRecord (S1 s (K1 i (Maybe a))) where
687+ (Selector s, FromJSON a) => FromRecord (S1 s (K1 i (Maybe a))) where
664 parseRecord _ (Just lab) obj = (M1 . K1) . join <$> obj .:? lab
688 parseRecord _ (Just lab) obj = (M1 . K1) . join <$> obj .:? lab
665 parseRecord opts Nothing obj = (M1 . K1) . join <$> obj .:? pack label
689 parseRecord opts Nothing obj = (M1 . K1) . join <$> obj .:? pack label
666 where
690 where
@@ -729,7 +753,11 @@ class IsRecord (f :: * -> *) isRecord | f -> isRecord
729
753
730instance (IsRecord f isRecord) => IsRecord (f :*: g) isRecord
754instance (IsRecord f isRecord) => IsRecord (f :*: g) isRecord
731 where isUnary = const False
755 where isUnary = const False
756+instance
757+#if __GLASGOW_HASKELL__ >= 710
758+ {-# OVERLAPPING #-}
759+#endif
732−instance IsRecord (M1 S NoSelector f) False
760+ IsRecord (M1 S NoSelector f) False
733instance (IsRecord f isRecord) => IsRecord (M1 S c f) isRecord
761instance (IsRecord f isRecord) => IsRecord (M1 S c f) isRecord
734instance IsRecord (K1 i c) True
762instance IsRecord (K1 i c) True
735instance IsRecord U1 False
763instance IsRecord U1 False
Data/Aeson/Types/Instances.hs+22−5
@@ -1,8 +1,13 @@
1{-# LANGUAGE CPP, BangPatterns, DeriveDataTypeable, FlexibleContexts,
1{-# LANGUAGE CPP, BangPatterns, DeriveDataTypeable, FlexibleContexts,
2− FlexibleInstances, GeneralizedNewtypeDeriving, IncoherentInstances,
2+ FlexibleInstances, GeneralizedNewtypeDeriving,
3− OverlappingInstances, OverloadedStrings, UndecidableInstances,
3+ OverloadedStrings, UndecidableInstances,
4 ViewPatterns #-}
4 ViewPatterns #-}
5{-# LANGUAGE DefaultSignatures #-}
5{-# LANGUAGE DefaultSignatures #-}
6+
7+#if __GLASGOW_HASKELL__ < 710
8+{-# LANGUAGE OverlappingInstances #-}
9+#endif
10+
6{-# OPTIONS_GHC -fno-warn-orphans #-}
11{-# OPTIONS_GHC -fno-warn-orphans #-}
7
12
8-- TODO: Drop this when we remove support for Data.Attoparsec.Number
13-- TODO: Drop this when we remove support for Data.Attoparsec.Number
@@ -448,19 +453,31 @@ instance FromJSON LT.Text where
448 parseJSON = withText "Lazy Text" $ pure . LT.fromStrict
453 parseJSON = withText "Lazy Text" $ pure . LT.fromStrict
449 {-# INLINE parseJSON #-}
454 {-# INLINE parseJSON #-}
450
455
456+instance
457+#if __GLASGOW_HASKELL__ >= 710
458+ {-# OVERLAPPABLE #-}
459+#endif
451−instance (ToJSON a) => ToJSON [a] where
460+ (ToJSON a) => ToJSON [a] where
452 toJSON = Array . V.fromList . map toJSON
461 toJSON = Array . V.fromList . map toJSON
453 {-# INLINE toJSON #-}
462 {-# INLINE toJSON #-}
454
463
455 toEncoding xs = list xs
464 toEncoding xs = list xs
456 {-# INLINE toEncoding #-}
465 {-# INLINE toEncoding #-}
457
466
467+instance
468+#if __GLASGOW_HASKELL__ >= 710
469+ {-# OVERLAPPABLE #-}
470+#endif
458−instance (FromJSON a) => FromJSON [a] where
471+ (FromJSON a) => FromJSON [a] where
459 parseJSON = withArray "[a]" $ Tr.sequence .
472 parseJSON = withArray "[a]" $ Tr.sequence .
460 zipWith parseIndexedJSON [0..] . V.toList
473 zipWith parseIndexedJSON [0..] . V.toList
461 {-# INLINE parseJSON #-}
474 {-# INLINE parseJSON #-}
462
475
476+instance
477+#if __GLASGOW_HASKELL__ >= 710
478+ {-# OVERLAPPABLE #-}
479+#endif
463−instance (Foldable t, ToJSON a) => ToJSON (t a) where
480+ (Foldable t, ToJSON a) => ToJSON (t a) where
464 toJSON = toJSON . toList
481 toJSON = toJSON . toList
465 {-# INLINE toJSON #-}
482 {-# INLINE toJSON #-}
466
483
tests/UnitTests.hs+8−2
@@ -6,7 +6,7 @@ import Control.Monad (forM)
6import Data.Aeson (decode, eitherDecode, encode, genericToJSON, genericToEncoding)
6import Data.Aeson (decode, eitherDecode, encode, genericToJSON, genericToEncoding)
7import Data.Aeson.TH ( deriveJSON )
7import Data.Aeson.TH ( deriveJSON )
8import Data.Aeson.Encode (encodeToTextBuilder)
8import Data.Aeson.Encode (encodeToTextBuilder)
9−import Data.Aeson.Types (ToJSON(..), Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
9+import Data.Aeson.Types (ToJSON(..), FromJSON, Value, camelTo, camelTo2, defaultOptions, omitNothingFields)
10import Data.Char (toUpper)
10import Data.Char (toUpper)
11import Data.Time (UTCTime)
11import Data.Time (UTCTime)
12import Data.Time.Format (parseTime)
12import Data.Time.Format (parseTime)
@@ -187,5 +187,11 @@ encoderComparisonTests = do
187 ]
187 ]
188
188
189-- A regression test for: https://github.com/bos/aeson/issues/293
189-- A regression test for: https://github.com/bos/aeson/issues/293
190−data MyRecord = MyRecord {field1 :: Maybe Int, field2 :: Maybe Bool}
190+data MyRecord = MyRecord {_field1 :: Maybe Int, _field2 :: Maybe Bool}
191deriveJSON defaultOptions{omitNothingFields=True} ''MyRecord
191deriveJSON defaultOptions{omitNothingFields=True} ''MyRecord
192+
193+data MyRecord2 = MyRecord2 {_field3 :: Maybe Int, _field4 :: Maybe Bool}
194+ deriving Generic
195+
196+instance ToJSON MyRecord2
197+instance FromJSON MyRecord2