on master help sign in
Fixed bug in the TH code of parsing a 2-element-array encoded value
3dc442dBas van Dijk
Data/Aeson/TH.hs+13−2
@@ -1,5 +1,5 @@
1{-# LANGUAGE CPP, FlexibleInstances, NamedFieldPuns, NoImplicitPrelude,
1{-# LANGUAGE CPP, FlexibleInstances, NamedFieldPuns, NoImplicitPrelude,
2− OverlappingInstances, TemplateHaskell, UndecidableInstances
2+ OverlappingInstances, TemplateHaskell, UndecidableInstances, IncoherentInstances
3 #-}
3 #-}
4
4
5{-|
5{-|
@@ -496,6 +496,14 @@ consFromJSON tName opts cons = do
496 'conNotFoundFail2ElemArray
496 'conNotFoundFail2ElemArray
497 )
497 )
498 []
498 []
499+ , do other <- newName "other"
500+ match (varP other)
501+ ( normalB
502+ $ [|firstElemNoStringFail|]
503+ `appE` (litE $ stringL $ show tName)
504+ `appE` ([|valueConName|] `appE` varE other)
505+ )
506+ []
499 ]
507 ]
500 )
508 )
501
509
@@ -735,6 +743,9 @@ noArrayFail t o = fail $ printf "When parsing %s expected Array but got %s." t o
735noObjectFail :: String -> String -> Parser fail
743noObjectFail :: String -> String -> Parser fail
736noObjectFail t o = fail $ printf "When parsing %s expected Object but got %s." t o
744noObjectFail t o = fail $ printf "When parsing %s expected Object but got %s." t o
737
745
746+firstElemNoStringFail :: String -> String -> Parser fail
747+firstElemNoStringFail t o = fail $ printf "When parsing %s expected an Array of 2 elements where the first element is a String but got %s at the first element." t o
748+
738wrongPairCountFail :: String -> String -> Parser fail
749wrongPairCountFail :: String -> String -> Parser fail
739wrongPairCountFail t n =
750wrongPairCountFail t n =
740 fail $ printf "When parsing %s expected an Object with a single name/value pair but got %s pairs."
751 fail $ printf "When parsing %s expected an Object with a single name/value pair but got %s pairs."
@@ -748,7 +759,7 @@ noMatchFail t o =
748 fail $ printf "When parsing %s expected a String with the name of a constructor but got %s." t o
759 fail $ printf "When parsing %s expected a String with the name of a constructor but got %s." t o
749
760
750not2ElemArray :: String -> Int -> Parser fail
761not2ElemArray :: String -> Int -> Parser fail
751−not2ElemArray t i = fail $ printf "When parsing %s expected an Array of 2-elements but got %i elements" t i
762+not2ElemArray t i = fail $ printf "When parsing %s expected an Array of 2 elements but got %i elements" t i
752
763
753conNotFoundFail2ElemArray :: String -> [String] -> String -> Parser fail
764conNotFoundFail2ElemArray :: String -> [String] -> String -> Parser fail
754conNotFoundFail2ElemArray t cs o =
765conNotFoundFail2ElemArray t cs o =