on master help sign in
Fixed bug in the TH code of parsing a 2-element-array encoded value
commit3dc442dce1e6f19f0029d6a4a5e5de35bd00850f authorBas van Dijk <v.dijk.bas@gmail.com> dateSun 7 Apr 2013, 18:18 (14 years ago) parenteb99c5d
1 file changed+13−2
Data/Aeson/TH.hs+13−2
Data/Aeson/TH.hs+13−2
@@ -1,5 +1,5 @@
11{-# LANGUAGE CPP, FlexibleInstances, NamedFieldPuns, NoImplicitPrelude,
2− OverlappingInstances, TemplateHaskell, UndecidableInstances
2+ OverlappingInstances, TemplateHaskell, UndecidableInstances, IncoherentInstances
33 #-}
44
55{-|
@@ -496,6 +496,14 @@ consFromJSON tName opts cons = do
496496 'conNotFoundFail2ElemArray
497497 )
498498 []
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+ []
499507 ]
500508 )
501509
@@ -735,6 +743,9 @@ noArrayFail t o = fail $ printf "When parsing %s expected Array but got %s." t o
735743noObjectFail :: String -> String -> Parser fail
736744noObjectFail t o = fail $ printf "When parsing %s expected Object but got %s." t o
737745
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+
738749wrongPairCountFail :: String -> String -> Parser fail
739750wrongPairCountFail t n =
740751 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 =
748759 fail $ printf "When parsing %s expected a String with the name of a constructor but got %s." t o
749760
750761not2ElemArray :: 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
752763
753764conNotFoundFail2ElemArray :: String -> [String] -> String -> Parser fail
754765conNotFoundFail2ElemArray t cs o =