Skip to content

Commit 584135e

Browse files
committed
Accumulate DList errors
1 parent 7bcf368 commit 584135e

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Data/Aeson/AccParser.hs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module Data.Aeson.AccParser
88
, (<*>+)
99
) where
1010

11+
import Prelude ()
12+
import Prelude.Compat
13+
1114
import Data.Aeson.Types.Internal (Parser (..), runParser)
1215
import Data.List.NonEmpty (NonEmpty ((:|)))
1316
import qualified Data.List.NonEmpty as NonEmpty

Data/Aeson/Types/FromJSON.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ instance FromJSON Scientific where
14391439
instance FromJSON1 DList.DList where
14401440
liftParseJSON p _ = withArray "DList a" $
14411441
fmap DList.fromList .
1442-
Tr.sequence . zipWith (parseIndexedJSON p) [0..] . V.toList
1442+
accSequence . zipWith (parseIndexedJSON p) [0..] . V.toList
14431443
{-# INLINE liftParseJSON #-}
14441444

14451445
instance (FromJSON a) => FromJSON (DList.DList a) where

tests/UnitTests/AccErrors.hs

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Prelude ()
66
import Prelude.Compat hiding (seq)
77

88
import Data.Aeson
9+
import Data.DList (DList)
910
import Data.Aeson.Parser.Internal
1011
import Data.Aeson.Types ()
1112
import Data.Aeson.Internal
@@ -24,6 +25,7 @@ tests = testGroup "Error accumulation" [
2425
testCase "Seq" seq
2526
, testCase "Vector" vector
2627
, testCase "NonEmpty" nonEmpty
28+
, testCase "DList" dlist
2729
]
2830

2931
decoder :: FromJSON a
@@ -48,3 +50,9 @@ nonEmpty = do
4850
let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (NL.NonEmpty Int)
4951
let message i s = ([Index i], "expected Int, encountered " <> s)
5052
res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])
53+
54+
dlist :: Assertion
55+
dlist = do
56+
let res = decoder "[true, null]" :: Either (NonEmpty (JSONPath, String)) (DList Int)
57+
let message i s = ([Index i], "expected Int, encountered " <> s)
58+
res @=? Left (NL.fromList [message 0 "Boolean", message 1 "Null"])

0 commit comments

Comments
 (0)