on master help sign in
Less noisy OVERLAPPABLE pragma's using some CPP
e2b038dBas van Dijk
Data/Aeson/TH.hs+2−8
@@ -2,9 +2,7 @@
2 NoImplicitPrelude, TemplateHaskell,
2 NoImplicitPrelude, TemplateHaskell,
3 UndecidableInstances #-}
3 UndecidableInstances #-}
4
4
5−#if __GLASGOW_HASKELL__ < 710
5+#include "overlapping-compat.h"
6−{-# LANGUAGE OverlappingInstances #-}
7−#endif
8
6
9{-|
7{-|
10Module: Data.Aeson.TH
8Module: Data.Aeson.TH
@@ -955,11 +953,7 @@ parseTypeMismatch tName conName expected actual =
955class (FromJSON a) => LookupField a where
953class (FromJSON a) => LookupField a where
956 lookupField :: String -> String -> Object -> T.Text -> Parser a
954 lookupField :: String -> String -> Object -> T.Text -> Parser a
957
955
958−instance
959−#if __GLASGOW_HASKELL__ >= 710
960− {-# OVERLAPPABLE #-}
961−#endif
962− (FromJSON a) => LookupField a where
956+instance OVERLAPPABLE_ (FromJSON a) => LookupField a where
963 lookupField tName rec obj key =
957 lookupField tName rec obj key =
964 case H.lookup key obj of
958 case H.lookup key obj of
965 Nothing -> unknownFieldFail tName rec (T.unpack key)
959 Nothing -> unknownFieldFail tName rec (T.unpack key)
Data/Aeson/Types/Generic.hs+9−33
@@ -5,9 +5,7 @@
5 RecordWildCards #-}
5 RecordWildCards #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
6{-# OPTIONS_GHC -fno-warn-orphans #-}
7
7
8−#if __GLASGOW_HASKELL__ < 710
8+#include "overlapping-compat.h"
9−{-# LANGUAGE OverlappingInstances #-}
10−#endif
11
9
12-- |
10-- |
13-- Module: Data.Aeson.Types.Generic
11-- Module: Data.Aeson.Types.Generic
@@ -49,11 +47,7 @@ import Data.Monoid (mempty)
49--------------------------------------------------------------------------------
47--------------------------------------------------------------------------------
50-- Generic toJSON
48-- Generic toJSON
51
49
52−instance
53−#if __GLASGOW_HASKELL__ >= 710
54− {-# OVERLAPPABLE #-}
55−#endif
56− (GToJSON a) => GToJSON (M1 i c a) where
50+instance OVERLAPPABLE_ (GToJSON a) => GToJSON (M1 i c a) where
57 -- Meta-information, which is not handled elsewhere, is ignored:
51 -- Meta-information, which is not handled elsewhere, is ignored:
58 gToJSON opts = gToJSON opts . unM1
52 gToJSON opts = gToJSON opts . unM1
59 {-# INLINE gToJSON #-}
53 {-# INLINE gToJSON #-}
@@ -346,11 +340,8 @@ instance (Selector s, GToJSON a) => RecordTo (S1 s a) where
346 recordToEncoding = fieldToEncoding
340 recordToEncoding = fieldToEncoding
347 {-# INLINE recordToEncoding #-}
341 {-# INLINE recordToEncoding #-}
348
342
349−instance
343+instance OVERLAPPING_ (Selector s, ToJSON a) =>
350−#if __GLASGOW_HASKELL__ >= 710
351− {-# OVERLAPPING #-}
352−#endif
353− (Selector s, ToJSON a) => RecordTo (S1 s (K1 i (Maybe a))) where
344+ RecordTo (S1 s (K1 i (Maybe a))) where
354 recordToPairs opts (M1 k1) | omitNothingFields opts
345 recordToPairs opts (M1 k1) | omitNothingFields opts
355 , K1 Nothing <- k1 = empty
346 , K1 Nothing <- k1 = empty
356 recordToPairs opts m1 = fieldToPair opts m1
347 recordToPairs opts m1 = fieldToPair opts m1
@@ -401,11 +392,7 @@ instance ( WriteProduct a
401 encodeProduct opts b
392 encodeProduct opts b
402 {-# INLINE encodeProduct #-}
393 {-# INLINE encodeProduct #-}
403
394
404−instance
405−#if __GLASGOW_HASKELL__ >= 710
406− {-# OVERLAPPABLE #-}
407−#endif
408− (GToJSON a) => WriteProduct a where
395+instance OVERLAPPABLE_ (GToJSON a) => WriteProduct a where
409 writeProduct opts mv ix _ = VM.unsafeWrite mv ix . gToJSON opts
396 writeProduct opts mv ix _ = VM.unsafeWrite mv ix . gToJSON opts
410 {-# INLINE writeProduct #-}
397 {-# INLINE writeProduct #-}
411
398
@@ -451,11 +438,7 @@ gbuilder opts = fromEncoding . gToEncoding opts
451--------------------------------------------------------------------------------
438--------------------------------------------------------------------------------
452-- Generic parseJSON
439-- Generic parseJSON
453
440
454−instance
455−#if __GLASGOW_HASKELL__ >= 710
456− {-# OVERLAPPABLE #-}
457−#endif
458− (GFromJSON a) => GFromJSON (M1 i c a) where
441+instance OVERLAPPABLE_ (GFromJSON a) => GFromJSON (M1 i c a) where
459 -- Meta-information, which is not handled elsewhere, is just added to the
442 -- Meta-information, which is not handled elsewhere, is just added to the
460 -- parsed value:
443 -- parsed value:
461 gParseJSON opts = fmap M1 . gParseJSON opts
444 gParseJSON opts = fmap M1 . gParseJSON opts
@@ -680,11 +663,8 @@ instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
680 label = fieldLabelModifier opts $ selName (undefined :: t s a p)
663 label = fieldLabelModifier opts $ selName (undefined :: t s a p)
681 {-# INLINE parseRecord #-}
664 {-# INLINE parseRecord #-}
682
665
683−instance
666+instance OVERLAPPING_ (Selector s, FromJSON a) =>
684−#if __GLASGOW_HASKELL__ >= 710
685− {-# OVERLAPPING #-}
686−#endif
687− (Selector s, FromJSON a) => FromRecord (S1 s (K1 i (Maybe a))) where
667+ FromRecord (S1 s (K1 i (Maybe a))) where
688 parseRecord _ (Just lab) obj = (M1 . K1) . join <$> obj .:? lab
668 parseRecord _ (Just lab) obj = (M1 . K1) . join <$> obj .:? lab
689 parseRecord opts Nothing obj = (M1 . K1) . join <$> obj .:? pack label
669 parseRecord opts Nothing obj = (M1 . K1) . join <$> obj .:? pack label
690 where
670 where
@@ -753,11 +733,7 @@ class IsRecord (f :: * -> *) isRecord | f -> isRecord
753
733
754instance (IsRecord f isRecord) => IsRecord (f :*: g) isRecord
734instance (IsRecord f isRecord) => IsRecord (f :*: g) isRecord
755 where isUnary = const False
735 where isUnary = const False
756−instance
757−#if __GLASGOW_HASKELL__ >= 710
758− {-# OVERLAPPING #-}
759−#endif
760− IsRecord (M1 S NoSelector f) False
736+instance OVERLAPPING_ IsRecord (M1 S NoSelector f) False
761instance (IsRecord f isRecord) => IsRecord (M1 S c f) isRecord
737instance (IsRecord f isRecord) => IsRecord (M1 S c f) isRecord
762instance IsRecord (K1 i c) True
738instance IsRecord (K1 i c) True
763instance IsRecord U1 False
739instance IsRecord U1 False
Data/Aeson/Types/Instances.hs+4−18
@@ -4,9 +4,7 @@
4 ViewPatterns #-}
4 ViewPatterns #-}
5{-# LANGUAGE DefaultSignatures #-}
5{-# LANGUAGE DefaultSignatures #-}
6
6
7−#if __GLASGOW_HASKELL__ < 710
7+#include "overlapping-compat.h"
8−{-# LANGUAGE OverlappingInstances #-}
9−#endif
10
8
11{-# OPTIONS_GHC -fno-warn-orphans #-}
9{-# OPTIONS_GHC -fno-warn-orphans #-}
12
10
@@ -453,31 +451,19 @@ instance FromJSON LT.Text where
453 parseJSON = withText "Lazy Text" $ pure . LT.fromStrict
451 parseJSON = withText "Lazy Text" $ pure . LT.fromStrict
454 {-# INLINE parseJSON #-}
452 {-# INLINE parseJSON #-}
455
453
456−instance
457−#if __GLASGOW_HASKELL__ >= 710
458− {-# OVERLAPPABLE #-}
459−#endif
460− (ToJSON a) => ToJSON [a] where
454+instance OVERLAPPABLE_ (ToJSON a) => ToJSON [a] where
461 toJSON = Array . V.fromList . map toJSON
455 toJSON = Array . V.fromList . map toJSON
462 {-# INLINE toJSON #-}
456 {-# INLINE toJSON #-}
463
457
464 toEncoding xs = list xs
458 toEncoding xs = list xs
465 {-# INLINE toEncoding #-}
459 {-# INLINE toEncoding #-}
466
460
467−instance
468−#if __GLASGOW_HASKELL__ >= 710
469− {-# OVERLAPPABLE #-}
470−#endif
471− (FromJSON a) => FromJSON [a] where
461+instance OVERLAPPABLE_ (FromJSON a) => FromJSON [a] where
472 parseJSON = withArray "[a]" $ Tr.sequence .
462 parseJSON = withArray "[a]" $ Tr.sequence .
473 zipWith parseIndexedJSON [0..] . V.toList
463 zipWith parseIndexedJSON [0..] . V.toList
474 {-# INLINE parseJSON #-}
464 {-# INLINE parseJSON #-}
475
465
476−instance
477−#if __GLASGOW_HASKELL__ >= 710
478− {-# OVERLAPPABLE #-}
479−#endif
480− (Foldable t, ToJSON a) => ToJSON (t a) where
466+instance OVERLAPPABLE_ (Foldable t, ToJSON a) => ToJSON (t a) where
481 toJSON = toJSON . toList
467 toJSON = toJSON . toList
482 {-# INLINE toJSON #-}
468 {-# INLINE toJSON #-}
483
469
aeson.cabal+2
@@ -112,6 +112,8 @@ library
112
112
113 ghc-options: -O2 -Wall
113 ghc-options: -O2 -Wall
114
114
115+ include-dirs: include
116+
115test-suite tests
117test-suite tests
116 type: exitcode-stdio-1.0
118 type: exitcode-stdio-1.0
117 hs-source-dirs: tests
119 hs-source-dirs: tests
include/overlapping-compat.hnew file+8
@@ -0,0 +1,8 @@
1+#if __GLASGOW_HASKELL__ >= 710
2+#define OVERLAPPABLE_ {-# OVERLAPPABLE #-}
3+#define OVERLAPPING_ {-# OVERLAPPING #-}
4+#else
5+{-# LANGUAGE OverlappingInstances #-}
6+#define OVERLAPPABLE_
7+#define OVERLAPPING_
8+#endif